options.pas 71 KB

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