options.pas 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
  3. Reads command line options and config files
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit options;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,globals,verbose,systems,cpuinfo;
  22. type
  23. TOption=class
  24. FirstPass,
  25. ParaLogo,
  26. NoPressEnter,
  27. LogoWritten : boolean;
  28. FileLevel : longint;
  29. QuickInfo : string;
  30. ParaIncludePath,
  31. ParaUnitPath,
  32. ParaObjectPath,
  33. ParaLibraryPath : TSearchPathList;
  34. ParaAlignment : TAlignmentInfo;
  35. Constructor Create;
  36. Destructor Destroy;override;
  37. procedure WriteLogo;
  38. procedure WriteInfo;
  39. procedure WriteHelpPages;
  40. procedure WriteQuickInfo;
  41. procedure IllegalPara(const opt:string);
  42. function Unsetbool(var Opts:string; Pos: Longint):boolean;
  43. procedure interpret_option(const opt :string;ispara:boolean);
  44. procedure Interpret_envvar(const envname : string);
  45. procedure Interpret_file(const filename : string);
  46. procedure Read_Parameters;
  47. procedure parsecmd(cmd:string);
  48. procedure TargetDefines(def:boolean);
  49. end;
  50. TOptionClass=class of toption;
  51. var
  52. coption : TOptionClass;
  53. procedure read_arguments(cmd:string);
  54. implementation
  55. uses
  56. widestr,
  57. {$IFDEF USE_SYSUTILS}
  58. SysUtils,
  59. {$ELSE USE_SYSUTILS}
  60. dos,
  61. {$ENDIF USE_SYSUTILS}
  62. version,
  63. cutils,cmsgs,
  64. comphook,
  65. symtable,scanner,rabase
  66. {$ifdef BrowserLog}
  67. ,browlog
  68. {$endif BrowserLog}
  69. ;
  70. const
  71. page_size = 24;
  72. var
  73. option : toption;
  74. read_configfile, { read config file, set when a cfgfile is found }
  75. disable_configfile : boolean;
  76. fpcdir,
  77. ppccfg,
  78. ppcaltcfg,
  79. param_file : string; { file to compile specified on the commandline }
  80. {****************************************************************************
  81. Defines
  82. ****************************************************************************}
  83. procedure set_default_link_type;
  84. begin
  85. undef_system_macro('FPC_LINK_SMART');
  86. def_system_macro('FPC_LINK_STATIC');
  87. undef_system_macro('FPC_LINK_DYNAMIC');
  88. initglobalswitches:=initglobalswitches+[cs_link_static];
  89. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  90. end;
  91. {****************************************************************************
  92. Toption
  93. ****************************************************************************}
  94. procedure StopOptions(err:longint);
  95. begin
  96. if assigned(Option) then
  97. begin
  98. Option.free;
  99. Option:=nil;
  100. end;
  101. raise ECompilerAbortSilent.Create;
  102. end;
  103. procedure Toption.WriteLogo;
  104. var
  105. p : pchar;
  106. begin
  107. if not LogoWritten then
  108. begin
  109. p:=MessagePchar(option_logo);
  110. while assigned(p) do
  111. Comment(V_Normal,GetMsgLine(p));
  112. LogoWritten:= true;
  113. end;
  114. end;
  115. procedure Toption.WriteInfo;
  116. var
  117. p : pchar;
  118. hs,hs1,s : TCmdStr;
  119. target : tsystem;
  120. cpu : tcputype;
  121. fpu : tfputype;
  122. opt : toptimizerswitch;
  123. begin
  124. p:=MessagePchar(option_info);
  125. while assigned(p) do
  126. begin
  127. s:=GetMsgLine(p);
  128. { list OS Targets }
  129. if pos('$OSTARGETS',s)>0 then
  130. begin
  131. for target:=low(tsystem) to high(tsystem) do
  132. if assigned(targetinfos[target]) then
  133. begin
  134. hs:=s;
  135. hs1:=targetinfos[target]^.name;
  136. if tf_under_development in targetinfos[target]^.flags then
  137. hs1:=hs1+' (under development)';
  138. Replace(hs,'$OSTARGETS',hs1);
  139. Comment(V_Normal,hs);
  140. end;
  141. end
  142. else if pos('$INSTRUCTIONSETS',s)>0 then
  143. begin
  144. for cpu:=low(tcputype) to high(tcputype) do
  145. begin
  146. hs:=s;
  147. hs1:=cputypestr[cpu];
  148. if hs1<>'' then
  149. begin
  150. Replace(hs,'$INSTRUCTIONSETS',hs1);
  151. Comment(V_Normal,hs);
  152. end;
  153. end;
  154. end
  155. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  156. begin
  157. for fpu:=low(tfputype) to high(tfputype) do
  158. begin
  159. hs:=s;
  160. hs1:=fputypestr[fpu];
  161. if hs1<>'' then
  162. begin
  163. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  164. Comment(V_Normal,hs);
  165. end;
  166. end;
  167. end
  168. else if pos('$OPTIMIZATIONS',s)>0 then
  169. begin
  170. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  171. begin
  172. if opt in supported_optimizerswitches then
  173. begin
  174. hs:=s;
  175. hs1:=OptimizerSwitchStr[opt];
  176. if hs1<>'' then
  177. begin
  178. Replace(hs,'$OPTIMIZATIONS',hs1);
  179. Comment(V_Normal,hs);
  180. end;
  181. end;
  182. end;
  183. end
  184. else
  185. Comment(V_Normal,s);
  186. end;
  187. StopOptions(0);
  188. end;
  189. procedure Toption.WriteHelpPages;
  190. function PadEnd(s:string;i:longint):string;
  191. begin
  192. while (length(s)<i) do
  193. s:=s+' ';
  194. PadEnd:=s;
  195. end;
  196. var
  197. lastident,
  198. j,outline,
  199. ident,
  200. lines : longint;
  201. show : boolean;
  202. opt : string[32];
  203. input,
  204. s : string;
  205. p : pchar;
  206. begin
  207. WriteLogo;
  208. Lines:=4;
  209. Message1(option_usage,FixFileName(system.paramstr(0)));
  210. lastident:=0;
  211. p:=MessagePChar(option_help_pages);
  212. while assigned(p) do
  213. begin
  214. { get a line and reset }
  215. s:=GetMsgLine(p);
  216. ident:=0;
  217. show:=false;
  218. { parse options }
  219. case s[1] of
  220. {$ifdef UNITALIASES}
  221. 'a',
  222. {$endif}
  223. {$ifdef EXTDEBUG}
  224. 'e',
  225. {$endif EXTDEBUG}
  226. {$ifdef i386}
  227. '3',
  228. {$endif}
  229. {$ifdef x86_64}
  230. '4',
  231. {$endif}
  232. {$ifdef m68k}
  233. '6',
  234. {$endif}
  235. {$ifdef arm}
  236. 'A',
  237. {$endif}
  238. {$ifdef powerpc}
  239. 'P',
  240. {$endif}
  241. {$ifdef sparc}
  242. 'S',
  243. {$endif}
  244. {$ifdef vis}
  245. 'V',
  246. {$endif}
  247. '*' : show:=true;
  248. end;
  249. if show then
  250. begin
  251. case s[2] of
  252. 'g',
  253. {$ifdef Unix}
  254. 'L',
  255. {$endif}
  256. {$ifdef os2}
  257. 'O',
  258. {$endif}
  259. '*' : show:=true;
  260. else
  261. show:=false;
  262. end;
  263. end;
  264. { now we may show the message or not }
  265. if show then
  266. begin
  267. case s[3] of
  268. '0' : begin
  269. ident:=0;
  270. outline:=0;
  271. end;
  272. '1' : begin
  273. ident:=2;
  274. outline:=7;
  275. end;
  276. '2' : begin
  277. ident:=6;
  278. outline:=11;
  279. end;
  280. '3' : begin
  281. ident:=9;
  282. outline:=11;
  283. end;
  284. end;
  285. j:=pos('_',s);
  286. opt:=Copy(s,4,j-4);
  287. if opt='*' then
  288. opt:=''
  289. else
  290. if opt=' ' then
  291. opt:=PadEnd(opt,outline)
  292. else
  293. opt:=PadEnd('-'+opt,outline);
  294. if (ident=0) and (lastident<>0) then
  295. begin
  296. Comment(V_Normal,'');
  297. inc(Lines);
  298. end;
  299. { page full ? }
  300. if (lines >= page_size - 1) then
  301. begin
  302. if not NoPressEnter then
  303. begin
  304. Message(option_help_press_enter);
  305. readln(input);
  306. if upper(input)='Q' then
  307. StopOptions(0);
  308. end;
  309. lines:=0;
  310. end;
  311. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  312. LastIdent:=Ident;
  313. inc(Lines);
  314. end;
  315. end;
  316. StopOptions(0);
  317. end;
  318. procedure Toption.IllegalPara(const opt:string);
  319. begin
  320. Message1(option_illegal_para,opt);
  321. Message(option_help_pages_para);
  322. StopOptions(1);
  323. end;
  324. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  325. { checks if the character after pos in Opts is a + or a - and returns resp.
  326. false or true. If it is another character (or none), it also returns false }
  327. begin
  328. UnsetBool := false;
  329. if Length(Opts)>Pos then
  330. begin
  331. inc(Pos);
  332. UnsetBool := Opts[Pos] = '-';
  333. if Opts[Pos] in ['-','+']then
  334. delete(Opts,Pos,1);
  335. end;
  336. end;
  337. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  338. var
  339. code : integer;
  340. c : char;
  341. more : string;
  342. major,minor : longint;
  343. error : integer;
  344. j,l : longint;
  345. d : DirStr;
  346. s : string;
  347. begin
  348. if opt='' then
  349. exit;
  350. { only parse define,undef,target,verbosity,link etc options the firsttime }
  351. if firstpass and
  352. not(
  353. (opt[1]='-') and
  354. (
  355. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  356. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e'))
  357. )
  358. ) then
  359. exit;
  360. Message1(option_handling_option,opt);
  361. case opt[1] of
  362. '-' :
  363. begin
  364. more:=Copy(opt,3,255);
  365. if firstpass then
  366. Message1(option_interpreting_firstpass_option,opt)
  367. else
  368. Message1(option_interpreting_option,opt);
  369. case opt[2] of
  370. '?' :
  371. WriteHelpPages;
  372. 'a' :
  373. begin
  374. include(initglobalswitches,cs_asm_leave);
  375. j:=1;
  376. while j<=length(more) do
  377. begin
  378. case more[j] of
  379. 'l' :
  380. include(initglobalswitches,cs_asm_source);
  381. 'r' :
  382. include(initglobalswitches,cs_asm_regalloc);
  383. 't' :
  384. include(initglobalswitches,cs_asm_tempalloc);
  385. 'n' :
  386. include(initglobalswitches,cs_asm_nodes);
  387. 'p' :
  388. begin
  389. exclude(initglobalswitches,cs_asm_leave);
  390. if UnsetBool(More, 0) then
  391. exclude(initglobalswitches,cs_asm_pipe)
  392. else
  393. include(initglobalswitches,cs_asm_pipe);
  394. end;
  395. '-' :
  396. initglobalswitches:=initglobalswitches -
  397. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  398. cs_asm_nodes, cs_asm_pipe];
  399. else
  400. IllegalPara(opt);
  401. end;
  402. inc(j);
  403. end;
  404. end;
  405. 'A' :
  406. begin
  407. paratargetasm:=find_asm_by_string(More);
  408. if paratargetasm=as_none then
  409. IllegalPara(opt);
  410. end;
  411. 'b' :
  412. begin
  413. {$ifdef supportbrowser}
  414. if UnsetBool(More,0) then
  415. begin
  416. exclude(initmoduleswitches,cs_browser);
  417. exclude(initmoduleswitches,cs_local_browser);
  418. {$ifdef BrowserLog}
  419. exclude(initglobalswitches,cs_browser_log);
  420. {$endif}
  421. end
  422. else
  423. begin
  424. include(initmoduleswitches,cs_browser);
  425. {$ifdef BrowserLog}
  426. include(initglobalswitches,cs_browser_log);
  427. {$endif}
  428. end;
  429. if More<>'' then
  430. if (More='l') or (More='l+') then
  431. include(initmoduleswitches,cs_local_browser)
  432. else
  433. if More='l-' then
  434. exclude(initmoduleswitches,cs_local_browser)
  435. else
  436. {$ifdef BrowserLog}
  437. browserlog.elements_to_list.insert(more);
  438. {$else}
  439. IllegalPara(opt);
  440. {$endif}
  441. {$endif supportbrowser}
  442. end;
  443. 'B' :
  444. do_build:=not UnSetBool(more,0);
  445. 'C' :
  446. begin
  447. j:=1;
  448. while j<=length(more) do
  449. begin
  450. case more[j] of
  451. 'c' :
  452. begin
  453. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),initdefproccall) then
  454. IllegalPara(opt);
  455. break;
  456. end;
  457. {$ifdef cpufpemu}
  458. 'e' :
  459. begin
  460. If UnsetBool(More, j) then
  461. exclude(initmoduleswitches,cs_fp_emulation)
  462. Else
  463. include(initmoduleswitches,cs_fp_emulation);
  464. end;
  465. {$endif cpufpemu}
  466. 'f' :
  467. begin
  468. s:=upper(copy(more,j+1,length(more)-j));
  469. if not(SetFpuType(s,initfputype)) then
  470. IllegalPara(opt);
  471. break;
  472. end;
  473. 'g' :
  474. include(initmoduleswitches,cs_create_pic);
  475. 'h' :
  476. begin
  477. val(copy(more,j+1,length(more)-j),heapsize,code);
  478. if (code<>0) or (heapsize<1024) then
  479. IllegalPara(opt);
  480. break;
  481. end;
  482. 'i' :
  483. If UnsetBool(More, j) then
  484. exclude(initlocalswitches,cs_check_io)
  485. else
  486. include(initlocalswitches,cs_check_io);
  487. 'n' :
  488. If UnsetBool(More, j) then
  489. exclude(initglobalswitches,cs_link_nolink)
  490. Else
  491. include(initglobalswitches,cs_link_nolink);
  492. 'o' :
  493. If UnsetBool(More, j) then
  494. exclude(initlocalswitches,cs_check_overflow)
  495. Else
  496. include(initlocalswitches,cs_check_overflow);
  497. 'p' :
  498. begin
  499. s:=upper(copy(more,j+1,length(more)-j));
  500. if not(Setcputype(s,initcputype)) then
  501. IllegalPara(opt);
  502. break;
  503. end;
  504. 'r' :
  505. If UnsetBool(More, j) then
  506. exclude(initlocalswitches,cs_check_range)
  507. Else
  508. include(initlocalswitches,cs_check_range);
  509. 'R' :
  510. If UnsetBool(More, j) then
  511. begin
  512. exclude(initlocalswitches,cs_check_range);
  513. exclude(initlocalswitches,cs_check_object);
  514. end
  515. Else
  516. begin
  517. include(initlocalswitches,cs_check_range);
  518. include(initlocalswitches,cs_check_object);
  519. end;
  520. 's' :
  521. begin
  522. val(copy(more,j+1,length(more)-j),stacksize,code);
  523. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  524. IllegalPara(opt);
  525. break;
  526. end;
  527. 't' :
  528. If UnsetBool(More, j) then
  529. exclude(initlocalswitches,cs_check_stack)
  530. Else
  531. include(initlocalswitches,cs_check_stack);
  532. 'D' :
  533. If UnsetBool(More, j) then
  534. exclude(initmoduleswitches,cs_create_dynamic)
  535. Else
  536. include(initmoduleswitches,cs_create_dynamic);
  537. 'X' :
  538. If UnsetBool(More, j) then
  539. exclude(initmoduleswitches,cs_create_smart)
  540. Else
  541. include(initmoduleswitches,cs_create_smart);
  542. else
  543. IllegalPara(opt);
  544. end;
  545. inc(j);
  546. end;
  547. end;
  548. 'd' :
  549. if more <> '' then
  550. begin
  551. l:=Pos(':=',more);
  552. if l>0 then
  553. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  554. else
  555. def_system_macro(more);
  556. end;
  557. 'D' :
  558. begin
  559. include(initglobalswitches,cs_link_deffile);
  560. j:=1;
  561. while j<=length(more) do
  562. begin
  563. case more[j] of
  564. 'd' :
  565. begin
  566. description:=Copy(more,j+1,255);
  567. break;
  568. end;
  569. 'v' :
  570. begin
  571. dllversion:=Copy(more,j+1,255);
  572. l:=pos('.',dllversion);
  573. dllminor:=0;
  574. error:=0;
  575. if l>0 then
  576. begin
  577. val(copy(dllversion,l+1,255),minor,error);
  578. if (error=0) and
  579. (minor>=0) and (minor<=$ffff) then
  580. dllminor:=minor
  581. else
  582. if error=0 then
  583. error:=1;
  584. end;
  585. if l=0 then
  586. l:=256;
  587. dllmajor:=1;
  588. if error=0 then
  589. val(copy(dllversion,1,l-1),major,error);
  590. if (error=0) and (major>=0) and (major<=$ffff) then
  591. dllmajor:=major
  592. else
  593. if error=0 then
  594. error:=1;
  595. if error<>0 then
  596. Message1(scan_w_wrong_version_ignored,dllversion);
  597. break;
  598. end;
  599. 'w' :
  600. usewindowapi:=true;
  601. '-' :
  602. begin
  603. exclude(initglobalswitches,cs_link_deffile);
  604. usewindowapi:=false;
  605. end;
  606. else
  607. IllegalPara(opt);
  608. end;
  609. inc(j);
  610. end;
  611. end;
  612. 'e' :
  613. exepath:=FixPath(More,true);
  614. 'E' :
  615. begin
  616. if UnsetBool(More, 0) then
  617. exclude(initglobalswitches,cs_link_nolink)
  618. else
  619. include(initglobalswitches,cs_link_nolink);
  620. end;
  621. 'F' :
  622. begin
  623. c:=more[1];
  624. Delete(more,1,1);
  625. DefaultReplacements(More);
  626. case c of
  627. 'a' :
  628. autoloadunits:=more;
  629. 'c' :
  630. begin
  631. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  632. initsourcecodepage:='utf8'
  633. else if not(cpavailable(more)) then
  634. Message1(option_code_page_not_available,more)
  635. else
  636. initsourcecodepage:=more;
  637. end;
  638. 'D' :
  639. utilsdirectory:=FixPath(More,true);
  640. 'e' :
  641. SetRedirectFile(More);
  642. 'E' :
  643. OutputExeDir:=FixPath(More,true);
  644. 'i' :
  645. begin
  646. if ispara then
  647. ParaIncludePath.AddPath(More,false)
  648. else
  649. includesearchpath.AddPath(More,true);
  650. end;
  651. 'g' :
  652. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  653. 'l' :
  654. begin
  655. if ispara then
  656. ParaLibraryPath.AddPath(More,false)
  657. else
  658. LibrarySearchPath.AddPath(More,true);
  659. end;
  660. 'L' :
  661. begin
  662. if More<>'' then
  663. ParaDynamicLinker:=More
  664. else
  665. IllegalPara(opt);
  666. end;
  667. 'o' :
  668. begin
  669. if ispara then
  670. ParaObjectPath.AddPath(More,false)
  671. else
  672. ObjectSearchPath.AddPath(More,true);
  673. end;
  674. 'r' :
  675. Msgfilename:=More;
  676. 'u' :
  677. begin
  678. if ispara then
  679. ParaUnitPath.AddPath(More,false)
  680. else
  681. unitsearchpath.AddPath(More,true);
  682. end;
  683. 'U' :
  684. OutputUnitDir:=FixPath(More,true);
  685. else
  686. IllegalPara(opt);
  687. end;
  688. end;
  689. 'g' : begin
  690. if UnsetBool(More, 0) then
  691. begin
  692. exclude(initmoduleswitches,cs_debuginfo);
  693. exclude(initglobalswitches,cs_use_heaptrc);
  694. exclude(initglobalswitches,cs_use_lineinfo);
  695. exclude(initlocalswitches,cs_checkpointer);
  696. end
  697. else
  698. begin
  699. include(initmoduleswitches,cs_debuginfo);
  700. end;
  701. if not RelocSectionSetExplicitly then
  702. RelocSection:=false;
  703. j:=1;
  704. while j<=length(more) do
  705. begin
  706. case more[j] of
  707. 'c' :
  708. begin
  709. if UnsetBool(More, j) then
  710. exclude(initlocalswitches,cs_checkpointer)
  711. else
  712. include(initlocalswitches,cs_checkpointer);
  713. end;
  714. 'd' :
  715. begin
  716. paratargetdbg:=dbg_dwarf;
  717. end;
  718. 'h' :
  719. begin
  720. if UnsetBool(More, j) then
  721. exclude(initglobalswitches,cs_use_heaptrc)
  722. else
  723. include(initglobalswitches,cs_use_heaptrc);
  724. end;
  725. 'l' :
  726. begin
  727. if UnsetBool(More, j) then
  728. exclude(initglobalswitches,cs_use_lineinfo)
  729. else
  730. include(initglobalswitches,cs_use_lineinfo);
  731. end;
  732. 's' :
  733. begin
  734. paratargetdbg:=dbg_stabs;
  735. end;
  736. 'v' :
  737. begin
  738. if UnsetBool(More, j) then
  739. exclude(initglobalswitches,cs_gdb_valgrind)
  740. else
  741. include(initglobalswitches,cs_gdb_valgrind);
  742. end;
  743. 'w' :
  744. begin
  745. paratargetdbg:=dbg_dwarf;
  746. end;
  747. else
  748. IllegalPara(opt);
  749. end;
  750. inc(j);
  751. end;
  752. end;
  753. 'h' :
  754. begin
  755. NoPressEnter:=true;
  756. WriteHelpPages;
  757. end;
  758. 'i' :
  759. begin
  760. if More='' then
  761. WriteInfo
  762. else
  763. QuickInfo:=QuickInfo+More;
  764. end;
  765. 'I' :
  766. begin
  767. if ispara then
  768. ParaIncludePath.AddPath(More,false)
  769. else
  770. includesearchpath.AddPath(More,false);
  771. end;
  772. 'k' :
  773. begin
  774. if more<>'' then
  775. ParaLinkOptions:=ParaLinkOptions+' '+More
  776. else
  777. IllegalPara(opt);
  778. end;
  779. 'l' :
  780. if not UnSetBool(more,0) then
  781. ParaLogo:=true;
  782. 'm' :
  783. parapreprocess:=not UnSetBool(more,0);
  784. 'M' :
  785. begin
  786. more:=Upper(more);
  787. if not SetCompileMode(more, true) then
  788. IllegalPara(opt);
  789. end;
  790. 'n' :
  791. begin
  792. if More='' then
  793. disable_configfile:=true
  794. else
  795. IllegalPara(opt);
  796. end;
  797. 'o' :
  798. begin
  799. if More<>'' then
  800. begin
  801. {$IFDEF USE_SYSUTILS}
  802. D:=SplitPath(More);
  803. OutputFile:=SplitFileName(More);
  804. OutputExtension:=SplitExtension(More);
  805. {$ELSE USE_SYSUTILS}
  806. FSplit(More,D,OutputFile,OutputExtension);
  807. {$ENDIF USE_SYSUTILS}
  808. if (D<>'') then
  809. OutputExeDir:=FixPath(D,True);
  810. end
  811. else
  812. IllegalPara(opt);
  813. end;
  814. 'O' :
  815. begin
  816. j:=1;
  817. while j<=length(more) do
  818. begin
  819. case more[j] of
  820. '1' :
  821. initoptimizerswitches:=initoptimizerswitches+level1optimizerswitches;
  822. '2' :
  823. initoptimizerswitches:=initoptimizerswitches+level2optimizerswitches;
  824. '3' :
  825. initoptimizerswitches:=initoptimizerswitches+level3optimizerswitches;
  826. 'a' :
  827. begin
  828. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  829. IllegalPara(opt);
  830. break;
  831. end;
  832. 's' :
  833. include(initoptimizerswitches,cs_opt_size);
  834. 'p' :
  835. begin
  836. if not Setcputype(copy(more,j+1,length(more)),initoptimizecputype) then
  837. begin
  838. { Give warning for old i386 switches }
  839. if (Length(More)-j=1) and
  840. (More[j+1]>='1') and (More[j+1]<='5')then
  841. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  842. else
  843. IllegalPara(opt);
  844. end;
  845. break;
  846. end;
  847. 'o' :
  848. begin
  849. if not UpdateOptimizerStr(copy(more,j+1,length(more)),initoptimizerswitches) then
  850. IllegalPara(opt);
  851. break;
  852. end;
  853. '-' :
  854. begin
  855. initoptimizerswitches:=[];
  856. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  857. end;
  858. { Obsolete switches }
  859. 'g' :
  860. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  861. 'G' :
  862. Message1(option_obsolete_switch,'-OG');
  863. 'r' :
  864. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  865. 'u' :
  866. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  867. else
  868. IllegalPara(opt);
  869. end;
  870. inc(j);
  871. end;
  872. end;
  873. 'p' :
  874. begin
  875. if UnsetBool(More, 0) then
  876. begin
  877. initmoduleswitches:=initmoduleswitches-[cs_profile];
  878. undef_system_macro('FPC_PROFILE');
  879. end
  880. else
  881. if Length(More)=0 then
  882. IllegalPara(opt)
  883. else
  884. case more[1] of
  885. 'g' : if UnsetBool(more, 1) then
  886. begin
  887. exclude(initmoduleswitches,cs_profile);
  888. undef_system_macro('FPC_PROFILE');
  889. end
  890. else
  891. begin
  892. include(initmoduleswitches,cs_profile);
  893. def_system_macro('FPC_PROFILE');
  894. end;
  895. else
  896. IllegalPara(opt);
  897. end;
  898. end;
  899. 'P' : ; { Ignore used by fpc.pp }
  900. 'R' :
  901. begin
  902. if not SetAsmReadMode(More,initasmmode) then
  903. IllegalPara(opt);
  904. end;
  905. 's' :
  906. begin
  907. if UnsetBool(More, 0) then
  908. begin
  909. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  910. if more<>'' then
  911. IllegalPara(opt);
  912. end
  913. else
  914. begin
  915. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  916. if more='h' then
  917. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  918. else if more='t' then
  919. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  920. else if more='r' then
  921. initglobalswitches:=initglobalswitches+[cs_asm_leave,cs_no_regalloc]
  922. else if more<>'' then
  923. IllegalPara(opt);
  924. end;
  925. end;
  926. 'S' :
  927. begin
  928. if more[1]='I' then
  929. begin
  930. if upper(more)='ICOM' then
  931. initinterfacetype:=it_interfacecom
  932. else if upper(more)='ICORBA' then
  933. initinterfacetype:=it_interfacecorba
  934. else
  935. IllegalPara(opt);
  936. end
  937. else
  938. begin
  939. j:=1;
  940. while j<=length(more) do
  941. begin
  942. case more[j] of
  943. '2' : //an alternative to -Mobjfpc
  944. SetCompileMode('OBJFPC',true);
  945. 'a' :
  946. include(initlocalswitches,cs_do_assertion);
  947. 'c' :
  948. include(initmoduleswitches,cs_support_c_operators);
  949. 'd' : //an alternative to -Mdelphi
  950. SetCompileMode('DELPHI',true);
  951. 'e' :
  952. begin
  953. SetErrorFlags(copy(more,j+1,length(more)));
  954. break;
  955. end;
  956. 'g' :
  957. include(initmoduleswitches,cs_support_goto);
  958. 'h' :
  959. include(initlocalswitches,cs_ansistrings);
  960. 'i' :
  961. include(initmoduleswitches,cs_support_inline);
  962. 'k' :
  963. include(initglobalswitches,cs_load_fpcylix_unit);
  964. 'm' :
  965. include(initmoduleswitches,cs_support_macro);
  966. 'o' : //an alternative to -Mtp
  967. SetCompileMode('TP',true);
  968. 'p' : //an alternative to -Mgpc
  969. SetCompileMode('GPC',true);
  970. 's' :
  971. include(initglobalswitches,cs_constructor_name);
  972. 't' :
  973. include(initmoduleswitches,cs_static_keyword);
  974. '-' :
  975. begin
  976. exclude(initglobalswitches,cs_constructor_name);
  977. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  978. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  979. cs_support_inline, cs_support_macro,
  980. cs_static_keyword];
  981. end;
  982. else
  983. IllegalPara(opt);
  984. end;
  985. inc(j);
  986. end;
  987. end;
  988. end;
  989. 'T' :
  990. begin
  991. more:=Upper(More);
  992. if paratarget=system_none then
  993. begin
  994. { remove old target define }
  995. TargetDefines(false);
  996. { load new target }
  997. paratarget:=find_system_by_string(More);
  998. if paratarget<>system_none then
  999. set_target(paratarget)
  1000. else
  1001. IllegalPara(opt);
  1002. { set new define }
  1003. TargetDefines(true);
  1004. end
  1005. else
  1006. if More<>upper(target_info.shortname) then
  1007. Message1(option_target_is_already_set,target_info.shortname);
  1008. end;
  1009. 'u' :
  1010. if more <> '' then
  1011. undef_system_macro(more);
  1012. 'U' :
  1013. begin
  1014. j:=1;
  1015. while j<=length(more) do
  1016. begin
  1017. case more[j] of
  1018. {$ifdef UNITALIASES}
  1019. 'a' :
  1020. begin
  1021. AddUnitAlias(Copy(More,j+1,255));
  1022. break;
  1023. end;
  1024. {$endif UNITALIASES}
  1025. 'n' :
  1026. exclude(initglobalswitches,cs_check_unit_name);
  1027. 'p' :
  1028. begin
  1029. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1030. break;
  1031. end;
  1032. 'r' :
  1033. do_release:=true;
  1034. 's' :
  1035. include(initmoduleswitches,cs_compilesystem);
  1036. '-' :
  1037. begin
  1038. exclude(initmoduleswitches,cs_compilesystem);
  1039. exclude(initglobalswitches,cs_check_unit_name);
  1040. end;
  1041. else
  1042. IllegalPara(opt);
  1043. end;
  1044. inc(j);
  1045. end;
  1046. end;
  1047. 'v' :
  1048. begin
  1049. if not setverbosity(More) then
  1050. IllegalPara(opt);
  1051. end;
  1052. 'V' : ; { Ignore used by fpc }
  1053. 'W' :
  1054. begin
  1055. j:=1;
  1056. while j<=length(More) do
  1057. begin
  1058. case More[j] of
  1059. 'A':
  1060. begin
  1061. if UnsetBool(More, j) then
  1062. apptype:=app_native
  1063. else
  1064. apptype:=app_cui;
  1065. end;
  1066. 'B':
  1067. begin
  1068. { -WB200000 means set trefered base address
  1069. to $200000, but does not change relocsection boolean
  1070. this way we can create both relocatble and
  1071. non relocatable DLL at a specific base address PM }
  1072. if (length(More)>j) then
  1073. begin
  1074. if DLLImageBase=nil then
  1075. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1076. end
  1077. else
  1078. begin
  1079. RelocSection:=true;
  1080. RelocSectionSetExplicitly:=true;
  1081. end;
  1082. break;
  1083. end;
  1084. 'C':
  1085. begin
  1086. if UnsetBool(More, j) then
  1087. apptype:=app_gui
  1088. else
  1089. apptype:=app_cui;
  1090. end;
  1091. 'D':
  1092. begin
  1093. UseDeffileForExports:=not UnsetBool(More, j);
  1094. UseDeffileForExportsSetExplicitly:=true;
  1095. end;
  1096. 'F':
  1097. begin
  1098. if UnsetBool(More, j) then
  1099. apptype:=app_cui
  1100. else
  1101. apptype:=app_fs;
  1102. end;
  1103. 'G':
  1104. begin
  1105. if UnsetBool(More, j) then
  1106. apptype:=app_cui
  1107. else
  1108. apptype:=app_gui;
  1109. end;
  1110. 'I':
  1111. begin
  1112. GenerateImportSection:=not UnsetBool(More,j);
  1113. GenerateImportSectionSetExplicitly:=true;
  1114. end;
  1115. 'N':
  1116. begin
  1117. RelocSection:=UnsetBool(More,j);
  1118. RelocSectionSetExplicitly:=true;
  1119. end;
  1120. 'R':
  1121. begin
  1122. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1123. RelocSection:=not UnsetBool(More,j);
  1124. RelocSectionSetExplicitly:=true;
  1125. end;
  1126. 'T':
  1127. begin
  1128. if UnsetBool(More, j) then
  1129. apptype:=app_cui
  1130. else
  1131. apptype:=app_tool;
  1132. end;
  1133. else
  1134. IllegalPara(opt);
  1135. end;
  1136. inc(j);
  1137. end;
  1138. end;
  1139. 'X' :
  1140. begin
  1141. j:=1;
  1142. while j<=length(more) do
  1143. begin
  1144. case More[j] of
  1145. 'c' : Cshared:=TRUE;
  1146. 'd' : Dontlinkstdlibpath:=TRUE;
  1147. 'e' :
  1148. begin
  1149. If UnsetBool(More, j) then
  1150. exclude(initglobalswitches,cs_link_extern)
  1151. else
  1152. include(initglobalswitches,cs_link_extern);
  1153. end;
  1154. 'f' :
  1155. include(initglobalswitches,cs_link_pthread);
  1156. 'i' :
  1157. begin
  1158. If UnsetBool(More, j) then
  1159. include(initglobalswitches,cs_link_extern)
  1160. else
  1161. exclude(initglobalswitches,cs_link_extern);
  1162. end;
  1163. 'm' :
  1164. begin
  1165. If UnsetBool(More, j) then
  1166. exclude(initglobalswitches,cs_link_map)
  1167. else
  1168. include(initglobalswitches,cs_link_map);
  1169. end;
  1170. 'r' :
  1171. begin
  1172. rlinkpath:=Copy(more,2,length(More)-1);
  1173. DefaultReplacements(rlinkpath);
  1174. More:='';
  1175. end;
  1176. 's' :
  1177. begin
  1178. If UnsetBool(More, j) then
  1179. exclude(initglobalswitches,cs_link_strip)
  1180. else
  1181. include(initglobalswitches,cs_link_strip);
  1182. end;
  1183. 't' :
  1184. include(initglobalswitches,cs_link_staticflag);
  1185. 'v' :
  1186. begin
  1187. If UnsetBool(More, j) then
  1188. exclude(initglobalswitches,cs_link_opt_vtable)
  1189. else
  1190. include(initglobalswitches,cs_link_opt_vtable);
  1191. end;
  1192. 'D' :
  1193. begin
  1194. def_system_macro('FPC_LINK_DYNAMIC');
  1195. undef_system_macro('FPC_LINK_SMART');
  1196. undef_system_macro('FPC_LINK_STATIC');
  1197. exclude(initglobalswitches,cs_link_static);
  1198. exclude(initglobalswitches,cs_link_smart);
  1199. include(initglobalswitches,cs_link_shared);
  1200. LinkTypeSetExplicitly:=true;
  1201. end;
  1202. 'M' :
  1203. begin
  1204. mainaliasname:=Copy(more,2,length(More)-1);
  1205. More:='';
  1206. end;
  1207. 'P' :
  1208. begin
  1209. utilsprefix:=Copy(more,2,length(More)-1);
  1210. DefaultReplacements(utilsprefix);
  1211. More:='';
  1212. end;
  1213. 'S' :
  1214. begin
  1215. def_system_macro('FPC_LINK_STATIC');
  1216. undef_system_macro('FPC_LINK_SMART');
  1217. undef_system_macro('FPC_LINK_DYNAMIC');
  1218. include(initglobalswitches,cs_link_static);
  1219. exclude(initglobalswitches,cs_link_smart);
  1220. exclude(initglobalswitches,cs_link_shared);
  1221. LinkTypeSetExplicitly:=true;
  1222. end;
  1223. 'X' :
  1224. begin
  1225. def_system_macro('FPC_LINK_SMART');
  1226. undef_system_macro('FPC_LINK_STATIC');
  1227. undef_system_macro('FPC_LINK_DYNAMIC');
  1228. exclude(initglobalswitches,cs_link_static);
  1229. include(initglobalswitches,cs_link_smart);
  1230. exclude(initglobalswitches,cs_link_shared);
  1231. LinkTypeSetExplicitly:=true;
  1232. end;
  1233. '-' :
  1234. begin
  1235. exclude(initglobalswitches,cs_link_staticflag);
  1236. exclude(initglobalswitches,cs_link_strip);
  1237. exclude(initglobalswitches,cs_link_map);
  1238. set_default_link_type;
  1239. end;
  1240. else
  1241. IllegalPara(opt);
  1242. end;
  1243. inc(j);
  1244. end;
  1245. end;
  1246. end;
  1247. end;
  1248. '@' :
  1249. begin
  1250. Message(option_no_nested_response_file);
  1251. StopOptions(1);
  1252. end;
  1253. else
  1254. begin
  1255. if (length(param_file)<>0) then
  1256. Message(option_only_one_source_support);
  1257. param_file:=opt;
  1258. Message1(option_found_file,opt);
  1259. end;
  1260. end;
  1261. end;
  1262. procedure Toption.Interpret_file(const filename : string);
  1263. procedure RemoveSep(var fn:string);
  1264. var
  1265. i : longint;
  1266. begin
  1267. i:=0;
  1268. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1269. inc(i);
  1270. Delete(fn,1,i);
  1271. i:=length(fn);
  1272. while (i>0) and (fn[i] in [',',' ',#9]) do
  1273. dec(i);
  1274. fn:=copy(fn,1,i);
  1275. end;
  1276. function GetName(var fn:string):string;
  1277. var
  1278. i : longint;
  1279. begin
  1280. i:=0;
  1281. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1282. inc(i);
  1283. GetName:=Copy(fn,1,i);
  1284. Delete(fn,1,i);
  1285. end;
  1286. const
  1287. maxlevel=16;
  1288. var
  1289. f : text;
  1290. s, tmp,
  1291. opts : string;
  1292. skip : array[0..maxlevel-1] of boolean;
  1293. level : longint;
  1294. option_read : boolean;
  1295. begin
  1296. { avoid infinite loop }
  1297. Inc(FileLevel);
  1298. Option_read:=false;
  1299. If FileLevel>MaxLevel then
  1300. Message(option_too_many_cfg_files);
  1301. { Maybe It's Directory ?} //Jaro Change:
  1302. if DirectoryExists(filename) then
  1303. begin
  1304. Message1(option_config_is_dir,filename);
  1305. exit;
  1306. end;
  1307. { open file }
  1308. Message1(option_using_file,filename);
  1309. {$ifdef USE_SYSUTILS}
  1310. assign(f,ExpandFileName(filename));
  1311. {$else USE_SYSUTILS}
  1312. assign(f,FExpand(filename));
  1313. {$endif USE_SYsUTILS}
  1314. {$I-}
  1315. reset(f);
  1316. {$I+}
  1317. if ioresult<>0 then
  1318. begin
  1319. Message1(option_unable_open_file,filename);
  1320. exit;
  1321. end;
  1322. Message1(option_start_reading_configfile,filename);
  1323. fillchar(skip,sizeof(skip),0);
  1324. level:=0;
  1325. while not eof(f) do
  1326. begin
  1327. readln(f,opts);
  1328. RemoveSep(opts);
  1329. if (opts<>'') and (opts[1]<>';') then
  1330. begin
  1331. if opts[1]='#' then
  1332. begin
  1333. Message1(option_interpreting_file_option,opts);
  1334. Delete(opts,1,1);
  1335. s:=upper(GetName(opts));
  1336. if (s='SECTION') then
  1337. begin
  1338. RemoveSep(opts);
  1339. s:=upper(GetName(opts));
  1340. if level=0 then
  1341. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1342. end
  1343. else
  1344. if (s='IFDEF') then
  1345. begin
  1346. RemoveSep(opts);
  1347. if Level>=maxlevel then
  1348. begin
  1349. Message(option_too_many_ifdef);
  1350. stopOptions(1);
  1351. end;
  1352. inc(Level);
  1353. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1354. end
  1355. else
  1356. if (s='IFNDEF') then
  1357. begin
  1358. RemoveSep(opts);
  1359. if Level>=maxlevel then
  1360. begin
  1361. Message(option_too_many_ifdef);
  1362. stopOptions(1);
  1363. end;
  1364. inc(Level);
  1365. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1366. end
  1367. else
  1368. if (s='ELSE') then
  1369. skip[level]:=skip[level-1] or (not skip[level])
  1370. else
  1371. if (s='ENDIF') then
  1372. begin
  1373. skip[level]:=false;
  1374. if Level=0 then
  1375. begin
  1376. Message(option_too_many_endif);
  1377. stopOptions(1);
  1378. end;
  1379. dec(level);
  1380. end
  1381. else
  1382. if (not skip[level]) then
  1383. begin
  1384. if (s='DEFINE') then
  1385. begin
  1386. RemoveSep(opts);
  1387. tmp:= GetName(opts);
  1388. if tmp <> '' then
  1389. def_system_macro(tmp);
  1390. end
  1391. else
  1392. if (s='UNDEF') then
  1393. begin
  1394. RemoveSep(opts);
  1395. tmp:= GetName(opts);
  1396. if tmp <> '' then
  1397. undef_system_macro(tmp);
  1398. end
  1399. else
  1400. if (s='WRITE') then
  1401. begin
  1402. Delete(opts,1,1);
  1403. WriteLn(opts);
  1404. end
  1405. else
  1406. if (s='INCLUDE') then
  1407. begin
  1408. Delete(opts,1,1);
  1409. Interpret_file(opts);
  1410. end;
  1411. end;
  1412. end
  1413. else
  1414. begin
  1415. if (opts[1]='-') or (opts[1]='@') then
  1416. begin
  1417. if (not skip[level]) then
  1418. interpret_option(opts,false);
  1419. Option_read:=true;
  1420. end
  1421. else
  1422. Message1(option_illegal_para,opts);
  1423. end;
  1424. end;
  1425. end;
  1426. if Level>0 then
  1427. Message(option_too_less_endif);
  1428. if Not Option_read then
  1429. Message1(option_no_option_found,filename)
  1430. else
  1431. Message1(option_end_reading_configfile,filename);
  1432. Close(f);
  1433. Dec(FileLevel);
  1434. end;
  1435. procedure Toption.Interpret_envvar(const envname : string);
  1436. var
  1437. argstart,
  1438. env,
  1439. pc : pchar;
  1440. arglen : longint;
  1441. quote : set of char;
  1442. hs : string;
  1443. begin
  1444. Message1(option_using_env,envname);
  1445. env:=GetEnvPChar(envname);
  1446. pc:=env;
  1447. if assigned(pc) then
  1448. begin
  1449. repeat
  1450. { skip leading spaces }
  1451. while pc^ in [' ',#9,#13] do
  1452. inc(pc);
  1453. case pc^ of
  1454. #0 :
  1455. break;
  1456. '"' :
  1457. begin
  1458. quote:=['"'];
  1459. inc(pc);
  1460. end;
  1461. '''' :
  1462. begin
  1463. quote:=[''''];
  1464. inc(pc);
  1465. end;
  1466. else
  1467. quote:=[' ',#9,#13];
  1468. end;
  1469. { scan until the end of the argument }
  1470. argstart:=pc;
  1471. while (pc^<>#0) and not(pc^ in quote) do
  1472. inc(pc);
  1473. { create argument }
  1474. arglen:=pc-argstart;
  1475. hs[0]:=chr(arglen);
  1476. move(argstart^,hs[1],arglen);
  1477. interpret_option(hs,true);
  1478. { skip quote }
  1479. if pc^ in quote then
  1480. inc(pc);
  1481. until false;
  1482. end
  1483. else
  1484. Message1(option_no_option_found,'(env) '+envname);
  1485. FreeEnvPChar(env);
  1486. end;
  1487. procedure toption.read_parameters;
  1488. var
  1489. opts : string;
  1490. paramindex : longint;
  1491. begin
  1492. paramindex:=0;
  1493. while paramindex<paramcount do
  1494. begin
  1495. inc(paramindex);
  1496. opts:=system.paramstr(paramindex);
  1497. case opts[1] of
  1498. '@' :
  1499. if not firstpass then
  1500. begin
  1501. Delete(opts,1,1);
  1502. Message1(option_reading_further_from,opts);
  1503. interpret_file(opts);
  1504. end;
  1505. '!' :
  1506. if not firstpass then
  1507. begin
  1508. Delete(opts,1,1);
  1509. Message1(option_reading_further_from,'(env) '+opts);
  1510. interpret_envvar(opts);
  1511. end;
  1512. else
  1513. interpret_option(opts,true);
  1514. end;
  1515. end;
  1516. end;
  1517. procedure toption.parsecmd(cmd:string);
  1518. var
  1519. i,ps : longint;
  1520. opts : string;
  1521. begin
  1522. while (cmd<>'') do
  1523. begin
  1524. while cmd[1]=' ' do
  1525. delete(cmd,1,1);
  1526. i:=pos(' ',cmd);
  1527. if i=0 then
  1528. i:=256;
  1529. opts:=Copy(cmd,1,i-1);
  1530. Delete(cmd,1,i);
  1531. case opts[1] of
  1532. '@' :
  1533. if not firstpass then
  1534. begin
  1535. Delete(opts,1,1);
  1536. Message1(option_reading_further_from,opts);
  1537. interpret_file(opts);
  1538. end;
  1539. '!' :
  1540. if not firstpass then
  1541. begin
  1542. Delete(opts,1,1);
  1543. Message1(option_reading_further_from,'(env) '+opts);
  1544. interpret_envvar(opts);
  1545. end;
  1546. '"' :
  1547. begin
  1548. Delete(opts,1,1);
  1549. ps:=pos('"',cmd);
  1550. if (i<>256) and (ps>0) then
  1551. begin
  1552. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1553. cmd:=copy(cmd,ps+1,255);
  1554. end;
  1555. interpret_option(opts,true);
  1556. end;
  1557. else
  1558. interpret_option(opts,true);
  1559. end;
  1560. end;
  1561. end;
  1562. procedure toption.writequickinfo;
  1563. var
  1564. s : string;
  1565. i : longint;
  1566. procedure addinfo(const hs:string);
  1567. begin
  1568. if s<>'' then
  1569. s:=s+' '+hs
  1570. else
  1571. s:=hs;
  1572. end;
  1573. begin
  1574. s:='';
  1575. i:=0;
  1576. while (i<length(quickinfo)) do
  1577. begin
  1578. inc(i);
  1579. case quickinfo[i] of
  1580. 'S' :
  1581. begin
  1582. inc(i);
  1583. case quickinfo[i] of
  1584. 'O' :
  1585. addinfo(lower(source_info.shortname));
  1586. 'P' :
  1587. addinfo(source_cpu_string);
  1588. else
  1589. IllegalPara('-i'+QuickInfo);
  1590. end;
  1591. end;
  1592. 'T' :
  1593. begin
  1594. inc(i);
  1595. case quickinfo[i] of
  1596. 'O' :
  1597. addinfo(lower(target_info.shortname));
  1598. 'P' :
  1599. AddInfo(target_cpu_string);
  1600. else
  1601. IllegalPara('-i'+QuickInfo);
  1602. end;
  1603. end;
  1604. 'V' :
  1605. AddInfo(version_string);
  1606. 'D' :
  1607. AddInfo(date_string);
  1608. '_' :
  1609. ;
  1610. else
  1611. IllegalPara('-i'+QuickInfo);
  1612. end;
  1613. end;
  1614. if s<>'' then
  1615. begin
  1616. writeln(s);
  1617. stopoptions(0);
  1618. end;
  1619. end;
  1620. procedure TOption.TargetDefines(def:boolean);
  1621. var
  1622. s : string;
  1623. i : integer;
  1624. begin
  1625. if def then
  1626. def_system_macro(target_info.shortname)
  1627. else
  1628. undef_system_macro(target_info.shortname);
  1629. s:=target_info.extradefines;
  1630. while (s<>'') do
  1631. begin
  1632. i:=pos(';',s);
  1633. if i=0 then
  1634. i:=length(s)+1;
  1635. if def then
  1636. def_system_macro(Copy(s,1,i-1))
  1637. else
  1638. undef_system_macro(Copy(s,1,i-1));
  1639. delete(s,1,i);
  1640. end;
  1641. end;
  1642. constructor TOption.create;
  1643. begin
  1644. LogoWritten:=false;
  1645. NoPressEnter:=false;
  1646. FirstPass:=false;
  1647. FileLevel:=0;
  1648. Quickinfo:='';
  1649. ParaIncludePath:=TSearchPathList.Create;
  1650. ParaObjectPath:=TSearchPathList.Create;
  1651. ParaUnitPath:=TSearchPathList.Create;
  1652. ParaLibraryPath:=TSearchPathList.Create;
  1653. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1654. end;
  1655. destructor TOption.destroy;
  1656. begin
  1657. ParaIncludePath.Free;
  1658. ParaObjectPath.Free;
  1659. ParaUnitPath.Free;
  1660. ParaLibraryPath.Free;
  1661. end;
  1662. {****************************************************************************
  1663. Callable Routines
  1664. ****************************************************************************}
  1665. function check_configfile(const fn:string;var foundfn:string):boolean;
  1666. function CfgFileExists(const fn:string):boolean;
  1667. begin
  1668. Comment(V_Tried,'Configfile search: '+fn);
  1669. CfgFileExists:=FileExists(fn);
  1670. end;
  1671. var
  1672. configpath : pathstr;
  1673. begin
  1674. foundfn:=fn;
  1675. check_configfile:=true;
  1676. { retrieve configpath }
  1677. {$IFDEF USE_SYSUTILS}
  1678. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1679. {$ELSE USE_SYSUTILS}
  1680. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1681. {$ENDIF USE_SYSUTILS}
  1682. {$ifdef Unix}
  1683. if configpath='' then
  1684. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1685. {$endif}
  1686. {
  1687. Order to read configuration file :
  1688. try reading fpc.cfg in :
  1689. 1 - current dir
  1690. 2 - configpath
  1691. 3 - compiler path
  1692. }
  1693. if not FileExists(fn) then
  1694. begin
  1695. {$ifdef Unix}
  1696. {$IFDEF USE_SYSUTILS}
  1697. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1698. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1699. {$ELSE USE_SYSUTILS}
  1700. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1701. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1702. {$ENDIF USE_SYSUTILS}
  1703. else
  1704. {$endif}
  1705. if CfgFileExists(configpath+fn) then
  1706. foundfn:=configpath+fn
  1707. else
  1708. {$ifndef Unix}
  1709. if CfgFileExists(exepath+fn) then
  1710. foundfn:=exepath+fn
  1711. else
  1712. {$else}
  1713. if CfgFileExists('/etc/'+fn) then
  1714. foundfn:='/etc/'+fn
  1715. else
  1716. {$endif}
  1717. check_configfile:=false;
  1718. end;
  1719. end;
  1720. procedure read_arguments(cmd:string);
  1721. begin
  1722. option:=coption.create;
  1723. disable_configfile:=false;
  1724. { get default messagefile }
  1725. {$IFDEF USE_SYSUTILS}
  1726. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1727. {$ELSE USE_SYSUTILS}
  1728. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1729. {$ENDIF USE_SYSUTILS}
  1730. { default configfile can be specified on the commandline,
  1731. remove it first }
  1732. if (cmd<>'') and (cmd[1]='[') then
  1733. begin
  1734. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1735. Delete(cmd,1,pos(']',cmd));
  1736. end
  1737. else
  1738. begin
  1739. ppccfg:='fpc.cfg';
  1740. ppcaltcfg:='ppc386.cfg';
  1741. end;
  1742. { first pass reading of parameters, only -i -v -T etc.}
  1743. option.firstpass:=true;
  1744. if cmd<>'' then
  1745. option.parsecmd(cmd)
  1746. else
  1747. begin
  1748. option.read_parameters;
  1749. { Write only quickinfo }
  1750. if option.quickinfo<>'' then
  1751. option.writequickinfo;
  1752. end;
  1753. option.firstpass:=false;
  1754. { target is set here, for wince the default app type is gui }
  1755. if target_info.system in system_wince then
  1756. apptype:=app_gui;
  1757. { default defines }
  1758. def_system_macro(target_info.shortname);
  1759. def_system_macro('FPC');
  1760. def_system_macro('VER'+version_nr);
  1761. def_system_macro('VER'+version_nr+'_'+release_nr);
  1762. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1763. { Temporary defines, until things settle down }
  1764. { "main" symbol is generated in the main program, and left out of the system unit }
  1765. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1766. def_system_macro('FPC_DARWIN_JMP_MAIN');
  1767. def_system_macro('COMPPROCINLINEFIXED');
  1768. def_system_macro('PARAOUTFILE');
  1769. def_system_macro('RESSTRSECTIONS');
  1770. def_system_macro('FPC_HASFIXED64BITVARIANT');
  1771. { def_system_macro('INTERNAL_BACKTRACE');}
  1772. if pocall_default = pocall_register then
  1773. def_system_macro('REGCALL');
  1774. { using a case is pretty useless here (FK) }
  1775. { some stuff for TP compatibility }
  1776. {$ifdef i386}
  1777. def_system_macro('CPU86');
  1778. def_system_macro('CPU87');
  1779. def_system_macro('CPU386');
  1780. {$endif}
  1781. {$ifdef m68k}
  1782. def_system_macro('CPU68');
  1783. {$endif}
  1784. { new processor stuff }
  1785. {$ifdef i386}
  1786. def_system_macro('CPUI386');
  1787. def_system_macro('CPU32');
  1788. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1789. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1790. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1791. def_system_macro('FPC_HAS_RESOURCES');
  1792. {$endif}
  1793. {$ifdef m68k}
  1794. def_system_macro('CPU68K');
  1795. def_system_macro('CPUM68K');
  1796. def_system_macro('CPU32');
  1797. def_system_macro('FPC_CURRENCY_IS_INT64');
  1798. def_system_macro('FPC_COMP_IS_INT64');
  1799. {$endif}
  1800. {$ifdef ALPHA}
  1801. def_system_macro('CPUALPHA');
  1802. def_system_macro('CPU64');
  1803. {$endif}
  1804. {$ifdef powerpc}
  1805. def_system_macro('CPUPOWERPC');
  1806. def_system_macro('CPUPOWERPC32');
  1807. def_system_macro('CPU32');
  1808. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1809. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1810. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1811. def_system_macro('FPC_CURRENCY_IS_INT64');
  1812. def_system_macro('FPC_COMP_IS_INT64');
  1813. {$endif}
  1814. {$ifdef POWERPC64}
  1815. def_system_macro('CPUPOWERPC');
  1816. def_system_macro('CPUPOWERPC64');
  1817. def_system_macro('CPU64');
  1818. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1819. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1820. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1821. def_system_macro('FPC_CURRENCY_IS_INT64');
  1822. def_system_macro('FPC_COMP_IS_INT64');
  1823. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1824. {$endif}
  1825. {$ifdef iA64}
  1826. def_system_macro('CPUIA64');
  1827. def_system_macro('CPU64');
  1828. {$endif}
  1829. {$ifdef x86_64}
  1830. def_system_macro('CPUX86_64');
  1831. def_system_macro('CPUAMD64');
  1832. def_system_macro('CPU64');
  1833. { not supported for now, afaik (FK)
  1834. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1835. { win64 doesn't support the legacy fpu }
  1836. if target_info.system<>system_x86_64_win64 then
  1837. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1838. else
  1839. begin
  1840. def_system_macro('FPC_CURRENCY_IS_INT64');
  1841. def_system_macro('FPC_COMP_IS_INT64');
  1842. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1843. end;
  1844. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1845. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1846. {$endif}
  1847. {$ifdef sparc}
  1848. def_system_macro('CPUSPARC');
  1849. def_system_macro('CPUSPARC32');
  1850. def_system_macro('CPU32');
  1851. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1852. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1853. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1854. def_system_macro('FPC_CURRENCY_IS_INT64');
  1855. def_system_macro('FPC_COMP_IS_INT64');
  1856. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1857. {$endif}
  1858. {$ifdef vis}
  1859. def_system_macro('CPUVIS');
  1860. def_system_macro('CPU32');
  1861. {$endif}
  1862. {$ifdef arm}
  1863. def_system_macro('CPUARM');
  1864. def_system_macro('FPUFPA');
  1865. def_system_macro('CPU32');
  1866. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1867. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1868. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1869. def_system_macro('FPC_CURRENCY_IS_INT64');
  1870. def_system_macro('FPC_COMP_IS_INT64');
  1871. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1872. {$endif arm}
  1873. if source_info.system<>target_info.system then
  1874. def_system_macro('FPC_CROSSCOMPILING');
  1875. if source_info.cpu<>target_info.cpu then
  1876. def_system_macro('FPC_CPUCROSSCOMPILING');
  1877. if tf_winlikewidestring in target_info.flags then
  1878. def_system_macro('FPC_WINLIKEWIDESTRING');
  1879. { read configuration file }
  1880. if (not disable_configfile) and
  1881. (ppccfg<>'') then
  1882. begin
  1883. read_configfile:=check_configfile(ppccfg,ppccfg);
  1884. { Maybe alternative configfile ? }
  1885. if (not read_configfile) and
  1886. (ppcaltcfg<>'') then
  1887. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1888. end
  1889. else
  1890. read_configfile := false;
  1891. { Read commandline and configfile }
  1892. param_file:='';
  1893. { read configfile }
  1894. if read_configfile then
  1895. option.interpret_file(ppccfg);
  1896. { read parameters again to override config file }
  1897. if cmd<>'' then
  1898. option.parsecmd(cmd)
  1899. else
  1900. begin
  1901. { Write help pages if no parameters are passed }
  1902. if (paramcount=0) then
  1903. Option.WriteHelpPages;
  1904. option.read_parameters;
  1905. { Write only quickinfo }
  1906. if option.quickinfo<>'' then
  1907. option.writequickinfo;
  1908. end;
  1909. { Stop if errors in options }
  1910. if ErrorCount>0 then
  1911. StopOptions(1);
  1912. { Write logo }
  1913. if option.ParaLogo then
  1914. option.writelogo;
  1915. { Non-core target defines }
  1916. Option.TargetDefines(true);
  1917. { endian define }
  1918. case target_info.endian of
  1919. endian_little :
  1920. begin
  1921. def_system_macro('ENDIAN_LITTLE');
  1922. def_system_macro('FPC_LITTLE_ENDIAN');
  1923. end;
  1924. endian_big :
  1925. begin
  1926. def_system_macro('ENDIAN_BIG');
  1927. def_system_macro('FPC_BIG_ENDIAN');
  1928. end;
  1929. end;
  1930. { abi define }
  1931. case target_info.abi of
  1932. abi_powerpc_sysv :
  1933. def_system_macro('FPC_ABI_SYSV');
  1934. abi_powerpc_aix :
  1935. def_system_macro('FPC_ABI_AIX');
  1936. end;
  1937. { CPU Define }
  1938. def_system_macro('CPU'+Cputypestr[initcputype]);
  1939. { Check file to compile }
  1940. if param_file='' then
  1941. begin
  1942. Message(option_no_source_found);
  1943. StopOptions(1);
  1944. end;
  1945. {$ifndef Unix}
  1946. param_file:=FixFileName(param_file);
  1947. {$endif}
  1948. {$IFDEF USE_SYSUTILS}
  1949. inputdir := SplitPath(param_file);
  1950. inputfile := SplitName(param_file);
  1951. inputextension := SplitExtension(param_file);
  1952. {$ELSE USE_SYSUTILS}
  1953. fsplit(param_file,inputdir,inputfile,inputextension);
  1954. {$ENDIF USE_SYSUTILS}
  1955. if inputextension='' then
  1956. begin
  1957. if FileExists(inputdir+inputfile+sourceext) then
  1958. inputextension:=sourceext
  1959. else if FileExists(inputdir+inputfile+pasext) then
  1960. inputextension:=pasext
  1961. else if ((m_mac in aktmodeswitches) or
  1962. (tf_p_ext_support in target_info.flags))
  1963. and FileExists(inputdir+inputfile+pext) then
  1964. inputextension:=pext;
  1965. end;
  1966. { Check output dir }
  1967. if (OutputExeDir<>'') and
  1968. not PathExists(OutputExeDir) then
  1969. begin
  1970. Message1(general_e_path_does_not_exist,OutputExeDir);
  1971. StopOptions(1);
  1972. end;
  1973. { Add paths specified with parameters to the searchpaths }
  1974. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1975. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1976. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1977. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1978. { add unit environment and exepath to the unit search path }
  1979. if inputdir<>'' then
  1980. Unitsearchpath.AddPath(inputdir,true);
  1981. if not disable_configfile then
  1982. begin
  1983. {$IFDEF USE_SYSUTILS}
  1984. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  1985. {$ELSE USE_SYSUTILS}
  1986. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1987. {$ENDIF USE_SYSUTILS}
  1988. end;
  1989. {$ifdef Unix}
  1990. {$IFDEF USE_SYSUTILS}
  1991. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1992. {$ELSE USE_SYSUTILS}
  1993. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1994. {$ENDIF USE_SYSUTILS}
  1995. if fpcdir='' then
  1996. begin
  1997. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1998. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1999. else
  2000. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2001. end;
  2002. {$else}
  2003. {$IFDEF USE_SYSUTILS}
  2004. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2005. {$ELSE USE_SYSUTILS}
  2006. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2007. {$ENDIF USE_SYSUTILS}
  2008. if fpcdir='' then
  2009. begin
  2010. fpcdir:=ExePath+'../';
  2011. if not(PathExists(fpcdir+'/units')) and
  2012. not(PathExists(fpcdir+'/rtl')) then
  2013. fpcdir:=fpcdir+'../';
  2014. end;
  2015. {$endif}
  2016. { first try development RTL, else use the default installation path }
  2017. if not disable_configfile then
  2018. begin
  2019. if PathExists(FpcDir+'rtl') then
  2020. if tf_use_8_3 in Source_Info.Flags then
  2021. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2022. else
  2023. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2024. else
  2025. if tf_use_8_3 in Source_Info.Flags then
  2026. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2027. else
  2028. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2029. end;
  2030. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2031. Do not add it when linking on the target because then we can maybe already find
  2032. .o files that are not for the target }
  2033. if (ExePath<>GetCurrentDir) and
  2034. not(cs_link_on_target in initglobalswitches) then
  2035. UnitSearchPath.AddPath(ExePath,false);
  2036. { Add unit dir to the object and library path }
  2037. objectsearchpath.AddList(unitsearchpath,false);
  2038. librarysearchpath.AddList(unitsearchpath,false);
  2039. { maybe override debug info format }
  2040. if (paratargetdbg<>dbg_none) then
  2041. set_target_dbg(paratargetdbg);
  2042. { maybe override assembler }
  2043. if (paratargetasm<>as_none) then
  2044. begin
  2045. if not set_target_asm(paratargetasm) then
  2046. begin
  2047. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2048. set_target_asm(target_info.assemextern);
  2049. Message1(option_asm_forced,target_asm.idtxt);
  2050. end;
  2051. end;
  2052. { switch assembler if it's binary and we got -a on the cmdline }
  2053. if (cs_asm_leave in initglobalswitches) and
  2054. (af_outputbinary in target_asm.flags) then
  2055. begin
  2056. Message(option_switch_bin_to_src_assembler);
  2057. set_target_asm(target_info.assemextern);
  2058. end;
  2059. { disable internal linker if it is not registered or
  2060. if we skip the linking }
  2061. if not(cs_link_extern in initglobalswitches) and
  2062. (not assigned(target_info.link) or
  2063. (cs_link_nolink in initglobalswitches)) then
  2064. exclude(initglobalswitches,cs_link_extern);
  2065. { turn off stripping if compiling with debuginfo or profile }
  2066. if (cs_debuginfo in initmoduleswitches) or
  2067. (cs_profile in initmoduleswitches) then
  2068. exclude(initglobalswitches,cs_link_strip);
  2069. { force fpu emulation on arm/wince }
  2070. if target_info.system=system_arm_wince then
  2071. include(initmoduleswitches,cs_fp_emulation);
  2072. { Section smartlinking conflicts with import sections on Windows }
  2073. if GenerateImportSection and
  2074. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2075. exclude(target_info.flags,tf_smartlink_sections);
  2076. if (cs_link_extern in initglobalswitches) then
  2077. begin
  2078. { By default don't create import section if we use the internal linker }
  2079. if not GenerateImportSectionSetExplicitly then
  2080. GenerateImportSection:=false;
  2081. { Enable section smartlinking }
  2082. include(target_info.flags,tf_smartlink_sections);
  2083. end;
  2084. {$ifdef x86_64}
  2085. {$warning HACK: turn off smartlinking}
  2086. exclude(initmoduleswitches,cs_create_smart);
  2087. {$endif}
  2088. if not LinkTypeSetExplicitly then
  2089. set_default_link_type;
  2090. { Default alignment settings,
  2091. 1. load the defaults for the target
  2092. 2. override with generic optimizer setting (little size)
  2093. 3. override with the user specified -Oa }
  2094. UpdateAlignment(initalignment,target_info.alignment);
  2095. if (cs_opt_size in aktoptimizerswitches) then
  2096. begin
  2097. initalignment.procalign:=1;
  2098. initalignment.jumpalign:=1;
  2099. initalignment.loopalign:=1;
  2100. end;
  2101. UpdateAlignment(initalignment,option.paraalignment);
  2102. set_system_macro('FPC_VERSION',version_nr);
  2103. set_system_macro('FPC_RELEASE',release_nr);
  2104. set_system_macro('FPC_PATCH',patch_nr);
  2105. option.free;
  2106. Option:=nil;
  2107. end;
  2108. initialization
  2109. coption:=toption;
  2110. finalization
  2111. if assigned(option) then
  2112. option.free;
  2113. end.