options.pas 186 KB

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