options.pas 69 KB

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