options.pas 96 KB

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