options.pas 85 KB

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