options.pas 187 KB

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