options.pas 77 KB

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