options.pas 175 KB

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