options.pas 68 KB

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