options.pas 96 KB

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