options.pas 110 KB

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