options.pas 188 KB

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