options.pas 159 KB

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