options.pas 72 KB

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