options.pas 183 KB

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