options.pas 161 KB

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