options.pas 181 KB

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