options.pas 171 KB

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