options.pas 165 KB

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