options.pas 111 KB

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