options.pas 70 KB

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