options.pas 97 KB

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