options.pas 67 KB

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