options.pas 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298
  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' :
  690. begin
  691. if UnsetBool(More, 0) then
  692. begin
  693. exclude(initmoduleswitches,cs_debuginfo);
  694. exclude(initglobalswitches,cs_use_heaptrc);
  695. exclude(initglobalswitches,cs_use_lineinfo);
  696. exclude(initlocalswitches,cs_checkpointer);
  697. localvartrashing := -1;
  698. end
  699. else
  700. begin
  701. include(initmoduleswitches,cs_debuginfo);
  702. end;
  703. if not RelocSectionSetExplicitly then
  704. RelocSection:=false;
  705. j:=1;
  706. while j<=length(more) do
  707. begin
  708. case more[j] of
  709. 'c' :
  710. begin
  711. if UnsetBool(More, j) then
  712. exclude(initlocalswitches,cs_checkpointer)
  713. else
  714. include(initlocalswitches,cs_checkpointer);
  715. end;
  716. 'd' :
  717. begin
  718. paratargetdbg:=dbg_dwarf2;
  719. end;
  720. 'h' :
  721. begin
  722. if UnsetBool(More, j) then
  723. exclude(initglobalswitches,cs_use_heaptrc)
  724. else
  725. include(initglobalswitches,cs_use_heaptrc);
  726. end;
  727. 'l' :
  728. begin
  729. if UnsetBool(More, j) then
  730. exclude(initglobalswitches,cs_use_lineinfo)
  731. else
  732. include(initglobalswitches,cs_use_lineinfo);
  733. end;
  734. 's' :
  735. begin
  736. paratargetdbg:=dbg_stabs;
  737. end;
  738. 't' :
  739. begin
  740. if UnsetBool(More, j) then
  741. localvartrashing := -1
  742. else
  743. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  744. end;
  745. 'v' :
  746. begin
  747. if UnsetBool(More, j) then
  748. exclude(initglobalswitches,cs_gdb_valgrind)
  749. else
  750. include(initglobalswitches,cs_gdb_valgrind);
  751. end;
  752. 'w' :
  753. begin
  754. if (j<length(more)) and (more[j+1] in ['2','3']) then
  755. begin
  756. case more[j+1] of
  757. '2': paratargetdbg:=dbg_dwarf2;
  758. '3': paratargetdbg:=dbg_dwarf3;
  759. end;
  760. inc(j);
  761. end
  762. else
  763. paratargetdbg:=dbg_dwarf2;
  764. end;
  765. else
  766. IllegalPara(opt);
  767. end;
  768. inc(j);
  769. end;
  770. end;
  771. 'h' :
  772. begin
  773. NoPressEnter:=true;
  774. WriteHelpPages;
  775. end;
  776. 'i' :
  777. begin
  778. if More='' then
  779. WriteInfo
  780. else
  781. QuickInfo:=QuickInfo+More;
  782. end;
  783. 'I' :
  784. begin
  785. if ispara then
  786. ParaIncludePath.AddPath(More,false)
  787. else
  788. includesearchpath.AddPath(More,false);
  789. end;
  790. 'k' :
  791. begin
  792. if more<>'' then
  793. ParaLinkOptions:=ParaLinkOptions+' '+More
  794. else
  795. IllegalPara(opt);
  796. end;
  797. 'l' :
  798. if not UnSetBool(more,0) then
  799. ParaLogo:=true;
  800. 'm' :
  801. parapreprocess:=not UnSetBool(more,0);
  802. 'M' :
  803. begin
  804. more:=Upper(more);
  805. if not SetCompileMode(more, true) then
  806. IllegalPara(opt);
  807. end;
  808. 'n' :
  809. begin
  810. if More='' then
  811. disable_configfile:=true
  812. else
  813. IllegalPara(opt);
  814. end;
  815. 'o' :
  816. begin
  817. if More<>'' then
  818. begin
  819. DefaultReplacements(More);
  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+3,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,cs_link_nolink];
  929. if more<>'' then
  930. IllegalPara(opt);
  931. end
  932. else
  933. begin
  934. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  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(initlocalswitches,cs_do_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. 'v' :
  994. include(initglobalswitches,cs_support_vectors);
  995. 'x' :
  996. include(initglobalswitches,cs_support_exceptions);
  997. '-' :
  998. begin
  999. initglobalswitches:=initglobalswitches - [cs_constructor_name,cs_support_exceptions];
  1000. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  1001. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  1002. cs_support_macro,
  1003. cs_static_keyword];
  1004. end;
  1005. else
  1006. IllegalPara(opt);
  1007. end;
  1008. inc(j);
  1009. end;
  1010. end;
  1011. end;
  1012. 'T' :
  1013. begin
  1014. more:=Upper(More);
  1015. if paratarget=system_none then
  1016. begin
  1017. { remove old target define }
  1018. TargetDefines(false);
  1019. { load new target }
  1020. paratarget:=find_system_by_string(More);
  1021. if paratarget<>system_none then
  1022. set_target(paratarget)
  1023. else
  1024. IllegalPara(opt);
  1025. { set new define }
  1026. TargetDefines(true);
  1027. end
  1028. else
  1029. if More<>upper(target_info.shortname) then
  1030. Message1(option_target_is_already_set,target_info.shortname);
  1031. end;
  1032. 'u' :
  1033. if more <> '' then
  1034. undef_system_macro(more);
  1035. 'U' :
  1036. begin
  1037. j:=1;
  1038. while j<=length(more) do
  1039. begin
  1040. case more[j] of
  1041. {$ifdef UNITALIASES}
  1042. 'a' :
  1043. begin
  1044. AddUnitAlias(Copy(More,j+1,255));
  1045. break;
  1046. end;
  1047. {$endif UNITALIASES}
  1048. 'n' :
  1049. exclude(initglobalswitches,cs_check_unit_name);
  1050. 'p' :
  1051. begin
  1052. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1053. break;
  1054. end;
  1055. 'r' :
  1056. do_release:=true;
  1057. 's' :
  1058. include(initmoduleswitches,cs_compilesystem);
  1059. '-' :
  1060. begin
  1061. exclude(initmoduleswitches,cs_compilesystem);
  1062. exclude(initglobalswitches,cs_check_unit_name);
  1063. end;
  1064. else
  1065. IllegalPara(opt);
  1066. end;
  1067. inc(j);
  1068. end;
  1069. end;
  1070. 'v' :
  1071. begin
  1072. if not setverbosity(More) then
  1073. IllegalPara(opt);
  1074. end;
  1075. 'V' : ; { Ignore used by fpc }
  1076. 'W' :
  1077. begin
  1078. j:=1;
  1079. while j<=length(More) do
  1080. begin
  1081. case More[j] of
  1082. 'A':
  1083. begin
  1084. if UnsetBool(More, j) then
  1085. apptype:=app_native
  1086. else
  1087. apptype:=app_cui;
  1088. end;
  1089. 'B':
  1090. begin
  1091. { -WB200000 means set trefered base address
  1092. to $200000, but does not change relocsection boolean
  1093. this way we can create both relocatble and
  1094. non relocatable DLL at a specific base address PM }
  1095. if (length(More)>j) then
  1096. begin
  1097. if DLLImageBase=nil then
  1098. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1099. end
  1100. else
  1101. begin
  1102. RelocSection:=true;
  1103. RelocSectionSetExplicitly:=true;
  1104. end;
  1105. break;
  1106. end;
  1107. 'C':
  1108. begin
  1109. if UnsetBool(More, j) then
  1110. apptype:=app_gui
  1111. else
  1112. apptype:=app_cui;
  1113. end;
  1114. 'D':
  1115. begin
  1116. UseDeffileForExports:=not UnsetBool(More, j);
  1117. UseDeffileForExportsSetExplicitly:=true;
  1118. end;
  1119. 'F':
  1120. begin
  1121. if UnsetBool(More, j) then
  1122. apptype:=app_cui
  1123. else
  1124. apptype:=app_fs;
  1125. end;
  1126. 'G':
  1127. begin
  1128. if UnsetBool(More, j) then
  1129. apptype:=app_cui
  1130. else
  1131. apptype:=app_gui;
  1132. end;
  1133. 'I':
  1134. begin
  1135. GenerateImportSection:=not UnsetBool(More,j);
  1136. GenerateImportSectionSetExplicitly:=true;
  1137. end;
  1138. 'N':
  1139. begin
  1140. RelocSection:=UnsetBool(More,j);
  1141. RelocSectionSetExplicitly:=true;
  1142. end;
  1143. 'R':
  1144. begin
  1145. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1146. RelocSection:=not UnsetBool(More,j);
  1147. RelocSectionSetExplicitly:=true;
  1148. end;
  1149. 'T':
  1150. begin
  1151. if UnsetBool(More, j) then
  1152. apptype:=app_cui
  1153. else
  1154. apptype:=app_tool;
  1155. end;
  1156. else
  1157. IllegalPara(opt);
  1158. end;
  1159. inc(j);
  1160. end;
  1161. end;
  1162. 'X' :
  1163. begin
  1164. j:=1;
  1165. while j<=length(more) do
  1166. begin
  1167. case More[j] of
  1168. 'c' : Cshared:=TRUE;
  1169. 'd' : Dontlinkstdlibpath:=TRUE;
  1170. 'e' :
  1171. begin
  1172. If UnsetBool(More, j) then
  1173. exclude(initglobalswitches,cs_link_extern)
  1174. else
  1175. include(initglobalswitches,cs_link_extern);
  1176. end;
  1177. 'f' :
  1178. include(initglobalswitches,cs_link_pthread);
  1179. 'i' :
  1180. begin
  1181. If UnsetBool(More, j) then
  1182. include(initglobalswitches,cs_link_extern)
  1183. else
  1184. exclude(initglobalswitches,cs_link_extern);
  1185. end;
  1186. 'm' :
  1187. begin
  1188. If UnsetBool(More, j) then
  1189. exclude(initglobalswitches,cs_link_map)
  1190. else
  1191. include(initglobalswitches,cs_link_map);
  1192. end;
  1193. 'r' :
  1194. begin
  1195. rlinkpath:=Copy(more,2,length(More)-1);
  1196. DefaultReplacements(rlinkpath);
  1197. More:='';
  1198. end;
  1199. 's' :
  1200. begin
  1201. If UnsetBool(More, j) then
  1202. exclude(initglobalswitches,cs_link_strip)
  1203. else
  1204. include(initglobalswitches,cs_link_strip);
  1205. end;
  1206. 't' :
  1207. include(initglobalswitches,cs_link_staticflag);
  1208. 'v' :
  1209. begin
  1210. If UnsetBool(More, j) then
  1211. exclude(initglobalswitches,cs_link_opt_vtable)
  1212. else
  1213. include(initglobalswitches,cs_link_opt_vtable);
  1214. end;
  1215. 'D' :
  1216. begin
  1217. def_system_macro('FPC_LINK_DYNAMIC');
  1218. undef_system_macro('FPC_LINK_SMART');
  1219. undef_system_macro('FPC_LINK_STATIC');
  1220. exclude(initglobalswitches,cs_link_static);
  1221. exclude(initglobalswitches,cs_link_smart);
  1222. include(initglobalswitches,cs_link_shared);
  1223. LinkTypeSetExplicitly:=true;
  1224. end;
  1225. 'M' :
  1226. begin
  1227. mainaliasname:=Copy(more,2,length(More)-1);
  1228. More:='';
  1229. end;
  1230. 'P' :
  1231. begin
  1232. utilsprefix:=Copy(more,2,length(More)-1);
  1233. DefaultReplacements(utilsprefix);
  1234. More:='';
  1235. end;
  1236. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1237. // these are not aggregable.
  1238. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1239. IllegalPara(opt)
  1240. else
  1241. begin
  1242. case more[j+1] of
  1243. 'A' : begin
  1244. s:=Copy(more,3,length(More)-2);
  1245. if not LinkLibraryAliases.AddDep(s) Then
  1246. IllegalPara(opt);
  1247. end;
  1248. 'O' : begin
  1249. s:=Copy(more,3,length(More)-2);
  1250. if not LinkLibraryOrder.AddWeight(s) Then
  1251. IllegalPara(opt);
  1252. end;
  1253. 'D' : include(initglobalswitches,cs_link_no_default_lib_order)
  1254. else
  1255. IllegalPara(opt);
  1256. end; {case}
  1257. j:=length(more);
  1258. end; {else begin}
  1259. end;
  1260. 'S' :
  1261. begin
  1262. def_system_macro('FPC_LINK_STATIC');
  1263. undef_system_macro('FPC_LINK_SMART');
  1264. undef_system_macro('FPC_LINK_DYNAMIC');
  1265. include(initglobalswitches,cs_link_static);
  1266. exclude(initglobalswitches,cs_link_smart);
  1267. exclude(initglobalswitches,cs_link_shared);
  1268. LinkTypeSetExplicitly:=true;
  1269. end;
  1270. 'X' :
  1271. begin
  1272. def_system_macro('FPC_LINK_SMART');
  1273. undef_system_macro('FPC_LINK_STATIC');
  1274. undef_system_macro('FPC_LINK_DYNAMIC');
  1275. exclude(initglobalswitches,cs_link_static);
  1276. include(initglobalswitches,cs_link_smart);
  1277. exclude(initglobalswitches,cs_link_shared);
  1278. LinkTypeSetExplicitly:=true;
  1279. end;
  1280. '-' :
  1281. begin
  1282. exclude(initglobalswitches,cs_link_staticflag);
  1283. exclude(initglobalswitches,cs_link_strip);
  1284. exclude(initglobalswitches,cs_link_map);
  1285. set_default_link_type;
  1286. end;
  1287. else
  1288. IllegalPara(opt);
  1289. end;
  1290. inc(j);
  1291. end;
  1292. end;
  1293. end;
  1294. end;
  1295. '@' :
  1296. begin
  1297. Message(option_no_nested_response_file);
  1298. StopOptions(1);
  1299. end;
  1300. else
  1301. begin
  1302. if (length(param_file)<>0) then
  1303. Message(option_only_one_source_support);
  1304. param_file:=opt;
  1305. Message1(option_found_file,opt);
  1306. end;
  1307. end;
  1308. end;
  1309. procedure Toption.Interpret_file(const filename : string);
  1310. procedure RemoveSep(var fn:string);
  1311. var
  1312. i : longint;
  1313. begin
  1314. i:=0;
  1315. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1316. inc(i);
  1317. Delete(fn,1,i);
  1318. i:=length(fn);
  1319. while (i>0) and (fn[i] in [',',' ',#9]) do
  1320. dec(i);
  1321. fn:=copy(fn,1,i);
  1322. end;
  1323. function GetName(var fn:string):string;
  1324. var
  1325. i : longint;
  1326. begin
  1327. i:=0;
  1328. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1329. inc(i);
  1330. GetName:=Copy(fn,1,i);
  1331. Delete(fn,1,i);
  1332. end;
  1333. const
  1334. maxlevel=16;
  1335. var
  1336. f : text;
  1337. s, tmp,
  1338. opts : string;
  1339. skip : array[0..maxlevel-1] of boolean;
  1340. level : longint;
  1341. option_read : boolean;
  1342. begin
  1343. { avoid infinite loop }
  1344. Inc(FileLevel);
  1345. Option_read:=false;
  1346. If FileLevel>MaxLevel then
  1347. Message(option_too_many_cfg_files);
  1348. { Maybe It's Directory ?} //Jaro Change:
  1349. if DirectoryExists(filename) then
  1350. begin
  1351. Message1(option_config_is_dir,filename);
  1352. exit;
  1353. end;
  1354. { open file }
  1355. Message1(option_using_file,filename);
  1356. {$ifdef USE_SYSUTILS}
  1357. assign(f,ExpandFileName(filename));
  1358. {$else USE_SYSUTILS}
  1359. assign(f,FExpand(filename));
  1360. {$endif USE_SYsUTILS}
  1361. {$I-}
  1362. reset(f);
  1363. {$I+}
  1364. if ioresult<>0 then
  1365. begin
  1366. Message1(option_unable_open_file,filename);
  1367. exit;
  1368. end;
  1369. Message1(option_start_reading_configfile,filename);
  1370. fillchar(skip,sizeof(skip),0);
  1371. level:=0;
  1372. while not eof(f) do
  1373. begin
  1374. readln(f,opts);
  1375. RemoveSep(opts);
  1376. if (opts<>'') and (opts[1]<>';') then
  1377. begin
  1378. if opts[1]='#' then
  1379. begin
  1380. Message1(option_interpreting_file_option,opts);
  1381. Delete(opts,1,1);
  1382. s:=upper(GetName(opts));
  1383. if (s='SECTION') then
  1384. begin
  1385. RemoveSep(opts);
  1386. s:=upper(GetName(opts));
  1387. if level=0 then
  1388. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1389. end
  1390. else
  1391. if (s='IFDEF') then
  1392. begin
  1393. RemoveSep(opts);
  1394. if Level>=maxlevel then
  1395. begin
  1396. Message(option_too_many_ifdef);
  1397. stopOptions(1);
  1398. end;
  1399. inc(Level);
  1400. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1401. end
  1402. else
  1403. if (s='IFNDEF') then
  1404. begin
  1405. RemoveSep(opts);
  1406. if Level>=maxlevel then
  1407. begin
  1408. Message(option_too_many_ifdef);
  1409. stopOptions(1);
  1410. end;
  1411. inc(Level);
  1412. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1413. end
  1414. else
  1415. if (s='ELSE') then
  1416. skip[level]:=skip[level-1] or (not skip[level])
  1417. else
  1418. if (s='ENDIF') then
  1419. begin
  1420. skip[level]:=false;
  1421. if Level=0 then
  1422. begin
  1423. Message(option_too_many_endif);
  1424. stopOptions(1);
  1425. end;
  1426. dec(level);
  1427. end
  1428. else
  1429. if (not skip[level]) then
  1430. begin
  1431. if (s='DEFINE') then
  1432. begin
  1433. RemoveSep(opts);
  1434. tmp:= GetName(opts);
  1435. if tmp <> '' then
  1436. def_system_macro(tmp);
  1437. end
  1438. else
  1439. if (s='UNDEF') then
  1440. begin
  1441. RemoveSep(opts);
  1442. tmp:= GetName(opts);
  1443. if tmp <> '' then
  1444. undef_system_macro(tmp);
  1445. end
  1446. else
  1447. if (s='WRITE') then
  1448. begin
  1449. Delete(opts,1,1);
  1450. WriteLn(opts);
  1451. end
  1452. else
  1453. if (s='INCLUDE') then
  1454. begin
  1455. Delete(opts,1,1);
  1456. Interpret_file(opts);
  1457. end;
  1458. end;
  1459. end
  1460. else
  1461. begin
  1462. if (opts[1]='-') or (opts[1]='@') then
  1463. begin
  1464. if (not skip[level]) then
  1465. interpret_option(opts,false);
  1466. Option_read:=true;
  1467. end
  1468. else
  1469. Message1(option_illegal_para,opts);
  1470. end;
  1471. end;
  1472. end;
  1473. if Level>0 then
  1474. Message(option_too_less_endif);
  1475. if Not Option_read then
  1476. Message1(option_no_option_found,filename)
  1477. else
  1478. Message1(option_end_reading_configfile,filename);
  1479. Close(f);
  1480. Dec(FileLevel);
  1481. end;
  1482. procedure Toption.Interpret_envvar(const envname : string);
  1483. var
  1484. argstart,
  1485. env,
  1486. pc : pchar;
  1487. arglen : longint;
  1488. quote : set of char;
  1489. hs : string;
  1490. begin
  1491. Message1(option_using_env,envname);
  1492. env:=GetEnvPChar(envname);
  1493. pc:=env;
  1494. if assigned(pc) then
  1495. begin
  1496. repeat
  1497. { skip leading spaces }
  1498. while pc^ in [' ',#9,#13] do
  1499. inc(pc);
  1500. case pc^ of
  1501. #0 :
  1502. break;
  1503. '"' :
  1504. begin
  1505. quote:=['"'];
  1506. inc(pc);
  1507. end;
  1508. '''' :
  1509. begin
  1510. quote:=[''''];
  1511. inc(pc);
  1512. end;
  1513. else
  1514. quote:=[' ',#9,#13];
  1515. end;
  1516. { scan until the end of the argument }
  1517. argstart:=pc;
  1518. while (pc^<>#0) and not(pc^ in quote) do
  1519. inc(pc);
  1520. { create argument }
  1521. arglen:=pc-argstart;
  1522. hs[0]:=chr(arglen);
  1523. move(argstart^,hs[1],arglen);
  1524. interpret_option(hs,true);
  1525. { skip quote }
  1526. if pc^ in quote then
  1527. inc(pc);
  1528. until false;
  1529. end
  1530. else
  1531. Message1(option_no_option_found,'(env) '+envname);
  1532. FreeEnvPChar(env);
  1533. end;
  1534. procedure toption.read_parameters;
  1535. var
  1536. opts : string;
  1537. paramindex : longint;
  1538. begin
  1539. paramindex:=0;
  1540. while paramindex<paramcount do
  1541. begin
  1542. inc(paramindex);
  1543. opts:=system.paramstr(paramindex);
  1544. case opts[1] of
  1545. '@' :
  1546. if not firstpass then
  1547. begin
  1548. Delete(opts,1,1);
  1549. Message1(option_reading_further_from,opts);
  1550. interpret_file(opts);
  1551. end;
  1552. '!' :
  1553. if not firstpass then
  1554. begin
  1555. Delete(opts,1,1);
  1556. Message1(option_reading_further_from,'(env) '+opts);
  1557. interpret_envvar(opts);
  1558. end;
  1559. else
  1560. interpret_option(opts,true);
  1561. end;
  1562. end;
  1563. end;
  1564. procedure toption.parsecmd(cmd:string);
  1565. var
  1566. i,ps : longint;
  1567. opts : string;
  1568. begin
  1569. while (cmd<>'') do
  1570. begin
  1571. while cmd[1]=' ' do
  1572. delete(cmd,1,1);
  1573. i:=pos(' ',cmd);
  1574. if i=0 then
  1575. i:=256;
  1576. opts:=Copy(cmd,1,i-1);
  1577. Delete(cmd,1,i);
  1578. case opts[1] of
  1579. '@' :
  1580. if not firstpass then
  1581. begin
  1582. Delete(opts,1,1);
  1583. Message1(option_reading_further_from,opts);
  1584. interpret_file(opts);
  1585. end;
  1586. '!' :
  1587. if not firstpass then
  1588. begin
  1589. Delete(opts,1,1);
  1590. Message1(option_reading_further_from,'(env) '+opts);
  1591. interpret_envvar(opts);
  1592. end;
  1593. '"' :
  1594. begin
  1595. Delete(opts,1,1);
  1596. ps:=pos('"',cmd);
  1597. if (i<>256) and (ps>0) then
  1598. begin
  1599. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1600. cmd:=copy(cmd,ps+1,255);
  1601. end;
  1602. interpret_option(opts,true);
  1603. end;
  1604. else
  1605. interpret_option(opts,true);
  1606. end;
  1607. end;
  1608. end;
  1609. procedure toption.writequickinfo;
  1610. var
  1611. s : string;
  1612. i : longint;
  1613. procedure addinfo(const hs:string);
  1614. begin
  1615. if s<>'' then
  1616. s:=s+' '+hs
  1617. else
  1618. s:=hs;
  1619. end;
  1620. begin
  1621. s:='';
  1622. i:=0;
  1623. while (i<length(quickinfo)) do
  1624. begin
  1625. inc(i);
  1626. case quickinfo[i] of
  1627. 'S' :
  1628. begin
  1629. inc(i);
  1630. case quickinfo[i] of
  1631. 'O' :
  1632. addinfo(lower(source_info.shortname));
  1633. 'P' :
  1634. addinfo(source_cpu_string);
  1635. else
  1636. IllegalPara('-i'+QuickInfo);
  1637. end;
  1638. end;
  1639. 'T' :
  1640. begin
  1641. inc(i);
  1642. case quickinfo[i] of
  1643. 'O' :
  1644. addinfo(lower(target_info.shortname));
  1645. 'P' :
  1646. AddInfo(target_cpu_string);
  1647. else
  1648. IllegalPara('-i'+QuickInfo);
  1649. end;
  1650. end;
  1651. 'V' :
  1652. AddInfo(version_string);
  1653. 'W' :
  1654. AddInfo(full_version_string);
  1655. 'D' :
  1656. AddInfo(date_string);
  1657. '_' :
  1658. ;
  1659. else
  1660. IllegalPara('-i'+QuickInfo);
  1661. end;
  1662. end;
  1663. if s<>'' then
  1664. begin
  1665. writeln(s);
  1666. stopoptions(0);
  1667. end;
  1668. end;
  1669. procedure TOption.TargetDefines(def:boolean);
  1670. var
  1671. s : string;
  1672. i : integer;
  1673. begin
  1674. if def then
  1675. def_system_macro(target_info.shortname)
  1676. else
  1677. undef_system_macro(target_info.shortname);
  1678. s:=target_info.extradefines;
  1679. while (s<>'') do
  1680. begin
  1681. i:=pos(';',s);
  1682. if i=0 then
  1683. i:=length(s)+1;
  1684. if def then
  1685. def_system_macro(Copy(s,1,i-1))
  1686. else
  1687. undef_system_macro(Copy(s,1,i-1));
  1688. delete(s,1,i);
  1689. end;
  1690. end;
  1691. constructor TOption.create;
  1692. begin
  1693. LogoWritten:=false;
  1694. NoPressEnter:=false;
  1695. FirstPass:=false;
  1696. FileLevel:=0;
  1697. Quickinfo:='';
  1698. ParaIncludePath:=TSearchPathList.Create;
  1699. ParaObjectPath:=TSearchPathList.Create;
  1700. ParaUnitPath:=TSearchPathList.Create;
  1701. ParaLibraryPath:=TSearchPathList.Create;
  1702. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1703. end;
  1704. destructor TOption.destroy;
  1705. begin
  1706. ParaIncludePath.Free;
  1707. ParaObjectPath.Free;
  1708. ParaUnitPath.Free;
  1709. ParaLibraryPath.Free;
  1710. end;
  1711. {****************************************************************************
  1712. Callable Routines
  1713. ****************************************************************************}
  1714. function check_configfile(const fn:string;var foundfn:string):boolean;
  1715. function CfgFileExists(const fn:string):boolean;
  1716. begin
  1717. Comment(V_Tried,'Configfile search: '+fn);
  1718. CfgFileExists:=FileExists(fn);
  1719. end;
  1720. var
  1721. configpath : pathstr;
  1722. begin
  1723. foundfn:=fn;
  1724. check_configfile:=true;
  1725. { retrieve configpath }
  1726. {$IFDEF USE_SYSUTILS}
  1727. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1728. {$ELSE USE_SYSUTILS}
  1729. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1730. {$ENDIF USE_SYSUTILS}
  1731. {$ifdef Unix}
  1732. if configpath='' then
  1733. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1734. {$endif}
  1735. {
  1736. Order to read configuration file :
  1737. try reading fpc.cfg in :
  1738. 1 - current dir
  1739. 2 - configpath
  1740. 3 - compiler path
  1741. }
  1742. if not FileExists(fn) then
  1743. begin
  1744. {$ifdef Unix}
  1745. {$IFDEF USE_SYSUTILS}
  1746. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1747. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1748. {$ELSE USE_SYSUTILS}
  1749. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1750. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1751. {$ENDIF USE_SYSUTILS}
  1752. else
  1753. {$endif}
  1754. if CfgFileExists(configpath+fn) then
  1755. foundfn:=configpath+fn
  1756. else
  1757. {$ifndef Unix}
  1758. if CfgFileExists(exepath+fn) then
  1759. foundfn:=exepath+fn
  1760. else
  1761. {$else}
  1762. if CfgFileExists('/etc/'+fn) then
  1763. foundfn:='/etc/'+fn
  1764. else
  1765. {$endif}
  1766. check_configfile:=false;
  1767. end;
  1768. end;
  1769. procedure read_arguments(cmd:string);
  1770. begin
  1771. option:=coption.create;
  1772. disable_configfile:=false;
  1773. { get default messagefile }
  1774. {$IFDEF USE_SYSUTILS}
  1775. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1776. {$ELSE USE_SYSUTILS}
  1777. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1778. {$ENDIF USE_SYSUTILS}
  1779. { default configfile can be specified on the commandline,
  1780. remove it first }
  1781. if (cmd<>'') and (cmd[1]='[') then
  1782. begin
  1783. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1784. Delete(cmd,1,pos(']',cmd));
  1785. end
  1786. else
  1787. begin
  1788. ppccfg:='fpc.cfg';
  1789. ppcaltcfg:='ppc386.cfg';
  1790. end;
  1791. { first pass reading of parameters, only -i -v -T etc.}
  1792. option.firstpass:=true;
  1793. if cmd<>'' then
  1794. option.parsecmd(cmd)
  1795. else
  1796. begin
  1797. option.read_parameters;
  1798. { Write only quickinfo }
  1799. if option.quickinfo<>'' then
  1800. option.writequickinfo;
  1801. end;
  1802. option.firstpass:=false;
  1803. { target is set here, for wince the default app type is gui }
  1804. if target_info.system in system_wince then
  1805. apptype:=app_gui;
  1806. { default defines }
  1807. def_system_macro(target_info.shortname);
  1808. def_system_macro('FPC');
  1809. def_system_macro('VER'+version_nr);
  1810. def_system_macro('VER'+version_nr+'_'+release_nr);
  1811. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1812. { Temporary defines, until things settle down }
  1813. { "main" symbol is generated in the main program, and left out of the system unit }
  1814. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1815. def_system_macro('FPC_DARWIN_JMP_MAIN');
  1816. def_system_macro('COMPPROCINLINEFIXED');
  1817. def_system_macro('PARAOUTFILE');
  1818. def_system_macro('RESSTRSECTIONS');
  1819. def_system_macro('FPC_HASFIXED64BITVARIANT');
  1820. {$ifdef x86}
  1821. { def_system_macro('INTERNAL_BACKTRACE');}
  1822. {$endif}
  1823. def_system_macro('STR_CONCAT_PROCS');
  1824. if pocall_default = pocall_register then
  1825. def_system_macro('REGCALL');
  1826. { using a case is pretty useless here (FK) }
  1827. { some stuff for TP compatibility }
  1828. {$ifdef i386}
  1829. def_system_macro('CPU86');
  1830. def_system_macro('CPU87');
  1831. def_system_macro('CPU386');
  1832. {$endif}
  1833. {$ifdef m68k}
  1834. def_system_macro('CPU68');
  1835. {$endif}
  1836. { new processor stuff }
  1837. {$ifdef i386}
  1838. def_system_macro('CPUI386');
  1839. def_system_macro('CPU32');
  1840. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1841. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1842. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1843. def_system_macro('FPC_HAS_RESOURCES');
  1844. {$endif}
  1845. {$ifdef m68k}
  1846. def_system_macro('CPU68K');
  1847. def_system_macro('CPUM68K');
  1848. def_system_macro('CPU32');
  1849. def_system_macro('FPC_CURRENCY_IS_INT64');
  1850. def_system_macro('FPC_COMP_IS_INT64');
  1851. {$endif}
  1852. {$ifdef ALPHA}
  1853. def_system_macro('CPUALPHA');
  1854. def_system_macro('CPU64');
  1855. {$endif}
  1856. {$ifdef powerpc}
  1857. def_system_macro('CPUPOWERPC');
  1858. def_system_macro('CPUPOWERPC32');
  1859. def_system_macro('CPU32');
  1860. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1861. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1862. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1863. def_system_macro('FPC_CURRENCY_IS_INT64');
  1864. def_system_macro('FPC_COMP_IS_INT64');
  1865. {$endif}
  1866. {$ifdef POWERPC64}
  1867. def_system_macro('CPUPOWERPC');
  1868. def_system_macro('CPUPOWERPC64');
  1869. def_system_macro('CPU64');
  1870. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1871. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1872. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1873. def_system_macro('FPC_CURRENCY_IS_INT64');
  1874. def_system_macro('FPC_COMP_IS_INT64');
  1875. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1876. {$endif}
  1877. {$ifdef iA64}
  1878. def_system_macro('CPUIA64');
  1879. def_system_macro('CPU64');
  1880. {$endif}
  1881. {$ifdef x86_64}
  1882. def_system_macro('CPUX86_64');
  1883. def_system_macro('CPUAMD64');
  1884. def_system_macro('CPU64');
  1885. { not supported for now, afaik (FK)
  1886. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1887. { win64 doesn't support the legacy fpu }
  1888. if target_info.system<>system_x86_64_win64 then
  1889. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1890. else
  1891. begin
  1892. def_system_macro('FPC_CURRENCY_IS_INT64');
  1893. def_system_macro('FPC_COMP_IS_INT64');
  1894. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1895. end;
  1896. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1897. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1898. {$endif}
  1899. {$ifdef sparc}
  1900. def_system_macro('CPUSPARC');
  1901. def_system_macro('CPUSPARC32');
  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}
  1910. {$ifdef vis}
  1911. def_system_macro('CPUVIS');
  1912. def_system_macro('CPU32');
  1913. {$endif}
  1914. {$ifdef arm}
  1915. def_system_macro('CPUARM');
  1916. def_system_macro('FPUFPA');
  1917. def_system_macro('CPU32');
  1918. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1919. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1920. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1921. def_system_macro('FPC_CURRENCY_IS_INT64');
  1922. def_system_macro('FPC_COMP_IS_INT64');
  1923. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1924. {$endif arm}
  1925. if source_info.system<>target_info.system then
  1926. def_system_macro('FPC_CROSSCOMPILING');
  1927. if source_info.cpu<>target_info.cpu then
  1928. def_system_macro('FPC_CPUCROSSCOMPILING');
  1929. if tf_winlikewidestring in target_info.flags then
  1930. def_system_macro('FPC_WINLIKEWIDESTRING');
  1931. { read configuration file }
  1932. if (not disable_configfile) and
  1933. (ppccfg<>'') then
  1934. begin
  1935. read_configfile:=check_configfile(ppccfg,ppccfg);
  1936. { Maybe alternative configfile ? }
  1937. if (not read_configfile) and
  1938. (ppcaltcfg<>'') then
  1939. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1940. end
  1941. else
  1942. read_configfile := false;
  1943. { Read commandline and configfile }
  1944. param_file:='';
  1945. { read configfile }
  1946. if read_configfile then
  1947. option.interpret_file(ppccfg);
  1948. { read parameters again to override config file }
  1949. if cmd<>'' then
  1950. option.parsecmd(cmd)
  1951. else
  1952. begin
  1953. { Write help pages if no parameters are passed }
  1954. if (paramcount=0) then
  1955. Option.WriteHelpPages;
  1956. option.read_parameters;
  1957. { Write only quickinfo }
  1958. if option.quickinfo<>'' then
  1959. option.writequickinfo;
  1960. end;
  1961. { Stop if errors in options }
  1962. if ErrorCount>0 then
  1963. StopOptions(1);
  1964. { Write logo }
  1965. if option.ParaLogo then
  1966. option.writelogo;
  1967. { Non-core target defines }
  1968. Option.TargetDefines(true);
  1969. { endian define }
  1970. case target_info.endian of
  1971. endian_little :
  1972. begin
  1973. def_system_macro('ENDIAN_LITTLE');
  1974. def_system_macro('FPC_LITTLE_ENDIAN');
  1975. end;
  1976. endian_big :
  1977. begin
  1978. def_system_macro('ENDIAN_BIG');
  1979. def_system_macro('FPC_BIG_ENDIAN');
  1980. end;
  1981. end;
  1982. { abi define }
  1983. case target_info.abi of
  1984. abi_powerpc_sysv :
  1985. def_system_macro('FPC_ABI_SYSV');
  1986. abi_powerpc_aix :
  1987. def_system_macro('FPC_ABI_AIX');
  1988. end;
  1989. { CPU Define }
  1990. def_system_macro('CPU'+Cputypestr[initcputype]);
  1991. { Check file to compile }
  1992. if param_file='' then
  1993. begin
  1994. Message(option_no_source_found);
  1995. StopOptions(1);
  1996. end;
  1997. {$ifndef Unix}
  1998. param_file:=FixFileName(param_file);
  1999. {$endif}
  2000. {$IFDEF USE_SYSUTILS}
  2001. inputdir := SplitPath(param_file);
  2002. inputfile := SplitName(param_file);
  2003. inputextension := SplitExtension(param_file);
  2004. {$ELSE USE_SYSUTILS}
  2005. fsplit(param_file,inputdir,inputfile,inputextension);
  2006. {$ENDIF USE_SYSUTILS}
  2007. if inputextension='' then
  2008. begin
  2009. if FileExists(inputdir+inputfile+sourceext) then
  2010. inputextension:=sourceext
  2011. else if FileExists(inputdir+inputfile+pasext) then
  2012. inputextension:=pasext
  2013. else if ((m_mac in aktmodeswitches) or
  2014. (tf_p_ext_support in target_info.flags))
  2015. and FileExists(inputdir+inputfile+pext) then
  2016. inputextension:=pext;
  2017. end;
  2018. { Check output dir }
  2019. if (OutputExeDir<>'') and
  2020. not PathExists(OutputExeDir) then
  2021. begin
  2022. Message1(general_e_path_does_not_exist,OutputExeDir);
  2023. StopOptions(1);
  2024. end;
  2025. { Add paths specified with parameters to the searchpaths }
  2026. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2027. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2028. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2029. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2030. { add unit environment and exepath to the unit search path }
  2031. if inputdir<>'' then
  2032. Unitsearchpath.AddPath(inputdir,true);
  2033. if not disable_configfile then
  2034. begin
  2035. {$IFDEF USE_SYSUTILS}
  2036. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2037. {$ELSE USE_SYSUTILS}
  2038. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  2039. {$ENDIF USE_SYSUTILS}
  2040. end;
  2041. {$ifdef Unix}
  2042. {$IFDEF USE_SYSUTILS}
  2043. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2044. {$ELSE USE_SYSUTILS}
  2045. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2046. {$ENDIF USE_SYSUTILS}
  2047. if fpcdir='' then
  2048. begin
  2049. if PathExists('/usr/local/lib/fpc/'+version_string) then
  2050. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2051. else
  2052. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2053. end;
  2054. {$else}
  2055. {$IFDEF USE_SYSUTILS}
  2056. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2057. {$ELSE USE_SYSUTILS}
  2058. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2059. {$ENDIF USE_SYSUTILS}
  2060. if fpcdir='' then
  2061. begin
  2062. fpcdir:=ExePath+'../';
  2063. if not(PathExists(fpcdir+'/units')) and
  2064. not(PathExists(fpcdir+'/rtl')) then
  2065. fpcdir:=fpcdir+'../';
  2066. end;
  2067. {$endif}
  2068. { first try development RTL, else use the default installation path }
  2069. if not disable_configfile then
  2070. begin
  2071. if PathExists(FpcDir+'rtl') then
  2072. if tf_use_8_3 in Source_Info.Flags then
  2073. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2074. else
  2075. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2076. else
  2077. if tf_use_8_3 in Source_Info.Flags then
  2078. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2079. else
  2080. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2081. end;
  2082. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2083. Do not add it when linking on the target because then we can maybe already find
  2084. .o files that are not for the target }
  2085. if (ExePath<>GetCurrentDir) and
  2086. not(cs_link_on_target in initglobalswitches) then
  2087. UnitSearchPath.AddPath(ExePath,false);
  2088. { Add unit dir to the object and library path }
  2089. objectsearchpath.AddList(unitsearchpath,false);
  2090. librarysearchpath.AddList(unitsearchpath,false);
  2091. { maybe override debug info format }
  2092. if (paratargetdbg<>dbg_none) then
  2093. set_target_dbg(paratargetdbg);
  2094. { maybe override assembler }
  2095. if (paratargetasm<>as_none) then
  2096. begin
  2097. if not set_target_asm(paratargetasm) then
  2098. begin
  2099. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2100. set_target_asm(target_info.assemextern);
  2101. Message1(option_asm_forced,target_asm.idtxt);
  2102. end;
  2103. end;
  2104. { switch assembler if it's binary and we got -a on the cmdline }
  2105. if (cs_asm_leave in initglobalswitches) and
  2106. (af_outputbinary in target_asm.flags) then
  2107. begin
  2108. Message(option_switch_bin_to_src_assembler);
  2109. set_target_asm(target_info.assemextern);
  2110. end;
  2111. { Force use of external linker if there is no
  2112. internal linker or the linking is skipped }
  2113. if not(cs_link_extern in initglobalswitches) and
  2114. (not assigned(target_info.link) or
  2115. (cs_link_nolink in initglobalswitches)) then
  2116. include(initglobalswitches,cs_link_extern);
  2117. { turn off stripping if compiling with debuginfo or profile }
  2118. if (cs_debuginfo in initmoduleswitches) or
  2119. (cs_profile in initmoduleswitches) then
  2120. exclude(initglobalswitches,cs_link_strip);
  2121. { force fpu emulation on arm/wince and arm/gba }
  2122. if target_info.system in [system_arm_wince,system_arm_gba] then
  2123. include(initmoduleswitches,cs_fp_emulation);
  2124. { Section smartlinking conflicts with import sections on Windows }
  2125. if GenerateImportSection and
  2126. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2127. exclude(target_info.flags,tf_smartlink_sections);
  2128. {$ifdef x86_64}
  2129. {$warning HACK: turn off smartlinking}
  2130. exclude(initmoduleswitches,cs_create_smart);
  2131. {$endif}
  2132. if not LinkTypeSetExplicitly then
  2133. set_default_link_type;
  2134. { Default alignment settings,
  2135. 1. load the defaults for the target
  2136. 2. override with generic optimizer setting (little size)
  2137. 3. override with the user specified -Oa }
  2138. UpdateAlignment(initalignment,target_info.alignment);
  2139. if (cs_opt_size in aktoptimizerswitches) then
  2140. begin
  2141. initalignment.procalign:=1;
  2142. initalignment.jumpalign:=1;
  2143. initalignment.loopalign:=1;
  2144. end;
  2145. UpdateAlignment(initalignment,option.paraalignment);
  2146. set_system_macro('FPC_VERSION',version_nr);
  2147. set_system_macro('FPC_RELEASE',release_nr);
  2148. set_system_macro('FPC_PATCH',patch_nr);
  2149. option.free;
  2150. Option:=nil;
  2151. end;
  2152. initialization
  2153. coption:=toption;
  2154. finalization
  2155. if assigned(option) then
  2156. option.free;
  2157. end.