options.pas 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937
  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. {$ifdef jvm}
  1197. UnsupportedPara('-SI');
  1198. {$endif}
  1199. if upper(more)='ICOM' then
  1200. init_settings.interfacetype:=it_interfacecom
  1201. else if upper(more)='ICORBA' then
  1202. init_settings.interfacetype:=it_interfacecorba
  1203. else
  1204. IllegalPara(opt);
  1205. end
  1206. else
  1207. begin
  1208. j:=1;
  1209. while j<=length(more) do
  1210. begin
  1211. case more[j] of
  1212. '2' : //an alternative to -Mobjfpc
  1213. SetCompileMode('OBJFPC',true);
  1214. 'a' :
  1215. If UnsetBool(More, j) then
  1216. exclude(init_settings.localswitches,cs_do_assertion)
  1217. else
  1218. include(init_settings.localswitches,cs_do_assertion);
  1219. 'c' :
  1220. If UnsetBool(More, j) then
  1221. include(init_settings.moduleswitches,cs_support_c_operators)
  1222. else
  1223. include(init_settings.moduleswitches,cs_support_c_operators);
  1224. 'd' : //an alternative to -Mdelphi
  1225. SetCompileMode('DELPHI',true);
  1226. 'e' :
  1227. begin
  1228. SetErrorFlags(copy(more,j+1,length(more)));
  1229. break;
  1230. end;
  1231. 'f' :
  1232. begin
  1233. inc(j);
  1234. if more[j]='-' then
  1235. begin
  1236. features:=[];
  1237. if length(more)>j then
  1238. IllegalPara(opt);
  1239. end
  1240. else
  1241. begin
  1242. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1243. j:=length(more)
  1244. else
  1245. IllegalPara(opt);
  1246. end;
  1247. end;
  1248. 'g' :
  1249. If UnsetBool(More, j) then
  1250. exclude(init_settings.moduleswitches,cs_support_goto)
  1251. else
  1252. include(init_settings.moduleswitches,cs_support_goto);
  1253. 'h' :
  1254. If UnsetBool(More, j) then
  1255. exclude(init_settings.localswitches,cs_refcountedstrings)
  1256. else
  1257. include(init_settings.localswitches,cs_refcountedstrings);
  1258. 'i' :
  1259. If UnsetBool(More, j) then
  1260. exclude(init_settings.localswitches,cs_do_inline)
  1261. else
  1262. include(init_settings.localswitches,cs_do_inline);
  1263. 'k' :
  1264. If UnsetBool(More, j) then
  1265. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1266. else
  1267. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1268. 'm' :
  1269. If UnsetBool(More, j) then
  1270. exclude(init_settings.moduleswitches,cs_support_macro)
  1271. else
  1272. include(init_settings.moduleswitches,cs_support_macro);
  1273. 'o' : //an alternative to -Mtp
  1274. SetCompileMode('TP',true);
  1275. {$ifdef gpc_mode}
  1276. 'p' : //an alternative to -Mgpc
  1277. SetCompileMode('GPC',true);
  1278. {$endif}
  1279. 's' :
  1280. If UnsetBool(More, j) then
  1281. exclude(init_settings.globalswitches,cs_constructor_name)
  1282. else
  1283. include(init_settings.globalswitches,cs_constructor_name);
  1284. 't' :
  1285. Message1(option_obsolete_switch,'-St');
  1286. 'v' :
  1287. If UnsetBool(More, j) then
  1288. exclude(init_settings.globalswitches,cs_support_vectors)
  1289. else
  1290. include(init_settings.globalswitches,cs_support_vectors);
  1291. 'x' :
  1292. If UnsetBool(More, j) then
  1293. exclude(init_settings.globalswitches,cs_support_exceptions)
  1294. else
  1295. include(init_settings.globalswitches,cs_support_exceptions);
  1296. 'y' :
  1297. If UnsetBool(More, j) then
  1298. exclude(init_settings.localswitches,cs_typed_addresses)
  1299. else
  1300. include(init_settings.localswitches,cs_typed_addresses);
  1301. '-' :
  1302. begin
  1303. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1304. cs_support_vectors,cs_load_fpcylix_unit];
  1305. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  1306. cs_typed_addresses];
  1307. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1308. cs_support_macro];
  1309. end;
  1310. else
  1311. IllegalPara(opt);
  1312. end;
  1313. inc(j);
  1314. end;
  1315. end;
  1316. end;
  1317. 'T' :
  1318. begin
  1319. more:=Upper(More);
  1320. if paratarget=system_none then
  1321. begin
  1322. { remove old target define }
  1323. TargetOptions(false);
  1324. { load new target }
  1325. paratarget:=find_system_by_string(More);
  1326. if paratarget<>system_none then
  1327. set_target(paratarget)
  1328. else
  1329. IllegalPara(opt);
  1330. { set new define }
  1331. TargetOptions(true);
  1332. end
  1333. else
  1334. if More<>upper(target_info.shortname) then
  1335. Message1(option_target_is_already_set,target_info.shortname);
  1336. end;
  1337. 'u' :
  1338. if more <> '' then
  1339. undef_system_macro(more);
  1340. 'U' :
  1341. begin
  1342. j:=1;
  1343. while j<=length(more) do
  1344. begin
  1345. case more[j] of
  1346. {$ifdef UNITALIASES}
  1347. 'a' :
  1348. begin
  1349. AddUnitAlias(Copy(More,j+1,255));
  1350. break;
  1351. end;
  1352. {$endif UNITALIASES}
  1353. 'n' :
  1354. exclude(init_settings.globalswitches,cs_check_unit_name);
  1355. 'p' :
  1356. begin
  1357. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1358. break;
  1359. end;
  1360. 'r' :
  1361. do_release:=true;
  1362. 's' :
  1363. include(init_settings.moduleswitches,cs_compilesystem);
  1364. '-' :
  1365. begin
  1366. exclude(init_settings.moduleswitches,cs_compilesystem);
  1367. exclude(init_settings.globalswitches,cs_check_unit_name);
  1368. end;
  1369. else
  1370. IllegalPara(opt);
  1371. end;
  1372. inc(j);
  1373. end;
  1374. end;
  1375. 'v' :
  1376. begin
  1377. if not setverbosity(More) then
  1378. IllegalPara(opt);
  1379. end;
  1380. 'V' : ; { Ignore used by fpc }
  1381. 'W' :
  1382. begin
  1383. j:=1;
  1384. while j<=length(More) do
  1385. begin
  1386. case More[j] of
  1387. 'A':
  1388. begin
  1389. if target_info.system in systems_all_windows then
  1390. begin
  1391. if UnsetBool(More, j) then
  1392. apptype:=app_cui
  1393. else
  1394. apptype:=app_native;
  1395. end
  1396. else
  1397. IllegalPara(opt);
  1398. end;
  1399. 'b':
  1400. begin
  1401. if target_info.system in systems_darwin then
  1402. begin
  1403. if UnsetBool(More, j) then
  1404. apptype:=app_cui
  1405. else
  1406. apptype:=app_bundle
  1407. end
  1408. else
  1409. IllegalPara(opt);
  1410. end;
  1411. 'B':
  1412. begin
  1413. if target_info.system in systems_all_windows+systems_symbian then
  1414. begin
  1415. { -WB200000 means set trefered base address
  1416. to $200000, but does not change relocsection boolean
  1417. this way we can create both relocatble and
  1418. non relocatable DLL at a specific base address PM }
  1419. if (length(More)>j) then
  1420. begin
  1421. val('$'+Copy(More,j+1,255),imagebase,code);
  1422. if code<>0 then
  1423. IllegalPara(opt);
  1424. ImageBaseSetExplicity:=true;
  1425. end
  1426. else
  1427. begin
  1428. RelocSection:=true;
  1429. RelocSectionSetExplicitly:=true;
  1430. end;
  1431. break;
  1432. end
  1433. else
  1434. IllegalPara(opt);
  1435. end;
  1436. 'C':
  1437. begin
  1438. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1439. begin
  1440. if UnsetBool(More, j) then
  1441. apptype:=app_gui
  1442. else
  1443. apptype:=app_cui;
  1444. end
  1445. else
  1446. IllegalPara(opt);
  1447. end;
  1448. 'D':
  1449. begin
  1450. if target_info.system in systems_all_windows then
  1451. begin
  1452. UseDeffileForExports:=not UnsetBool(More, j);
  1453. UseDeffileForExportsSetExplicitly:=true;
  1454. end
  1455. else
  1456. IllegalPara(opt);
  1457. end;
  1458. 'e':
  1459. begin
  1460. if (target_info.system in systems_darwin) then
  1461. begin
  1462. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1463. set_target_res(res_ext);
  1464. target_info.resobjext:='.fpcres';
  1465. end
  1466. else
  1467. IllegalPara(opt);
  1468. end;
  1469. 'F':
  1470. begin
  1471. if target_info.system in systems_os2 then
  1472. begin
  1473. if UnsetBool(More, j) then
  1474. apptype:=app_cui
  1475. else
  1476. apptype:=app_fs;
  1477. end
  1478. else
  1479. IllegalPara(opt);
  1480. end;
  1481. 'G':
  1482. begin
  1483. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1484. begin
  1485. if UnsetBool(More, j) then
  1486. apptype:=app_cui
  1487. else
  1488. apptype:=app_gui;
  1489. end
  1490. else
  1491. IllegalPara(opt);
  1492. end;
  1493. 'I':
  1494. begin
  1495. if target_info.system in systems_all_windows then
  1496. begin
  1497. GenerateImportSection:=not UnsetBool(More,j);
  1498. GenerateImportSectionSetExplicitly:=true;
  1499. end
  1500. else
  1501. IllegalPara(opt);
  1502. end;
  1503. 'i':
  1504. begin
  1505. if (target_info.system in systems_darwin) then
  1506. begin
  1507. set_target_res(res_macho);
  1508. target_info.resobjext:=
  1509. targetinfos[target_info.system]^.resobjext;
  1510. end
  1511. else
  1512. IllegalPara(opt);
  1513. end;
  1514. 'N':
  1515. begin
  1516. if target_info.system in systems_all_windows then
  1517. begin
  1518. RelocSection:=UnsetBool(More,j);
  1519. RelocSectionSetExplicitly:=true;
  1520. end
  1521. else
  1522. IllegalPara(opt);
  1523. end;
  1524. 'p':
  1525. begin
  1526. {$if defined(arm) or defined(avr)}
  1527. if (target_info.system in systems_embedded) then
  1528. begin
  1529. s:=upper(copy(more,j+1,length(more)-j));
  1530. if not(SetControllerType(s,init_settings.controllertype)) then
  1531. IllegalPara(opt);
  1532. break;
  1533. end
  1534. else
  1535. {$endif defined(arm) or defined(avr)}
  1536. IllegalPara(opt);
  1537. end;
  1538. 'R':
  1539. begin
  1540. if target_info.system in systems_all_windows then
  1541. begin
  1542. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1543. RelocSection:=not UnsetBool(More,j);
  1544. RelocSectionSetExplicitly:=true;
  1545. end
  1546. else
  1547. IllegalPara(opt);
  1548. end;
  1549. 'T':
  1550. begin
  1551. if target_info.system in systems_macos then
  1552. begin
  1553. if UnsetBool(More, j) then
  1554. apptype:=app_cui
  1555. else
  1556. apptype:=app_tool;
  1557. end
  1558. else
  1559. IllegalPara(opt);
  1560. end;
  1561. 'X':
  1562. begin
  1563. if (target_info.system in systems_linux) then
  1564. begin
  1565. if UnsetBool(More, j) then
  1566. exclude(init_settings.moduleswitches,cs_executable_stack)
  1567. else
  1568. include(init_settings.moduleswitches,cs_executable_stack)
  1569. end
  1570. else
  1571. IllegalPara(opt);
  1572. end
  1573. else
  1574. IllegalPara(opt);
  1575. end;
  1576. inc(j);
  1577. end;
  1578. end;
  1579. 'X' :
  1580. begin
  1581. j:=1;
  1582. while j<=length(more) do
  1583. begin
  1584. case More[j] of
  1585. 'c' : Cshared:=TRUE;
  1586. 'd' : Dontlinkstdlibpath:=TRUE;
  1587. 'e' :
  1588. begin
  1589. If UnsetBool(More, j) then
  1590. exclude(init_settings.globalswitches,cs_link_extern)
  1591. else
  1592. include(init_settings.globalswitches,cs_link_extern);
  1593. end;
  1594. 'f' :
  1595. include(init_settings.globalswitches,cs_link_pthread);
  1596. 'g' :
  1597. begin
  1598. If UnsetBool(More, j) then
  1599. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1600. else
  1601. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1602. end;
  1603. 'i' :
  1604. begin
  1605. If UnsetBool(More, j) then
  1606. include(init_settings.globalswitches,cs_link_extern)
  1607. else
  1608. exclude(init_settings.globalswitches,cs_link_extern);
  1609. end;
  1610. 'n' :
  1611. begin
  1612. If UnsetBool(More, j) then
  1613. exclude(init_settings.globalswitches,cs_link_native)
  1614. else
  1615. include(init_settings.globalswitches,cs_link_native);
  1616. end;
  1617. 'm' :
  1618. begin
  1619. If UnsetBool(More, j) then
  1620. exclude(init_settings.globalswitches,cs_link_map)
  1621. else
  1622. include(init_settings.globalswitches,cs_link_map);
  1623. end;
  1624. 'p' : ; { Ignore used by fpc.pp }
  1625. 'r' :
  1626. begin
  1627. if (target_info.system in suppported_targets_x_smallr) then
  1628. begin
  1629. rlinkpath:=Copy(more,2,length(More)-1);
  1630. DefaultReplacements(rlinkpath);
  1631. end
  1632. else
  1633. IgnoredPara('-Xr');
  1634. more:='';
  1635. end;
  1636. 'R' :
  1637. begin
  1638. sysrootpath:=copy(more,2,length(more)-1);
  1639. defaultreplacements(sysrootpath);
  1640. more:='';
  1641. end;
  1642. 's' :
  1643. begin
  1644. If UnsetBool(More, j) then
  1645. exclude(init_settings.globalswitches,cs_link_strip)
  1646. else
  1647. include(init_settings.globalswitches,cs_link_strip);
  1648. end;
  1649. 't' :
  1650. include(init_settings.globalswitches,cs_link_staticflag);
  1651. 'v' :
  1652. begin
  1653. If UnsetBool(More, j) then
  1654. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1655. else
  1656. include(init_settings.globalswitches,cs_link_opt_vtable);
  1657. end;
  1658. 'D' :
  1659. begin
  1660. def_system_macro('FPC_LINK_DYNAMIC');
  1661. undef_system_macro('FPC_LINK_SMART');
  1662. undef_system_macro('FPC_LINK_STATIC');
  1663. exclude(init_settings.globalswitches,cs_link_static);
  1664. exclude(init_settings.globalswitches,cs_link_smart);
  1665. include(init_settings.globalswitches,cs_link_shared);
  1666. LinkTypeSetExplicitly:=true;
  1667. end;
  1668. 'M' :
  1669. begin
  1670. mainaliasname:=Copy(more,2,length(More)-1);
  1671. More:='';
  1672. end;
  1673. 'P' :
  1674. begin
  1675. utilsprefix:=Copy(more,2,length(More)-1);
  1676. DefaultReplacements(utilsprefix);
  1677. More:='';
  1678. end;
  1679. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1680. // these are not aggregable.
  1681. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1682. IllegalPara(opt)
  1683. else
  1684. begin
  1685. case more[j+1] of
  1686. 'A' : begin
  1687. s:=Copy(more,3,length(More)-2);
  1688. if not LinkLibraryAliases.AddDep(s) Then
  1689. IllegalPara(opt);
  1690. end;
  1691. 'O' : begin
  1692. s:=Copy(more,3,length(More)-2);
  1693. if not LinkLibraryOrder.AddWeight(s) Then
  1694. IllegalPara(opt);
  1695. end;
  1696. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1697. else
  1698. IllegalPara(opt);
  1699. end; {case}
  1700. j:=length(more);
  1701. end; {else begin}
  1702. end;
  1703. 'S' :
  1704. begin
  1705. ForceStaticLinking;
  1706. end;
  1707. 'X' :
  1708. begin
  1709. def_system_macro('FPC_LINK_SMART');
  1710. undef_system_macro('FPC_LINK_STATIC');
  1711. undef_system_macro('FPC_LINK_DYNAMIC');
  1712. exclude(init_settings.globalswitches,cs_link_static);
  1713. include(init_settings.globalswitches,cs_link_smart);
  1714. exclude(init_settings.globalswitches,cs_link_shared);
  1715. LinkTypeSetExplicitly:=true;
  1716. end;
  1717. '-' :
  1718. begin
  1719. exclude(init_settings.globalswitches,cs_link_staticflag);
  1720. exclude(init_settings.globalswitches,cs_link_strip);
  1721. exclude(init_settings.globalswitches,cs_link_map);
  1722. set_default_link_type;
  1723. end;
  1724. else
  1725. IllegalPara(opt);
  1726. end;
  1727. inc(j);
  1728. end;
  1729. end;
  1730. else
  1731. IllegalPara(opt);
  1732. end;
  1733. end;
  1734. '@' :
  1735. begin
  1736. Message(option_no_nested_response_file);
  1737. StopOptions(1);
  1738. end;
  1739. else
  1740. begin
  1741. if (length(param_file)<>0) then
  1742. Message2(option_only_one_source_support,param_file,opt);
  1743. param_file:=opt;
  1744. Message1(option_found_file,opt);
  1745. end;
  1746. end;
  1747. end;
  1748. procedure Toption.Interpret_file(const filename : TPathStr);
  1749. procedure RemoveSep(var fn:TPathStr);
  1750. var
  1751. i : longint;
  1752. begin
  1753. i:=0;
  1754. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1755. inc(i);
  1756. Delete(fn,1,i);
  1757. i:=length(fn);
  1758. while (i>0) and (fn[i] in [',',' ',#9]) do
  1759. dec(i);
  1760. fn:=copy(fn,1,i);
  1761. end;
  1762. function GetName(var fn:TPathStr):TPathStr;
  1763. var
  1764. i : longint;
  1765. begin
  1766. i:=0;
  1767. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1768. inc(i);
  1769. GetName:=Copy(fn,1,i);
  1770. Delete(fn,1,i);
  1771. end;
  1772. const
  1773. maxlevel = 15;
  1774. var
  1775. f : text;
  1776. s, tmp,
  1777. opts : TCmdStr;
  1778. skip : array[0..maxlevel] of boolean;
  1779. line,
  1780. level : longint;
  1781. option_read : boolean;
  1782. begin
  1783. { avoid infinite loop }
  1784. Inc(FileLevel);
  1785. Option_read:=false;
  1786. If FileLevel>MaxLevel then
  1787. Message(option_too_many_cfg_files);
  1788. { Maybe It's Directory ?} //Jaro Change:
  1789. if PathExists(filename,false) then
  1790. begin
  1791. Message1(option_config_is_dir,filename);
  1792. exit;
  1793. end;
  1794. { open file }
  1795. Message1(option_using_file,filename);
  1796. assign(f,ExpandFileName(filename));
  1797. {$I-}
  1798. reset(f);
  1799. {$I+}
  1800. if ioresult<>0 then
  1801. begin
  1802. Message1(option_unable_open_file,filename);
  1803. exit;
  1804. end;
  1805. Message1(option_start_reading_configfile,filename);
  1806. fillchar(skip,sizeof(skip),0);
  1807. level:=0;
  1808. line:=0;
  1809. while not eof(f) do
  1810. begin
  1811. readln(f,opts);
  1812. inc(line);
  1813. RemoveSep(opts);
  1814. if (opts<>'') and (opts[1]<>';') then
  1815. begin
  1816. if opts[1]='#' then
  1817. begin
  1818. Message1(option_interpreting_file_option,opts);
  1819. Delete(opts,1,1);
  1820. s:=upper(GetName(opts));
  1821. if (s='SECTION') then
  1822. begin
  1823. RemoveSep(opts);
  1824. s:=upper(GetName(opts));
  1825. if level=0 then
  1826. skip[level]:=not defined_macro(s) or (s='COMMON');
  1827. end
  1828. else
  1829. if (s='IFDEF') then
  1830. begin
  1831. RemoveSep(opts);
  1832. if Level>=maxlevel then
  1833. begin
  1834. Message2(option_too_many_ifdef,filename,tostr(line));
  1835. stopOptions(1);
  1836. end;
  1837. inc(Level);
  1838. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1839. end
  1840. else
  1841. if (s='IFNDEF') then
  1842. begin
  1843. RemoveSep(opts);
  1844. if Level>=maxlevel then
  1845. begin
  1846. Message2(option_too_many_ifdef,filename,tostr(line));
  1847. stopOptions(1);
  1848. end;
  1849. inc(Level);
  1850. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1851. end
  1852. else
  1853. if (s='ELSE') then
  1854. begin
  1855. if Level=0 then
  1856. begin
  1857. Message2(option_else_without_if,filename,tostr(line));
  1858. stopOptions(1);
  1859. end
  1860. else
  1861. skip[level]:=skip[level-1] or (not skip[level])
  1862. end
  1863. else
  1864. if (s='ENDIF') then
  1865. begin
  1866. skip[level]:=false;
  1867. if Level=0 then
  1868. begin
  1869. Message2(option_too_many_endif,filename,tostr(line));
  1870. stopOptions(1);
  1871. end;
  1872. dec(level);
  1873. end
  1874. else
  1875. if (not skip[level]) then
  1876. begin
  1877. if (s='DEFINE') then
  1878. begin
  1879. RemoveSep(opts);
  1880. tmp:= GetName(opts);
  1881. if tmp <> '' then
  1882. def_system_macro(tmp);
  1883. end
  1884. else
  1885. if (s='UNDEF') then
  1886. begin
  1887. RemoveSep(opts);
  1888. tmp:= GetName(opts);
  1889. if tmp <> '' then
  1890. undef_system_macro(tmp);
  1891. end
  1892. else
  1893. if (s='WRITE') then
  1894. begin
  1895. Delete(opts,1,1);
  1896. WriteLn(opts);
  1897. end
  1898. else
  1899. if (s='INCLUDE') then
  1900. begin
  1901. Delete(opts,1,1);
  1902. Interpret_file(opts);
  1903. end;
  1904. end;
  1905. end
  1906. else
  1907. begin
  1908. if (opts[1]='-') or (opts[1]='@') then
  1909. begin
  1910. if (not skip[level]) then
  1911. interpret_option(opts,false);
  1912. Option_read:=true;
  1913. end
  1914. else
  1915. Message1(option_illegal_para,opts);
  1916. end;
  1917. end;
  1918. end;
  1919. if Level>0 then
  1920. Message(option_too_less_endif);
  1921. if Not Option_read then
  1922. Message1(option_no_option_found,filename)
  1923. else
  1924. Message1(option_end_reading_configfile,filename);
  1925. Close(f);
  1926. Dec(FileLevel);
  1927. end;
  1928. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  1929. var
  1930. argstart,
  1931. env,
  1932. pc : pchar;
  1933. arglen : longint;
  1934. quote : set of char;
  1935. hs : TCmdStr;
  1936. begin
  1937. Message1(option_using_env,envname);
  1938. env:=GetEnvPChar(envname);
  1939. pc:=env;
  1940. if assigned(pc) then
  1941. begin
  1942. repeat
  1943. { skip leading spaces }
  1944. while pc^ in [' ',#9,#13] do
  1945. inc(pc);
  1946. case pc^ of
  1947. #0 :
  1948. break;
  1949. '"' :
  1950. begin
  1951. quote:=['"'];
  1952. inc(pc);
  1953. end;
  1954. '''' :
  1955. begin
  1956. quote:=[''''];
  1957. inc(pc);
  1958. end;
  1959. else
  1960. quote:=[' ',#9,#13];
  1961. end;
  1962. { scan until the end of the argument }
  1963. argstart:=pc;
  1964. while (pc^<>#0) and not(pc^ in quote) do
  1965. inc(pc);
  1966. { create argument }
  1967. arglen:=pc-argstart;
  1968. { TODO: FIXME: silent truncation of environment parameters }
  1969. if (arglen > 255) then
  1970. arglen := 255;
  1971. setlength(hs,arglen);
  1972. move(argstart^,hs[1],arglen);
  1973. interpret_option(hs,true);
  1974. { skip quote }
  1975. if pc^ in quote then
  1976. inc(pc);
  1977. until false;
  1978. end
  1979. else
  1980. Message1(option_no_option_found,'(env) '+envname);
  1981. FreeEnvPChar(env);
  1982. end;
  1983. procedure toption.read_parameters;
  1984. var
  1985. opts : TCmdStr;
  1986. paramindex : longint;
  1987. begin
  1988. paramindex:=0;
  1989. while paramindex<paramcount do
  1990. begin
  1991. inc(paramindex);
  1992. opts:=objpas.paramstr(paramindex);
  1993. case opts[1] of
  1994. '@' :
  1995. if not firstpass then
  1996. begin
  1997. Delete(opts,1,1);
  1998. Message1(option_reading_further_from,opts);
  1999. interpret_file(opts);
  2000. end;
  2001. '!' :
  2002. if not firstpass then
  2003. begin
  2004. Delete(opts,1,1);
  2005. Message1(option_reading_further_from,'(env) '+opts);
  2006. interpret_envvar(opts);
  2007. end;
  2008. else
  2009. interpret_option(opts,true);
  2010. end;
  2011. end;
  2012. end;
  2013. procedure toption.parsecmd(cmd:TCmdStr);
  2014. var
  2015. i,ps : longint;
  2016. opts : TCmdStr;
  2017. begin
  2018. while (cmd<>'') do
  2019. begin
  2020. while cmd[1]=' ' do
  2021. delete(cmd,1,1);
  2022. i:=pos(' ',cmd);
  2023. if i=0 then
  2024. i:=2147483647;
  2025. opts:=Copy(cmd,1,i-1);
  2026. Delete(cmd,1,i);
  2027. case opts[1] of
  2028. '@' :
  2029. if not firstpass then
  2030. begin
  2031. Delete(opts,1,1);
  2032. Message1(option_reading_further_from,opts);
  2033. interpret_file(opts);
  2034. end;
  2035. '!' :
  2036. if not firstpass then
  2037. begin
  2038. Delete(opts,1,1);
  2039. Message1(option_reading_further_from,'(env) '+opts);
  2040. interpret_envvar(opts);
  2041. end;
  2042. '"' :
  2043. begin
  2044. Delete(opts,1,1);
  2045. ps:=pos('"',cmd);
  2046. if (i<>256) and (ps>0) then
  2047. begin
  2048. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2049. cmd:=copy(cmd,ps+1,255);
  2050. end;
  2051. interpret_option(opts,true);
  2052. end;
  2053. else
  2054. interpret_option(opts,true);
  2055. end;
  2056. end;
  2057. end;
  2058. procedure toption.writequickinfo;
  2059. var
  2060. s : string;
  2061. i : longint;
  2062. procedure addinfo(const hs:string);
  2063. begin
  2064. if s<>'' then
  2065. s:=s+' '+hs
  2066. else
  2067. s:=hs;
  2068. end;
  2069. begin
  2070. s:='';
  2071. i:=0;
  2072. while (i<length(quickinfo)) do
  2073. begin
  2074. inc(i);
  2075. case quickinfo[i] of
  2076. 'S' :
  2077. begin
  2078. inc(i);
  2079. case quickinfo[i] of
  2080. 'O' :
  2081. addinfo(lower(source_info.shortname));
  2082. 'P' :
  2083. addinfo(source_cpu_string);
  2084. else
  2085. IllegalPara('-i'+QuickInfo);
  2086. end;
  2087. end;
  2088. 'T' :
  2089. begin
  2090. inc(i);
  2091. case quickinfo[i] of
  2092. 'O' :
  2093. addinfo(lower(target_info.shortname));
  2094. 'P' :
  2095. AddInfo(target_cpu_string);
  2096. else
  2097. IllegalPara('-i'+QuickInfo);
  2098. end;
  2099. end;
  2100. 'V' :
  2101. AddInfo(version_string);
  2102. 'W' :
  2103. AddInfo(full_version_string);
  2104. 'D' :
  2105. AddInfo(date_string);
  2106. '_' :
  2107. ;
  2108. else
  2109. IllegalPara('-i'+QuickInfo);
  2110. end;
  2111. end;
  2112. if s<>'' then
  2113. begin
  2114. writeln(s);
  2115. stopoptions(0);
  2116. end;
  2117. end;
  2118. procedure TOption.TargetOptions(def:boolean);
  2119. var
  2120. s : string;
  2121. i : integer;
  2122. target_unsup_features : tfeatures;
  2123. begin
  2124. if def then
  2125. def_system_macro(target_info.shortname)
  2126. else
  2127. undef_system_macro(target_info.shortname);
  2128. s:=target_info.extradefines;
  2129. while (s<>'') do
  2130. begin
  2131. i:=pos(';',s);
  2132. if i=0 then
  2133. i:=length(s)+1;
  2134. if def then
  2135. def_system_macro(Copy(s,1,i-1))
  2136. else
  2137. undef_system_macro(Copy(s,1,i-1));
  2138. delete(s,1,i);
  2139. end;
  2140. if (tf_winlikewidestring in target_info.flags) then
  2141. if def then
  2142. def_system_macro('FPC_WINLIKEWIDESTRING')
  2143. else
  2144. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2145. if (tf_requires_proper_alignment in target_info.flags) then
  2146. if def then
  2147. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2148. else
  2149. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2150. if source_info.system<>target_info.system then
  2151. if def then
  2152. def_system_macro('FPC_CROSSCOMPILING')
  2153. else
  2154. undef_system_macro('FPC_CROSSCOMPILING');
  2155. if source_info.cpu<>target_info.cpu then
  2156. if def then
  2157. def_system_macro('FPC_CPUCROSSCOMPILING')
  2158. else
  2159. def_system_macro('FPC_CPUCROSSCOMPILING');
  2160. if (tf_no_generic_stackcheck in target_info.flags) then
  2161. if def then
  2162. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2163. else
  2164. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2165. { Code generation flags }
  2166. if def and
  2167. (tf_pic_default in target_info.flags) then
  2168. include(init_settings.moduleswitches,cs_create_pic)
  2169. else
  2170. exclude(init_settings.moduleswitches,cs_create_pic);
  2171. { Resources support }
  2172. if (tf_has_winlike_resources in target_info.flags) then
  2173. if def then
  2174. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2175. else
  2176. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2177. { Features }
  2178. case target_info.system of
  2179. system_arm_gba:
  2180. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2181. system_arm_nds:
  2182. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2183. system_i386_nativent:
  2184. // until these features are implemented, they are disabled in the compiler
  2185. target_unsup_features:=[f_stackcheck];
  2186. system_jvm_java32:
  2187. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2188. f_variants,f_objects,f_threading,f_commandargs,
  2189. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2190. else
  2191. target_unsup_features:=[];
  2192. end;
  2193. if def then
  2194. features:=features-target_unsup_features
  2195. else
  2196. features:=features+target_unsup_features;
  2197. end;
  2198. procedure TOption.checkoptionscompatibility;
  2199. begin
  2200. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2201. not(target_info.system in systems_darwin) then
  2202. begin
  2203. { smart linking does not yet work with DWARF debug info on most targets }
  2204. if (cs_link_smart in init_settings.globalswitches) then
  2205. begin
  2206. Message(option_dwarf_smart_linking);
  2207. ForceStaticLinking;
  2208. end;
  2209. end;
  2210. { external debug info is only supported for DWARF on darwin }
  2211. if (target_info.system in systems_darwin) and
  2212. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2213. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2214. begin
  2215. Message(option_debug_external_unsupported);
  2216. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2217. end;
  2218. end;
  2219. constructor TOption.create;
  2220. begin
  2221. LogoWritten:=false;
  2222. NoPressEnter:=false;
  2223. FirstPass:=false;
  2224. FPUSetExplicitly:=false;
  2225. CPUSetExplicitly:=false;
  2226. OptCPUSetExplicitly:=false;
  2227. FileLevel:=0;
  2228. Quickinfo:='';
  2229. ParaIncludePath:=TSearchPathList.Create;
  2230. ParaObjectPath:=TSearchPathList.Create;
  2231. ParaUnitPath:=TSearchPathList.Create;
  2232. ParaLibraryPath:=TSearchPathList.Create;
  2233. ParaFrameworkPath:=TSearchPathList.Create;
  2234. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2235. end;
  2236. destructor TOption.destroy;
  2237. begin
  2238. ParaIncludePath.Free;
  2239. ParaObjectPath.Free;
  2240. ParaUnitPath.Free;
  2241. ParaLibraryPath.Free;
  2242. ParaFrameworkPath.Free;
  2243. end;
  2244. {****************************************************************************
  2245. Callable Routines
  2246. ****************************************************************************}
  2247. function check_configfile(const fn:string;var foundfn:string):boolean;
  2248. function CfgFileExists(const fn:string):boolean;
  2249. begin
  2250. Comment(V_Tried,'Configfile search: '+fn);
  2251. CfgFileExists:=FileExists(fn);
  2252. end;
  2253. var
  2254. {$ifdef Unix}
  2255. hs,
  2256. {$endif Unix}
  2257. configpath : string;
  2258. begin
  2259. foundfn:=fn;
  2260. check_configfile:=true;
  2261. { retrieve configpath }
  2262. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2263. {$ifdef Unix}
  2264. if configpath='' then
  2265. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2266. {$endif}
  2267. {
  2268. Order to read configuration file :
  2269. try reading fpc.cfg in :
  2270. 1 - current dir
  2271. 2 - configpath
  2272. 3 - compiler path
  2273. }
  2274. if not FileExists(fn) then
  2275. begin
  2276. {$ifdef Unix}
  2277. hs:=GetEnvironmentVariable('HOME');
  2278. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2279. foundfn:=FixPath(hs,false)+'.'+fn
  2280. else
  2281. {$endif}
  2282. if CfgFileExists(configpath+fn) then
  2283. foundfn:=configpath+fn
  2284. else
  2285. {$ifndef Unix}
  2286. if CfgFileExists(exepath+fn) then
  2287. foundfn:=exepath+fn
  2288. else
  2289. {$else}
  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) or defined(jvm)}
  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. {$ifdef jvm}
  2474. def_system_macro('CPUJVM');
  2475. def_system_macro('CPU32');
  2476. def_system_macro('FPC_CURRENCY_IS_INT64');
  2477. def_system_macro('FPC_COMP_IS_INT64');
  2478. {$endif jvm}
  2479. { read configuration file }
  2480. if (not disable_configfile) and
  2481. (ppccfg<>'') then
  2482. read_configfile:=check_configfile(ppccfg,ppccfg)
  2483. else
  2484. read_configfile := false;
  2485. { Read commandline and configfile }
  2486. param_file:='';
  2487. { read configfile }
  2488. if read_configfile then
  2489. option.interpret_file(ppccfg);
  2490. { read parameters again to override config file }
  2491. if cmd<>'' then
  2492. option.parsecmd(cmd)
  2493. else
  2494. begin
  2495. { Write help pages if no parameters are passed }
  2496. if (paramcount=0) then
  2497. Option.WriteHelpPages;
  2498. option.read_parameters;
  2499. { Write only quickinfo }
  2500. if option.quickinfo<>'' then
  2501. option.writequickinfo;
  2502. end;
  2503. { check the compatibility of different options and adjust them if necessary
  2504. (and print possible errors)
  2505. }
  2506. option.checkoptionscompatibility;
  2507. { Stop if errors in options }
  2508. if ErrorCount>0 then
  2509. StopOptions(1);
  2510. { endian define }
  2511. case target_info.endian of
  2512. endian_little :
  2513. begin
  2514. def_system_macro('ENDIAN_LITTLE');
  2515. def_system_macro('FPC_LITTLE_ENDIAN');
  2516. end;
  2517. endian_big :
  2518. begin
  2519. def_system_macro('ENDIAN_BIG');
  2520. def_system_macro('FPC_BIG_ENDIAN');
  2521. end;
  2522. end;
  2523. { define abi }
  2524. for abi:=low(tabi) to high(tabi) do
  2525. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2526. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2527. { Write logo }
  2528. if option.ParaLogo then
  2529. option.writelogo;
  2530. { Check file to compile }
  2531. if param_file='' then
  2532. begin
  2533. Message(option_no_source_found);
  2534. StopOptions(1);
  2535. end;
  2536. {$ifndef Unix}
  2537. param_file:=FixFileName(param_file);
  2538. {$endif not unix}
  2539. inputfilepath:=ExtractFilePath(param_file);
  2540. inputfilename:=ExtractFileName(param_file);
  2541. if ExtractFileExt(inputfilename)='' then
  2542. begin
  2543. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2544. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2545. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2546. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2547. else if ((m_mac in current_settings.modeswitches) or
  2548. (tf_p_ext_support in target_info.flags))
  2549. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2550. inputfilename:=ChangeFileExt(inputfilename,pext);
  2551. end;
  2552. { Check output dir }
  2553. if (OutputExeDir<>'') and
  2554. not PathExists(OutputExeDir,false) then
  2555. begin
  2556. Message1(general_e_path_does_not_exist,OutputExeDir);
  2557. StopOptions(1);
  2558. end;
  2559. { Add paths specified with parameters to the searchpaths }
  2560. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2561. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2562. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2563. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2564. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2565. { add unit environment and exepath to the unit search path }
  2566. if inputfilepath<>'' then
  2567. Unitsearchpath.AddPath(inputfilepath,true);
  2568. if not disable_configfile then
  2569. begin
  2570. env:=GetEnvironmentVariable(target_info.unit_env);
  2571. if env<>'' then
  2572. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2573. end;
  2574. {$ifdef Unix}
  2575. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2576. if fpcdir='' then
  2577. begin
  2578. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2579. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2580. else
  2581. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2582. end;
  2583. {$else unix}
  2584. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2585. if fpcdir='' then
  2586. begin
  2587. fpcdir:=ExePath+'../';
  2588. if not(PathExists(fpcdir+'units',true)) and
  2589. not(PathExists(fpcdir+'rtl',true)) then
  2590. fpcdir:=fpcdir+'../';
  2591. end;
  2592. {$endif unix}
  2593. { first try development RTL, else use the default installation path }
  2594. if not disable_configfile then
  2595. begin
  2596. if PathExists(FpcDir+'rtl',true) then
  2597. if tf_use_8_3 in Source_Info.Flags then
  2598. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2599. else
  2600. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2601. else
  2602. if tf_use_8_3 in Source_Info.Flags then
  2603. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2604. else
  2605. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2606. end;
  2607. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2608. Do not add it when linking on the target because then we can maybe already find
  2609. .o files that are not for the target }
  2610. if (ExePath<>GetCurrentDir) and
  2611. not(cs_link_on_target in init_settings.globalswitches) then
  2612. UnitSearchPath.AddPath(ExePath,false);
  2613. { Add unit dir to the object and library path }
  2614. objectsearchpath.AddList(unitsearchpath,false);
  2615. librarysearchpath.AddList(unitsearchpath,false);
  2616. { maybe override assembler }
  2617. if (paratargetasm<>as_none) then
  2618. begin
  2619. if not set_target_asm(paratargetasm) then
  2620. begin
  2621. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2622. set_target_asm(target_info.assemextern);
  2623. Message1(option_asm_forced,target_asm.idtxt);
  2624. end;
  2625. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2626. (paratargetdbg<>dbg_none) then
  2627. begin
  2628. Message1(option_confict_asm_debug,
  2629. asminfos[paratargetasm]^.idtxt);
  2630. paratargetdbg:=dbg_none;
  2631. exclude(init_settings.moduleswitches,cs_debuginfo);
  2632. end;
  2633. end;
  2634. { maybe override debug info format }
  2635. if (paratargetdbg<>dbg_none) then
  2636. set_target_dbg(paratargetdbg);
  2637. { switch assembler if it's binary and we got -a on the cmdline }
  2638. if (cs_asm_leave in init_settings.globalswitches) and
  2639. (af_outputbinary in target_asm.flags) then
  2640. begin
  2641. Message(option_switch_bin_to_src_assembler);
  2642. set_target_asm(target_info.assemextern);
  2643. end;
  2644. { Force use of external linker if there is no
  2645. internal linker or the linking is skipped }
  2646. if not(cs_link_extern in init_settings.globalswitches) and
  2647. (not assigned(target_info.link) or
  2648. (cs_link_nolink in init_settings.globalswitches)) then
  2649. include(init_settings.globalswitches,cs_link_extern);
  2650. { turn off stripping if compiling with debuginfo or profile }
  2651. if (
  2652. (cs_debuginfo in init_settings.moduleswitches) or
  2653. (cs_profile in init_settings.moduleswitches)
  2654. ) and
  2655. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2656. exclude(init_settings.globalswitches,cs_link_strip);
  2657. { force fpu emulation on arm/wince, arm/gba, arm/embedded, arm/nds and
  2658. arm/darwin if fpu type not explicitly set }
  2659. if not(option.FPUSetExplicitly) and
  2660. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2661. system_m68k_linux,system_arm_nds,system_arm_embedded,system_arm_darwin])
  2662. {$ifdef arm}
  2663. or (target_info.abi=abi_eabi)
  2664. {$endif arm}
  2665. )
  2666. {$ifdef arm}
  2667. or (init_settings.fputype=fpu_soft)
  2668. {$endif arm}
  2669. then
  2670. begin
  2671. {$ifdef cpufpemu}
  2672. include(init_settings.moduleswitches,cs_fp_emulation);
  2673. { cs_fp_emulation and fpu_soft are equal on arm }
  2674. init_settings.fputype:=fpu_soft;
  2675. {$endif cpufpemu}
  2676. end;
  2677. {$ifdef arm}
  2678. { set default cpu type to ARMv6 for Darwin unless specified otherwise }
  2679. if (target_info.system=system_arm_darwin) then
  2680. begin
  2681. if not option.CPUSetExplicitly then
  2682. init_settings.cputype:=cpu_armv6;
  2683. if not option.OptCPUSetExplicitly then
  2684. init_settings.optimizecputype:=cpu_armv6;
  2685. end;
  2686. {$endif arm}
  2687. { now we can define cpu and fpu type }
  2688. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2689. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2690. if init_settings.fputype<>fpu_none then
  2691. begin
  2692. {$if defined(i386)}
  2693. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2694. {$endif}
  2695. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2696. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2697. {$if not defined(i386) and not defined(x86_64)}
  2698. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2699. {$endif}
  2700. {$ifdef x86_64}
  2701. { win64 doesn't support the legacy fpu }
  2702. if target_info.system=system_x86_64_win64 then
  2703. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2704. else
  2705. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2706. {$endif}
  2707. end;
  2708. { Not ready yet }
  2709. {$ifdef TEST_TLS_DIRECTORY}
  2710. if target_info.system in systems_windows then
  2711. def_system_macro('FPC_USE_TLS_DIRECTORY');
  2712. {$endif TEST_TLS_DIRECTORY}
  2713. {$ifdef ARM}
  2714. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2715. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2716. not(cs_fp_emulation in init_settings.moduleswitches) then
  2717. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2718. {$endif ARM}
  2719. { Section smartlinking conflicts with import sections on Windows }
  2720. if GenerateImportSection and
  2721. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2722. exclude(target_info.flags,tf_smartlink_sections);
  2723. if not LinkTypeSetExplicitly then
  2724. set_default_link_type;
  2725. { Default alignment settings,
  2726. 1. load the defaults for the target
  2727. 2. override with generic optimizer setting (little size)
  2728. 3. override with the user specified -Oa }
  2729. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2730. if (cs_opt_size in current_settings.optimizerswitches) then
  2731. begin
  2732. init_settings.alignment.procalign:=1;
  2733. init_settings.alignment.jumpalign:=1;
  2734. init_settings.alignment.loopalign:=1;
  2735. end;
  2736. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2737. set_system_macro('FPC_VERSION',version_nr);
  2738. set_system_macro('FPC_RELEASE',release_nr);
  2739. set_system_macro('FPC_PATCH',patch_nr);
  2740. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  2741. if not(target_info.system in systems_windows) then
  2742. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  2743. for i:=low(tfeature) to high(tfeature) do
  2744. if i in features then
  2745. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2746. option.free;
  2747. Option:=nil;
  2748. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  2749. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl];
  2750. if (tf_safecall_clearstack in target_info.flags) then
  2751. begin
  2752. include (cdecl_pocalls, pocall_safecall);
  2753. include (clearstack_pocalls, pocall_safecall)
  2754. end;
  2755. end;
  2756. initialization
  2757. coption:=toption;
  2758. finalization
  2759. if assigned(option) then
  2760. option.free;
  2761. end.