options.pas 96 KB

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