options.pas 185 KB

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