options.pas 129 KB

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