options.pas 82 KB

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