options.pas 164 KB

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