options.pas 179 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289
  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. IllegalPara(opt);
  2892. end;
  2893. 'T':
  2894. begin
  2895. if target_info.system in systems_macos then
  2896. begin
  2897. if UnsetBool(More, j, opt, false) then
  2898. SetApptype(app_cui)
  2899. else
  2900. SetApptype(app_tool);
  2901. end
  2902. else
  2903. IllegalPara(opt);
  2904. end;
  2905. 'X':
  2906. begin
  2907. if (target_info.system in systems_linux) then
  2908. begin
  2909. if UnsetBool(More, j, opt, false) then
  2910. exclude(init_settings.moduleswitches,cs_executable_stack)
  2911. else
  2912. include(init_settings.moduleswitches,cs_executable_stack)
  2913. end
  2914. else
  2915. IllegalPara(opt);
  2916. end;
  2917. else
  2918. IllegalPara(opt);
  2919. end;
  2920. inc(j);
  2921. end;
  2922. end;
  2923. 'X' :
  2924. begin
  2925. j:=1;
  2926. while j<=length(more) do
  2927. begin
  2928. case More[j] of
  2929. '9' :
  2930. begin
  2931. if target_info.system in systems_linux then
  2932. begin
  2933. if UnsetBool(More, j, opt, false) then
  2934. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2935. else
  2936. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2937. end
  2938. else
  2939. IllegalPara(opt);
  2940. end;
  2941. 'a' :
  2942. begin
  2943. If UnsetBool(More, j, opt, false) then
  2944. exclude(init_settings.globalswitches,cs_large)
  2945. else
  2946. include(init_settings.globalswitches,cs_large);
  2947. end;
  2948. 'c' : Cshared:=TRUE;
  2949. 'd' : Dontlinkstdlibpath:=TRUE;
  2950. 'e' :
  2951. begin
  2952. If UnsetBool(More, j, opt, false) then
  2953. exclude(init_settings.globalswitches,cs_link_extern)
  2954. else
  2955. include(init_settings.globalswitches,cs_link_extern);
  2956. end;
  2957. 'f' :
  2958. include(init_settings.globalswitches,cs_link_pthread);
  2959. 'g' :
  2960. begin
  2961. If UnsetBool(More, j, opt, false) then
  2962. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2963. else
  2964. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2965. end;
  2966. 'i' :
  2967. begin
  2968. If UnsetBool(More, j, opt, false) then
  2969. include(init_settings.globalswitches,cs_link_extern)
  2970. else
  2971. exclude(init_settings.globalswitches,cs_link_extern);
  2972. end;
  2973. 'n' :
  2974. begin
  2975. If UnsetBool(More, j, opt, false) then
  2976. exclude(init_settings.globalswitches,cs_link_native)
  2977. else
  2978. include(init_settings.globalswitches,cs_link_native);
  2979. end;
  2980. {$ifdef llvm}
  2981. 'l' :
  2982. begin
  2983. if j=length(more) then
  2984. IllegalPara(opt)
  2985. else
  2986. begin
  2987. case more[j+1] of
  2988. 'S':
  2989. begin
  2990. llvmutilssuffix:=copy(more,j+2,length(more));
  2991. j:=length(more);
  2992. end
  2993. else
  2994. IllegalPara(opt);
  2995. end;
  2996. end;
  2997. end;
  2998. {$endif}
  2999. 'm' :
  3000. begin
  3001. If UnsetBool(More, j, opt, false) then
  3002. exclude(init_settings.globalswitches,cs_link_map)
  3003. else
  3004. include(init_settings.globalswitches,cs_link_map);
  3005. end;
  3006. 'p' : ; { Ignore used by fpc.pp }
  3007. 'r' :
  3008. begin
  3009. if (target_info.system in suppported_targets_x_smallr) then
  3010. begin
  3011. rlinkpath:=Copy(more,2,length(More)-1);
  3012. DefaultReplacements(rlinkpath);
  3013. end
  3014. else
  3015. IgnoredPara('-Xr');
  3016. more:='';
  3017. end;
  3018. 'R' :
  3019. begin
  3020. sysrootpath:=copy(more,2,length(more)-1);
  3021. defaultreplacements(sysrootpath);
  3022. more:='';
  3023. end;
  3024. 's' :
  3025. begin
  3026. If UnsetBool(More, j, opt, false) then
  3027. exclude(init_settings.globalswitches,cs_link_strip)
  3028. else
  3029. include(init_settings.globalswitches,cs_link_strip);
  3030. end;
  3031. 't' :
  3032. include(init_settings.globalswitches,cs_link_staticflag);
  3033. 'u' :
  3034. begin
  3035. if target_info.system in systems_support_uf2 then
  3036. begin
  3037. if UnsetBool(More, j, opt, false) then
  3038. exclude(init_settings.globalswitches,cs_generate_uf2)
  3039. else
  3040. include(init_settings.globalswitches,cs_generate_uf2);
  3041. end
  3042. else
  3043. IgnoredPara('-Xu');
  3044. end;
  3045. 'v' :
  3046. begin
  3047. If UnsetBool(More, j, opt, false) then
  3048. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  3049. else
  3050. include(init_settings.globalswitches,cs_link_opt_vtable);
  3051. end;
  3052. 'D' :
  3053. begin
  3054. def_system_macro('FPC_LINK_DYNAMIC');
  3055. undef_system_macro('FPC_LINK_SMART');
  3056. undef_system_macro('FPC_LINK_STATIC');
  3057. exclude(init_settings.globalswitches,cs_link_static);
  3058. exclude(init_settings.globalswitches,cs_link_smart);
  3059. include(init_settings.globalswitches,cs_link_shared);
  3060. LinkTypeSetExplicitly:=true;
  3061. end;
  3062. 'M' :
  3063. begin
  3064. mainaliasname:=Copy(more,2,length(More)-1);
  3065. More:='';
  3066. end;
  3067. 'P' :
  3068. begin
  3069. utilsprefix:=Copy(more,2,length(More)-1);
  3070. DefaultReplacements(utilsprefix);
  3071. More:='';
  3072. end;
  3073. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  3074. // these are not aggregable.
  3075. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  3076. IllegalPara(opt)
  3077. else
  3078. begin
  3079. case more[j+1] of
  3080. 'A' : begin
  3081. s:=Copy(more,3,length(More)-2);
  3082. if not LinkLibraryAliases.AddDep(s) Then
  3083. IllegalPara(opt);
  3084. end;
  3085. 'O' : begin
  3086. s:=Copy(more,3,length(More)-2);
  3087. if not LinkLibraryOrder.AddWeight(s) Then
  3088. IllegalPara(opt);
  3089. end;
  3090. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  3091. else
  3092. IllegalPara(opt);
  3093. end; {case}
  3094. j:=length(more);
  3095. end; {else begin}
  3096. end;
  3097. 'S' :
  3098. begin
  3099. ForceStaticLinking;
  3100. end;
  3101. 'V' :
  3102. begin
  3103. if UnsetBool(More, j, opt, false) then
  3104. exclude(init_settings.globalswitches,cs_link_vlink)
  3105. else
  3106. begin
  3107. include(init_settings.globalswitches,cs_link_vlink);
  3108. include(init_settings.globalswitches,cs_link_extern);
  3109. end;
  3110. LinkerSetExplicitly:=true;
  3111. end;
  3112. 'X' :
  3113. begin
  3114. def_system_macro('FPC_LINK_SMART');
  3115. undef_system_macro('FPC_LINK_STATIC');
  3116. undef_system_macro('FPC_LINK_DYNAMIC');
  3117. exclude(init_settings.globalswitches,cs_link_static);
  3118. include(init_settings.globalswitches,cs_link_smart);
  3119. exclude(init_settings.globalswitches,cs_link_shared);
  3120. LinkTypeSetExplicitly:=true;
  3121. end;
  3122. '-' :
  3123. begin
  3124. exclude(init_settings.globalswitches,cs_link_staticflag);
  3125. exclude(init_settings.globalswitches,cs_link_strip);
  3126. exclude(init_settings.globalswitches,cs_link_map);
  3127. set_default_link_type;
  3128. end;
  3129. else
  3130. IllegalPara(opt);
  3131. end;
  3132. inc(j);
  3133. end;
  3134. end;
  3135. else
  3136. IllegalPara(opt);
  3137. end;
  3138. end;
  3139. '@' :
  3140. begin
  3141. Message(option_no_nested_response_file);
  3142. StopOptions(1);
  3143. end;
  3144. else
  3145. begin
  3146. if (length(param_file)<>0) then
  3147. Message2(option_only_one_source_support,param_file,opt);
  3148. param_file:=opt;
  3149. Message1(option_found_file,opt);
  3150. end;
  3151. end;
  3152. end;
  3153. procedure Toption.Interpret_file(const filename : TPathStr);
  3154. procedure RemoveSep(var fn:TPathStr);
  3155. var
  3156. i : longint;
  3157. begin
  3158. i:=0;
  3159. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  3160. inc(i);
  3161. Delete(fn,1,i);
  3162. i:=length(fn);
  3163. while (i>0) and (fn[i] in [',',' ',#9]) do
  3164. dec(i);
  3165. fn:=copy(fn,1,i);
  3166. end;
  3167. function GetName(var fn:TPathStr):TPathStr;
  3168. var
  3169. i : longint;
  3170. begin
  3171. i:=0;
  3172. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  3173. inc(i);
  3174. GetName:=Copy(fn,1,i);
  3175. Delete(fn,1,i);
  3176. end;
  3177. const
  3178. maxlevel = 15;
  3179. var
  3180. f : text;
  3181. s, tmp,
  3182. opts : TCmdStr;
  3183. skip : array[0..maxlevel] of boolean;
  3184. line,
  3185. level : longint;
  3186. option_read : boolean;
  3187. oldfilemode : byte;
  3188. ConfigFile: TPathStr;
  3189. begin
  3190. { avoid infinite loop }
  3191. Inc(FileLevel);
  3192. Option_read:=false;
  3193. If FileLevel>MaxLevel then
  3194. Message(option_too_many_cfg_files);
  3195. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  3196. ConfigFile := ExpandFileName(filename);
  3197. { Maybe It's Directory ?} //Jaro Change:
  3198. if PathExists(ConfigFile,false) then
  3199. begin
  3200. Message1(option_config_is_dir,filename);
  3201. exit;
  3202. end;
  3203. { open file }
  3204. Message1(option_using_file,filename);
  3205. oldfilemode:=filemode;
  3206. filemode:=0;
  3207. assign(f,ConfigFile);
  3208. {$push}{$I-}
  3209. reset(f);
  3210. {$pop}
  3211. filemode:=oldfilemode;
  3212. if ioresult<>0 then
  3213. begin
  3214. Message1(option_unable_open_file,filename);
  3215. exit;
  3216. end;
  3217. Message1(option_start_reading_configfile,filename);
  3218. fillchar(skip,sizeof(skip),0);
  3219. level:=0;
  3220. line:=0;
  3221. while not eof(f) do
  3222. begin
  3223. readln(f,opts);
  3224. inc(line);
  3225. RemoveSep(opts);
  3226. if (opts<>'') and (opts[1]<>';') then
  3227. begin
  3228. if opts[1]='#' then
  3229. begin
  3230. Message1(option_interpreting_file_option,opts);
  3231. Delete(opts,1,1);
  3232. s:=upper(GetName(opts));
  3233. if (s='SECTION') then
  3234. begin
  3235. RemoveSep(opts);
  3236. s:=upper(GetName(opts));
  3237. if level=0 then
  3238. skip[level]:=not defined_macro(s) or (s='COMMON');
  3239. end
  3240. else
  3241. if (s='IFDEF') then
  3242. begin
  3243. RemoveSep(opts);
  3244. if Level>=maxlevel then
  3245. begin
  3246. Message2(option_too_many_ifdef,filename,tostr(line));
  3247. stopOptions(1);
  3248. end;
  3249. inc(Level);
  3250. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  3251. end
  3252. else
  3253. if (s='IFNDEF') then
  3254. begin
  3255. RemoveSep(opts);
  3256. if Level>=maxlevel then
  3257. begin
  3258. Message2(option_too_many_ifdef,filename,tostr(line));
  3259. stopOptions(1);
  3260. end;
  3261. inc(Level);
  3262. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  3263. end
  3264. else
  3265. if (s='ELSE') then
  3266. begin
  3267. if Level=0 then
  3268. begin
  3269. Message2(option_else_without_if,filename,tostr(line));
  3270. stopOptions(1);
  3271. end
  3272. else
  3273. skip[level]:=skip[level-1] or (not skip[level])
  3274. end
  3275. else
  3276. if (s='ENDIF') then
  3277. begin
  3278. skip[level]:=false;
  3279. if Level=0 then
  3280. begin
  3281. Message2(option_too_many_endif,filename,tostr(line));
  3282. stopOptions(1);
  3283. end;
  3284. dec(level);
  3285. end
  3286. else
  3287. if (not skip[level]) then
  3288. begin
  3289. if (s='DEFINE') then
  3290. begin
  3291. RemoveSep(opts);
  3292. tmp:= GetName(opts);
  3293. if tmp <> '' then
  3294. def_system_macro(tmp);
  3295. Option_read:=true;
  3296. end
  3297. else
  3298. if (s='UNDEF') then
  3299. begin
  3300. RemoveSep(opts);
  3301. tmp:= GetName(opts);
  3302. if tmp <> '' then
  3303. undef_system_macro(tmp);
  3304. Option_read:=true;
  3305. end
  3306. else
  3307. if (s='WRITE') then
  3308. begin
  3309. Delete(opts,1,1);
  3310. DefaultReplacements(opts);
  3311. WriteLn(opts);
  3312. Option_read:=true;
  3313. end
  3314. else
  3315. if (s='INCLUDE') then
  3316. begin
  3317. Delete(opts,1,1);
  3318. DefaultReplacements(opts);
  3319. Interpret_file(opts);
  3320. Option_read:=true;
  3321. end
  3322. else
  3323. if (s='CFGDIR') then
  3324. begin
  3325. Delete(opts,1,1);
  3326. DefaultReplacements(opts);
  3327. ParaIncludeCfgPath.AddPath(opts,false);
  3328. Option_read:=true;
  3329. end;
  3330. end;
  3331. end
  3332. else
  3333. begin
  3334. if (opts[1]='-') or (opts[1]='@') then
  3335. begin
  3336. if (not skip[level]) then
  3337. interpret_option(opts,false);
  3338. Option_read:=true;
  3339. end
  3340. else
  3341. Message1(option_illegal_para,opts);
  3342. end;
  3343. end;
  3344. end;
  3345. if Level>0 then
  3346. Message(option_too_less_endif);
  3347. if Not Option_read then
  3348. Message1(option_no_option_found,filename)
  3349. else
  3350. Message1(option_end_reading_configfile,filename);
  3351. Close(f);
  3352. Dec(FileLevel);
  3353. end;
  3354. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  3355. var
  3356. argstart,
  3357. env,
  3358. pc : pchar;
  3359. arglen : longint;
  3360. quote : set of char;
  3361. hs : TCmdStr;
  3362. begin
  3363. Message1(option_using_env,envname);
  3364. env:=GetEnvPChar(envname);
  3365. pc:=env;
  3366. hs:='';
  3367. if assigned(pc) then
  3368. begin
  3369. repeat
  3370. { skip leading spaces }
  3371. while pc^ in [' ',#9,#13] do
  3372. inc(pc);
  3373. case pc^ of
  3374. #0 :
  3375. break;
  3376. '"' :
  3377. begin
  3378. quote:=['"'];
  3379. inc(pc);
  3380. end;
  3381. '''' :
  3382. begin
  3383. quote:=[''''];
  3384. inc(pc);
  3385. end;
  3386. else
  3387. quote:=[' ',#9,#13];
  3388. end;
  3389. { scan until the end of the argument }
  3390. argstart:=pc;
  3391. while (pc^<>#0) and not(pc^ in quote) do
  3392. inc(pc);
  3393. { create argument }
  3394. arglen:=pc-argstart;
  3395. { TODO: FIXME: silent truncation of environment parameters }
  3396. if (arglen > 255) then
  3397. arglen := 255;
  3398. setlength(hs,arglen);
  3399. move(argstart^,hs[1],arglen);
  3400. interpret_option(hs,true);
  3401. { skip quote }
  3402. if pc^ in quote then
  3403. inc(pc);
  3404. until false;
  3405. end
  3406. else
  3407. Message1(option_no_option_found,'(env) '+envname);
  3408. FreeEnvPChar(env);
  3409. end;
  3410. procedure toption.read_parameters;
  3411. var
  3412. opts : TCmdStr;
  3413. paramindex : longint;
  3414. begin
  3415. paramindex:=0;
  3416. while paramindex<paramcount do
  3417. begin
  3418. inc(paramindex);
  3419. opts:=objpas.paramstr(paramindex);
  3420. if length(opts)>0 then
  3421. case opts[1] of
  3422. '@' :
  3423. if not firstpass then
  3424. begin
  3425. Delete(opts,1,1);
  3426. Message1(option_reading_further_from,opts);
  3427. interpret_file(opts);
  3428. end;
  3429. '!' :
  3430. if not firstpass then
  3431. begin
  3432. Delete(opts,1,1);
  3433. Message1(option_reading_further_from,'(env) '+opts);
  3434. interpret_envvar(opts);
  3435. end;
  3436. else
  3437. interpret_option(opts,true);
  3438. end;
  3439. end;
  3440. end;
  3441. procedure toption.parsecmd(cmd:TCmdStr);
  3442. var
  3443. i,ps : longint;
  3444. opts : TCmdStr;
  3445. begin
  3446. while (cmd<>'') do
  3447. begin
  3448. while cmd[1]=' ' do
  3449. delete(cmd,1,1);
  3450. i:=pos(' ',cmd);
  3451. if i=0 then
  3452. i:=2147483647;
  3453. opts:=Copy(cmd,1,i-1);
  3454. Delete(cmd,1,i);
  3455. case opts[1] of
  3456. '@' :
  3457. if not firstpass then
  3458. begin
  3459. Delete(opts,1,1);
  3460. Message1(option_reading_further_from,opts);
  3461. interpret_file(opts);
  3462. end;
  3463. '!' :
  3464. if not firstpass then
  3465. begin
  3466. Delete(opts,1,1);
  3467. Message1(option_reading_further_from,'(env) '+opts);
  3468. interpret_envvar(opts);
  3469. end;
  3470. '"' :
  3471. begin
  3472. Delete(opts,1,1);
  3473. ps:=pos('"',cmd);
  3474. if (i<>256) and (ps>0) then
  3475. begin
  3476. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3477. cmd:=copy(cmd,ps+1,255);
  3478. end;
  3479. interpret_option(opts,true);
  3480. end;
  3481. else
  3482. interpret_option(opts,true);
  3483. end;
  3484. end;
  3485. end;
  3486. procedure toption.writequickinfo;
  3487. var
  3488. s : string;
  3489. i : longint;
  3490. procedure addinfo(const hs:string);
  3491. begin
  3492. if s<>'' then
  3493. s:=s+' '+hs
  3494. else
  3495. s:=hs;
  3496. end;
  3497. begin
  3498. s:='';
  3499. i:=0;
  3500. while (i<length(quickinfo)) do
  3501. begin
  3502. inc(i);
  3503. case quickinfo[i] of
  3504. 'S' :
  3505. begin
  3506. inc(i);
  3507. case quickinfo[i] of
  3508. 'O' :
  3509. addinfo(lower(source_info.shortname));
  3510. 'P' :
  3511. addinfo(source_cpu_string);
  3512. else
  3513. IllegalPara('-i'+QuickInfo);
  3514. end;
  3515. end;
  3516. 'T' :
  3517. begin
  3518. inc(i);
  3519. case quickinfo[i] of
  3520. 'O' :
  3521. addinfo(lower(target_info.shortname));
  3522. 'P' :
  3523. AddInfo(target_cpu_string);
  3524. else
  3525. IllegalPara('-i'+QuickInfo);
  3526. end;
  3527. end;
  3528. 'V' :
  3529. AddInfo(version_string);
  3530. 'W' :
  3531. AddInfo(full_version_string);
  3532. 'D' :
  3533. AddInfo(date_string);
  3534. '_' :
  3535. ;
  3536. else
  3537. IllegalPara('-i'+QuickInfo);
  3538. end;
  3539. end;
  3540. if s<>'' then
  3541. begin
  3542. writeln(s);
  3543. stopoptions(0);
  3544. end;
  3545. end;
  3546. procedure TOption.TargetOptions(def:boolean);
  3547. var
  3548. s : string;
  3549. i : integer;
  3550. target_unsup_features : tfeatures;
  3551. begin
  3552. if def then
  3553. def_system_macro(target_info.shortname)
  3554. else
  3555. undef_system_macro(target_info.shortname);
  3556. s:=target_info.extradefines;
  3557. while (s<>'') do
  3558. begin
  3559. i:=pos(';',s);
  3560. if i=0 then
  3561. i:=length(s)+1;
  3562. if def then
  3563. def_system_macro(Copy(s,1,i-1))
  3564. else
  3565. undef_system_macro(Copy(s,1,i-1));
  3566. delete(s,1,i);
  3567. end;
  3568. if (tf_winlikewidestring in target_info.flags) then
  3569. if def then
  3570. def_system_macro('FPC_WINLIKEWIDESTRING')
  3571. else
  3572. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3573. if (tf_requires_proper_alignment in target_info.flags) then
  3574. if def then
  3575. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3576. else
  3577. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3578. if (tf_init_final_units_by_calls in target_info.flags) then
  3579. if def then
  3580. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3581. else
  3582. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3583. if source_info.system<>target_info.system then
  3584. if def then
  3585. def_system_macro('FPC_CROSSCOMPILING')
  3586. else
  3587. undef_system_macro('FPC_CROSSCOMPILING');
  3588. if source_info.cpu<>target_info.cpu then
  3589. if def then
  3590. def_system_macro('FPC_CPUCROSSCOMPILING')
  3591. else
  3592. def_system_macro('FPC_CPUCROSSCOMPILING');
  3593. if (tf_no_generic_stackcheck in target_info.flags) then
  3594. if def then
  3595. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3596. else
  3597. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3598. if (tf_section_threadvars in target_info.flags) then
  3599. if def then
  3600. def_system_macro('FPC_SECTION_THREADVARS')
  3601. else
  3602. undef_system_macro('FPC_SECTION_THREADVARS');
  3603. if (tf_use_psabieh in target_info.flags) then
  3604. if def then
  3605. def_system_macro('FPC_USE_PSABIEH')
  3606. else
  3607. undef_system_macro('FPC_USE_PSABIEH');
  3608. { Code generation flags }
  3609. if (tf_pic_default in target_info.flags) then
  3610. if def then
  3611. include(init_settings.moduleswitches,cs_create_pic)
  3612. else
  3613. exclude(init_settings.moduleswitches,cs_create_pic);
  3614. { Resources support }
  3615. if (tf_has_winlike_resources in target_info.flags) then
  3616. if def then
  3617. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3618. else
  3619. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3620. { Features }
  3621. case target_info.system of
  3622. system_arm_gba:
  3623. target_unsup_features:=[f_dynlibs];
  3624. system_arm_nds:
  3625. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3626. system_i386_nativent:
  3627. // until these features are implemented, they are disabled in the compiler
  3628. target_unsup_features:=[f_stackcheck];
  3629. system_i8086_msdos:
  3630. target_unsup_features:=[f_threading,f_dynlibs];
  3631. system_i8086_win16:
  3632. target_unsup_features:=[f_threading];
  3633. system_jvm_java32,
  3634. system_jvm_android32:
  3635. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3636. f_variants,f_objects,f_commandargs,
  3637. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3638. system_arm_palmos,
  3639. system_m68k_palmos:
  3640. target_unsup_features:=[f_threading];
  3641. system_m68k_atari:
  3642. target_unsup_features:=[f_threading];
  3643. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3644. normal dynlibs infrastructure due to architectural differences, so therefore
  3645. lets disable the feature. }
  3646. system_m68k_amiga:
  3647. target_unsup_features:=[f_dynlibs];
  3648. system_m68k_sinclairql:
  3649. target_unsup_features:=[f_threading,f_dynlibs];
  3650. system_z80_zxspectrum:
  3651. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3652. system_z80_msxdos:
  3653. target_unsup_features:=[f_threading,f_dynlibs];
  3654. else
  3655. target_unsup_features:=[];
  3656. end;
  3657. if def then
  3658. features:=features-target_unsup_features
  3659. else
  3660. features:=features+target_unsup_features;
  3661. {$if defined(atari) or defined(hasamiga)}
  3662. { enable vlink as default linker on Atari and Amiga but not for cross compilers (for now) }
  3663. if (target_info.system in [system_m68k_amiga,system_m68k_atari,system_powerpc_amiga]) and
  3664. not LinkerSetExplicitly then
  3665. include(init_settings.globalswitches,cs_link_vlink);
  3666. {$endif}
  3667. {$ifdef m68k}
  3668. if (target_info.system in [system_m68k_sinclairql]) and
  3669. not LinkerSetExplicitly then
  3670. include(init_settings.globalswitches,cs_link_vlink);
  3671. {$endif m68k}
  3672. end;
  3673. procedure TOption.checkoptionscompatibility;
  3674. begin
  3675. {$ifdef wasm}
  3676. if (Ord(ts_wasm_no_exceptions in init_settings.targetswitches)+
  3677. Ord(ts_wasm_js_exceptions in init_settings.targetswitches)+
  3678. Ord(ts_wasm_native_exceptions in init_settings.targetswitches)+
  3679. Ord(ts_wasm_bf_exceptions in init_settings.targetswitches))>1 then
  3680. begin
  3681. Message(option_too_many_exception_modes);
  3682. StopOptions(1);
  3683. end;
  3684. {$endif}
  3685. {$ifdef i8086}
  3686. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3687. begin
  3688. Message(option_com_files_require_tiny_model);
  3689. StopOptions(1);
  3690. end;
  3691. {$endif i8086}
  3692. {$ifndef i8086_link_intern_debuginfo}
  3693. if (cs_debuginfo in init_settings.moduleswitches) and
  3694. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3695. not (cs_link_extern in init_settings.globalswitches) then
  3696. begin
  3697. Message(option_debug_info_requires_external_linker);
  3698. include(init_settings.globalswitches,cs_link_extern);
  3699. end;
  3700. {$endif i8086_link_intern_debuginfo}
  3701. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3702. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3703. begin
  3704. { smartlink creation does not yet work with DWARF
  3705. debug info on most targets, but it works in internal assembler }
  3706. if (cs_create_smart in init_settings.moduleswitches) and
  3707. not (af_outputbinary in target_asm.flags) then
  3708. begin
  3709. Message(option_dwarf_smartlink_creation);
  3710. exclude(init_settings.moduleswitches,cs_create_smart);
  3711. end;
  3712. { smart linking does not yet work with DWARF debug info on most targets }
  3713. if (cs_link_smart in init_settings.globalswitches) then
  3714. begin
  3715. Message(option_dwarf_smart_linking);
  3716. ForceStaticLinking;
  3717. end;
  3718. end;
  3719. { external debug info is only supported for DWARF on darwin }
  3720. if (target_info.system in systems_darwin) and
  3721. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3722. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3723. begin
  3724. Message(option_debug_external_unsupported);
  3725. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3726. end;
  3727. { Also create a smartlinked version, on an assembler that
  3728. does not support smartlink sections like nasm?
  3729. This is not compatible with using internal linker. }
  3730. if ((cs_link_smart in init_settings.globalswitches) or
  3731. (cs_create_smart in init_settings.moduleswitches)) and
  3732. (af_needar in target_asm.flags) and
  3733. not (af_smartlink_sections in target_asm.flags) and
  3734. not (cs_link_extern in init_settings.globalswitches) and
  3735. (target_info.link<>ld_none) and
  3736. not (cs_link_nolink in init_settings.globalswitches) then
  3737. begin
  3738. Message(option_smart_link_requires_external_linker);
  3739. include(init_settings.globalswitches,cs_link_extern);
  3740. end;
  3741. end;
  3742. constructor TOption.create;
  3743. begin
  3744. LogoWritten:=false;
  3745. NoPressEnter:=false;
  3746. FirstPass:=false;
  3747. ABISetExplicitly:=false;
  3748. FPUSetExplicitly:=false;
  3749. CPUSetExplicitly:=false;
  3750. OptCPUSetExplicitly:=false;
  3751. FileLevel:=0;
  3752. Quickinfo:='';
  3753. ParaIncludeCfgPath:=TSearchPathList.Create;
  3754. ParaIncludePath:=TSearchPathList.Create;
  3755. ParaObjectPath:=TSearchPathList.Create;
  3756. ParaUnitPath:=TSearchPathList.Create;
  3757. ParaLibraryPath:=TSearchPathList.Create;
  3758. ParaFrameworkPath:=TSearchPathList.Create;
  3759. parapackagepath:=TSearchPathList.Create;
  3760. parapackages:=TFPHashObjectList.Create;
  3761. paranamespaces:=TCmdStrList.Create;
  3762. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3763. MacVersionSet:=false;
  3764. paratarget:=system_none;
  3765. paratargetasm:=as_none;
  3766. paratargetdbg:=dbg_none;
  3767. LinkTypeSetExplicitly:=false;
  3768. LinkerSetExplicitly:=false;
  3769. end;
  3770. destructor TOption.destroy;
  3771. begin
  3772. ParaIncludeCfgPath.Free;
  3773. ParaIncludePath.Free;
  3774. ParaObjectPath.Free;
  3775. ParaUnitPath.Free;
  3776. ParaLibraryPath.Free;
  3777. ParaFrameworkPath.Free;
  3778. parapackagepath.Free;
  3779. ParaPackages.Free;
  3780. paranamespaces.free;
  3781. end;
  3782. {****************************************************************************
  3783. Callable Routines
  3784. ****************************************************************************}
  3785. function check_configfile(fn:string; var foundfn:string):boolean;
  3786. function CfgFileExists(const fn:string):boolean;
  3787. begin
  3788. Comment(V_Tried,'Configfile search: '+fn);
  3789. CfgFileExists:=FileExists(fn);
  3790. end;
  3791. var
  3792. {$ifdef Unix}
  3793. hs,
  3794. {$endif Unix}
  3795. configpath : string;
  3796. begin
  3797. foundfn:=fn;
  3798. check_configfile:=true;
  3799. { retrieve configpath }
  3800. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3801. {$ifdef Unix}
  3802. if configpath='' then
  3803. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3804. {$endif}
  3805. {
  3806. Order to read configuration file :
  3807. try reading fpc.cfg in :
  3808. 1 - current dir
  3809. 2 - configpath
  3810. 3 - compiler path
  3811. }
  3812. if not FileExists(fn) then
  3813. begin
  3814. {$ifdef Unix}
  3815. hs:=GetEnvironmentVariable('HOME');
  3816. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3817. foundfn:=FixPath(hs,false)+'.'+fn
  3818. else
  3819. {$endif}
  3820. if CfgFileExists(configpath+fn) then
  3821. foundfn:=configpath+fn
  3822. else
  3823. {$ifdef WINDOWS}
  3824. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3825. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3826. else
  3827. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3828. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3829. else
  3830. {$endif WINDOWS}
  3831. {$ifndef Unix}
  3832. if CfgFileExists(exepath+fn) then
  3833. foundfn:=exepath+fn
  3834. else
  3835. {$else}
  3836. if CfgFileExists('/etc/'+fn) then
  3837. foundfn:='/etc/'+fn
  3838. else
  3839. {$endif}
  3840. check_configfile:=false;
  3841. end;
  3842. end;
  3843. procedure read_arguments(cmd:TCmdStr);
  3844. procedure def_cpu_macros;
  3845. var
  3846. abi : tabi;
  3847. fputype : tfputype;
  3848. cputype : tcputype;
  3849. controller: tcontrollertype;
  3850. s: string;
  3851. begin
  3852. {$ifdef llvm}
  3853. def_system_macro('CPULLVM');
  3854. {$endif}
  3855. for cputype:=low(tcputype) to high(tcputype) do
  3856. undef_system_macro('CPU'+Cputypestr[cputype]);
  3857. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3858. for fputype:=low(tfputype) to high(tfputype) do
  3859. undef_system_macro('FPU'+fputypestr[fputype]);
  3860. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3861. {$PUSH}
  3862. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3863. if ControllerSupport then
  3864. begin
  3865. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3866. begin
  3867. s:=embedded_controllers[controller].controllertypestr;
  3868. if s<>'' then
  3869. undef_system_macro('FPC_MCU_'+s);
  3870. end;
  3871. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3872. if s<>'' then
  3873. def_system_macro('FPC_MCU_'+s);
  3874. end;
  3875. {$POP}
  3876. { define abi }
  3877. for abi:=low(tabi) to high(tabi) do
  3878. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3879. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3880. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3881. systems since most code needs to behave the same on both}
  3882. if target_info.abi = abi_eabihf then
  3883. def_system_macro('FPC_ABI_EABI');
  3884. { using a case is pretty useless here (FK) }
  3885. { some stuff for TP compatibility }
  3886. {$ifdef i386}
  3887. def_system_macro('CPU86');
  3888. def_system_macro('CPU87');
  3889. def_system_macro('CPU386');
  3890. {$endif}
  3891. { new processor stuff }
  3892. {$ifdef i386}
  3893. def_system_macro('CPUI386');
  3894. def_system_macro('CPU32');
  3895. def_system_macro('CPUX86');
  3896. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3897. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3898. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3899. {$endif}
  3900. {$ifdef m68k}
  3901. def_system_macro('CPU68');
  3902. def_system_macro('CPU68K');
  3903. def_system_macro('CPUM68K');
  3904. def_system_macro('CPU32');
  3905. def_system_macro('FPC_CURRENCY_IS_INT64');
  3906. def_system_macro('FPC_COMP_IS_INT64');
  3907. {$endif}
  3908. {$ifdef powerpc}
  3909. def_system_macro('CPUPOWERPC');
  3910. def_system_macro('CPUPOWERPC32');
  3911. def_system_macro('CPU32');
  3912. def_system_macro('FPC_CURRENCY_IS_INT64');
  3913. def_system_macro('FPC_COMP_IS_INT64');
  3914. {$endif}
  3915. {$ifdef POWERPC64}
  3916. def_system_macro('CPUPOWERPC');
  3917. def_system_macro('CPUPOWERPC64');
  3918. def_system_macro('CPU64');
  3919. def_system_macro('FPC_CURRENCY_IS_INT64');
  3920. def_system_macro('FPC_COMP_IS_INT64');
  3921. {$endif}
  3922. {$ifdef x86_64}
  3923. def_system_macro('CPUX86_64');
  3924. def_system_macro('CPUAMD64');
  3925. def_system_macro('CPU64');
  3926. def_system_macro('CPUX64');
  3927. { not supported for now, afaik (FK)
  3928. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3929. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3930. { normally, win64 doesn't support the legacy fpu }
  3931. if target_info.system=system_x86_64_win64 then
  3932. begin
  3933. def_system_macro('FPC_CURRENCY_IS_INT64');
  3934. def_system_macro('FPC_COMP_IS_INT64');
  3935. end;
  3936. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3937. {$endif}
  3938. {$ifdef sparc}
  3939. def_system_macro('CPUSPARCGEN');
  3940. def_system_macro('CPUSPARC');
  3941. def_system_macro('CPUSPARC32');
  3942. def_system_macro('CPU32');
  3943. def_system_macro('FPC_CURRENCY_IS_INT64');
  3944. def_system_macro('FPC_COMP_IS_INT64');
  3945. {$endif}
  3946. {$ifdef sparc64}
  3947. def_system_macro('CPUSPARCGEN');
  3948. def_system_macro('CPUSPARC64');
  3949. def_system_macro('CPU64');
  3950. def_system_macro('FPC_CURRENCY_IS_INT64');
  3951. def_system_macro('FPC_COMP_IS_INT64');
  3952. {$endif}
  3953. {$ifdef arm}
  3954. def_system_macro('CPUARM');
  3955. def_system_macro('CPU32');
  3956. def_system_macro('FPC_CURRENCY_IS_INT64');
  3957. def_system_macro('FPC_COMP_IS_INT64');
  3958. {$endif arm}
  3959. {$ifdef avr}
  3960. def_system_macro('CPUAVR');
  3961. def_system_macro('CPU16');
  3962. def_system_macro('FPC_CURRENCY_IS_INT64');
  3963. def_system_macro('FPC_COMP_IS_INT64');
  3964. {$endif avr}
  3965. {$ifdef jvm}
  3966. def_system_macro('CPUJVM');
  3967. def_system_macro('CPU32');
  3968. def_system_macro('FPC_CURRENCY_IS_INT64');
  3969. def_system_macro('FPC_COMP_IS_INT64');
  3970. {$endif jvm}
  3971. {$ifdef mipsel}
  3972. def_system_macro('CPUMIPS');
  3973. def_system_macro('CPUMIPS32');
  3974. def_system_macro('CPUMIPSEL');
  3975. def_system_macro('CPUMIPSEL32');
  3976. def_system_macro('CPU32');
  3977. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3978. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3979. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3980. def_system_macro('FPC_CURRENCY_IS_INT64');
  3981. def_system_macro('FPC_COMP_IS_INT64');
  3982. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3983. { On most systems, locals are accessed relative to base pointer,
  3984. but for MIPS cpu, they are accessed relative to stack pointer.
  3985. This needs adaptation for so low level routines,
  3986. like MethodPointerLocal and related objects unit functions. }
  3987. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3988. {$endif mipsel}
  3989. {$ifdef mipseb}
  3990. def_system_macro('CPUMIPS');
  3991. def_system_macro('CPUMIPS32');
  3992. def_system_macro('CPUMIPSEB');
  3993. def_system_macro('CPUMIPSEB32');
  3994. def_system_macro('CPU32');
  3995. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3996. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3997. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3998. def_system_macro('FPC_CURRENCY_IS_INT64');
  3999. def_system_macro('FPC_COMP_IS_INT64');
  4000. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4001. { See comment above for mipsel }
  4002. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4003. {$endif}
  4004. {$ifdef i8086}
  4005. def_system_macro('CPU86'); { Borland compatibility }
  4006. def_system_macro('CPU87'); { Borland compatibility }
  4007. def_system_macro('CPUI8086');
  4008. def_system_macro('CPU16');
  4009. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4010. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4011. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4012. case init_settings.x86memorymodel of
  4013. mm_tiny: def_system_macro('FPC_MM_TINY');
  4014. mm_small: def_system_macro('FPC_MM_SMALL');
  4015. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  4016. mm_compact: def_system_macro('FPC_MM_COMPACT');
  4017. mm_large: def_system_macro('FPC_MM_LARGE');
  4018. mm_huge: def_system_macro('FPC_MM_HUGE');
  4019. end;
  4020. {$endif i8086}
  4021. {$ifdef aarch64}
  4022. def_system_macro('CPUAARCH64');
  4023. def_system_macro('CPU64');
  4024. def_system_macro('FPC_CURRENCY_IS_INT64');
  4025. def_system_macro('FPC_COMP_IS_INT64');
  4026. {$endif aarch64}
  4027. {$ifdef riscv32}
  4028. def_system_macro('CPURISCV');
  4029. def_system_macro('CPURISCV32');
  4030. def_system_macro('CPU32');
  4031. def_system_macro('FPC_CURRENCY_IS_INT64');
  4032. def_system_macro('FPC_COMP_IS_INT64');
  4033. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4034. {$endif riscv32}
  4035. {$ifdef riscv64}
  4036. def_system_macro('CPURISCV');
  4037. def_system_macro('CPURISCV64');
  4038. def_system_macro('CPU64');
  4039. def_system_macro('FPC_CURRENCY_IS_INT64');
  4040. def_system_macro('FPC_COMP_IS_INT64');
  4041. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4042. {$endif riscv64}
  4043. {$ifdef xtensa}
  4044. def_system_macro('CPUXTENSA');
  4045. def_system_macro('CPU32');
  4046. def_system_macro('FPC_CURRENCY_IS_INT64');
  4047. def_system_macro('FPC_COMP_IS_INT64');
  4048. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4049. {$endif xtensa}
  4050. {$ifdef z80}
  4051. def_system_macro('CPUZ80');
  4052. def_system_macro('CPU16');
  4053. def_system_macro('FPC_CURRENCY_IS_INT64');
  4054. def_system_macro('FPC_COMP_IS_INT64');
  4055. {$endif z80}
  4056. {$ifdef wasm32}
  4057. def_system_macro('CPUWASM');
  4058. def_system_macro('CPUWASM32');
  4059. def_system_macro('CPU32');
  4060. def_system_macro('FPC_CURRENCY_IS_INT64');
  4061. def_system_macro('FPC_COMP_IS_INT64');
  4062. {$endif wasm32}
  4063. {$if defined(cpu8bitalu)}
  4064. def_system_macro('CPUINT8');
  4065. {$elseif defined(cpu16bitalu)}
  4066. def_system_macro('CPUINT16');
  4067. {$elseif defined(cpu32bitalu)}
  4068. def_system_macro('CPUINT32');
  4069. {$elseif defined(cpu64bitalu)}
  4070. def_system_macro('CPUINT64');
  4071. {$endif defined(cpu64bitalu)}
  4072. {$if defined(avr)}
  4073. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  4074. {$endif}
  4075. {$if defined(i8086) or defined(avr)}
  4076. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  4077. {$endif i8086 or avr}
  4078. { abs(long) is handled internally on all CPUs }
  4079. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  4080. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  4081. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  4082. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  4083. def_system_macro('FPC_HAS_UNICODESTRING');
  4084. def_system_macro('FPC_RTTI_PACKSET1');
  4085. def_system_macro('FPC_HAS_CPSTRING');
  4086. {$ifdef x86_64}
  4087. def_system_macro('FPC_HAS_RIP_RELATIVE');
  4088. {$endif x86_64}
  4089. def_system_macro('FPC_HAS_CEXTENDED');
  4090. def_system_macro('FPC_HAS_RESSTRINITS');
  4091. { these cpus have an inline rol/ror implementaion }
  4092. {$ifdef cpurox}
  4093. {$ifdef m68k}
  4094. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  4095. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4096. {$else}
  4097. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4098. {$endif}
  4099. {$endif}
  4100. {$ifdef powerpc64}
  4101. def_system_macro('FPC_HAS_LWSYNC');
  4102. {$endif}
  4103. { currently, all supported CPUs have an internal sar implementation }
  4104. def_system_macro('FPC_HAS_INTERNAL_SAR');
  4105. {$ifdef SUPPORT_GET_FRAME}
  4106. def_system_macro('INTERNAL_BACKTRACE');
  4107. {$endif SUPPORT_GET_FRAME}
  4108. def_system_macro('STR_CONCAT_PROCS');
  4109. {$warnings off}
  4110. if pocall_default = pocall_register then
  4111. def_system_macro('REGCALL');
  4112. {$warnings on}
  4113. end;
  4114. var
  4115. env: ansistring;
  4116. i : tfeature;
  4117. j : longint;
  4118. tmplist : TCmdStrList;
  4119. cmditem,
  4120. tmpcmditem : TCmdStrListItem;
  4121. cmdstr : TCmdStr;
  4122. {$if defined(cpucapabilities)}
  4123. cpuflag : tcpuflags;
  4124. {$endif defined(cpucapabilities)}
  4125. {$if defined(fpucapabilities)}
  4126. fpuflag : tfpuflags;
  4127. {$endif defined(fpucapabilities)}
  4128. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  4129. hs : string;
  4130. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  4131. begin
  4132. option:=coption.create;
  4133. disable_configfile:=false;
  4134. { Non-core target defines }
  4135. Option.TargetOptions(true);
  4136. { get default messagefile }
  4137. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  4138. { default configfile can be specified on the commandline,
  4139. remove it first }
  4140. if (cmd<>'') and (cmd[1]='[') then
  4141. begin
  4142. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  4143. Delete(cmd,1,pos(']',cmd));
  4144. end
  4145. else
  4146. ppccfg:='fpc.cfg';
  4147. { first pass reading of parameters, only -i -v -T etc.}
  4148. option.firstpass:=true;
  4149. if cmd<>'' then
  4150. option.parsecmd(cmd)
  4151. else
  4152. begin
  4153. option.read_parameters;
  4154. { Write only quickinfo }
  4155. if option.quickinfo<>'' then
  4156. option.writequickinfo;
  4157. end;
  4158. option.firstpass:=false;
  4159. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  4160. Option.TargetOptions(true);
  4161. { target is set here, for wince the default app type is gui }
  4162. if target_info.system in systems_wince then
  4163. SetApptype(app_gui)
  4164. else
  4165. SetApptype(apptype);
  4166. { default defines }
  4167. def_system_macro(target_info.shortname);
  4168. def_system_macro('FPC');
  4169. def_system_macro('VER'+version_nr);
  4170. def_system_macro('VER'+version_nr+'_'+release_nr);
  4171. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  4172. { Temporary defines, until things settle down }
  4173. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  4174. def_system_macro('FPC_HAS_CONSTREF');
  4175. def_system_macro('FPC_STATICRIPFIXED');
  4176. def_system_macro('FPC_VARIANTCOPY_FIXED');
  4177. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  4178. def_system_macro('FPC_HAS_MEMBAR');
  4179. def_system_macro('FPC_SETBASE_USED');
  4180. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  4181. { don't remove this, it's also for fpdoc necessary (FK) }
  4182. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  4183. { make cpu makros available when reading the config files the second time }
  4184. def_cpu_macros;
  4185. if tf_cld in target_info.flags then
  4186. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  4187. InternalError(2013092801);
  4188. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  4189. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  4190. InternalError(2013092802);
  4191. { Use standard Android NDK prefixes when cross-compiling }
  4192. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  4193. case target_info.system of
  4194. system_arm_android:
  4195. utilsprefix:='arm-linux-androideabi-';
  4196. system_i386_android:
  4197. utilsprefix:='i686-linux-android-';
  4198. else
  4199. utilsprefix:=target_cpu_string + '-linux-android-';
  4200. end;
  4201. { Set up default value for the heap on Amiga-likes (values only apply if the OSHeap allocator is used) }
  4202. if target_info.system in systems_amigalike then
  4203. begin
  4204. case target_info.system of
  4205. system_m68k_amiga:
  4206. heapsize:=256*1024;
  4207. system_powerpc_amiga,
  4208. system_powerpc_morphos,
  4209. system_arm_aros,
  4210. system_i386_aros,
  4211. system_x86_64_aros:
  4212. heapsize:=1024*1024;
  4213. else
  4214. heapsize:=256*1024;
  4215. end;
  4216. end;
  4217. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  4218. begin
  4219. case target_info.system of
  4220. {$ifdef AVR}
  4221. system_avr_embedded:
  4222. if init_settings.controllertype=ct_avrsim then
  4223. heapsize:=8192
  4224. else
  4225. heapsize:=128;
  4226. {$endif AVR}
  4227. system_arm_freertos:
  4228. heapsize:=8192;
  4229. system_xtensa_freertos:
  4230. { keep default value }
  4231. ;
  4232. system_arm_embedded:
  4233. heapsize:=256;
  4234. system_mipsel_embedded:
  4235. heapsize:=256;
  4236. else
  4237. heapsize:=256;
  4238. end;
  4239. end;
  4240. { read configuration file }
  4241. if (not disable_configfile) and
  4242. (ppccfg<>'') then
  4243. read_configfile:=check_configfile(ppccfg,ppccfg)
  4244. else
  4245. read_configfile := false;
  4246. { Read commandline and configfile }
  4247. param_file:='';
  4248. { read configfile }
  4249. if read_configfile then
  4250. option.interpret_file(ppccfg);
  4251. { read parameters again to override config file }
  4252. if cmd<>'' then
  4253. option.parsecmd(cmd)
  4254. else
  4255. begin
  4256. { Write help pages if no parameters are passed }
  4257. if (paramcount=0) then
  4258. Option.WriteHelpPages;
  4259. option.read_parameters;
  4260. { Write only quickinfo }
  4261. if option.quickinfo<>'' then
  4262. option.writequickinfo;
  4263. end;
  4264. { check the compatibility of different options and adjust them if necessary
  4265. (and print possible errors)
  4266. }
  4267. option.checkoptionscompatibility;
  4268. { uses the CPUXXX-defines and target_info to determine whether the selected
  4269. target processor, if any, is supported }
  4270. Option.VerifyTargetProcessor;
  4271. { Stop if errors in options }
  4272. if ErrorCount>0 then
  4273. StopOptions(1);
  4274. { endian define }
  4275. case target_info.endian of
  4276. endian_little :
  4277. begin
  4278. def_system_macro('ENDIAN_LITTLE');
  4279. def_system_macro('FPC_LITTLE_ENDIAN');
  4280. end;
  4281. endian_big :
  4282. begin
  4283. def_system_macro('ENDIAN_BIG');
  4284. def_system_macro('FPC_BIG_ENDIAN');
  4285. end;
  4286. end;
  4287. { Write logo }
  4288. if option.ParaLogo then
  4289. option.writelogo;
  4290. { Check file to compile }
  4291. if param_file='' then
  4292. begin
  4293. Message(option_no_source_found);
  4294. StopOptions(1);
  4295. end;
  4296. {$ifndef Unix}
  4297. param_file:=FixFileName(param_file);
  4298. {$endif not unix}
  4299. inputfilepath:=ExtractFilePath(param_file);
  4300. inputfilename:=ExtractFileName(param_file);
  4301. if ExtractFileExt(inputfilename)='' then
  4302. begin
  4303. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  4304. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  4305. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  4306. inputfilename:=ChangeFileExt(inputfilename,pasext)
  4307. else if ((m_mac in current_settings.modeswitches) or
  4308. (tf_p_ext_support in target_info.flags))
  4309. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  4310. inputfilename:=ChangeFileExt(inputfilename,pext);
  4311. end;
  4312. { Check output dir }
  4313. if (OutputExeDir<>'') and
  4314. not PathExists(OutputExeDir,false) then
  4315. begin
  4316. Message1(general_e_path_does_not_exist,OutputExeDir);
  4317. StopOptions(1);
  4318. end;
  4319. { Add paths specified with parameters to the searchpaths }
  4320. UnitSearchPath.AddList(option.ParaUnitPath,true);
  4321. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  4322. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  4323. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  4324. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  4325. packagesearchpath.addlist(option.parapackagepath,true);
  4326. for j:=0 to option.parapackages.count-1 do
  4327. add_package(option.parapackages.NameOfIndex(j),true,true);
  4328. { add default namespaces }
  4329. tmplist:=TCmdStrList.Create;
  4330. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  4331. while assigned(cmditem) do
  4332. begin
  4333. { use a temporary list cause if ";" are involved we need to reverse the
  4334. order due to how TCmdStrList behaves }
  4335. cmdstr:=cmditem.str;
  4336. repeat
  4337. j:=Pos(';',cmdstr);
  4338. if j>0 then
  4339. begin
  4340. tmplist.insert(copy(cmdstr,1,j-1));
  4341. delete(cmdstr,1,j);
  4342. end
  4343. else
  4344. tmplist.insert(cmdstr);
  4345. until j=0;
  4346. tmpcmditem:=TCmdStrListItem(tmplist.First);
  4347. while assigned(tmpcmditem) do
  4348. begin
  4349. namespacelist.insert(tmpcmditem.Str);
  4350. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  4351. end;
  4352. tmplist.clear;
  4353. cmditem:=TCmdStrListItem(cmditem.Next);
  4354. end;
  4355. tmplist.Free;
  4356. { add unit environment and exepath to the unit search path }
  4357. if inputfilepath<>'' then
  4358. Unitsearchpath.AddPath(inputfilepath,true);
  4359. if not disable_configfile then
  4360. begin
  4361. env:=GetEnvironmentVariable(target_info.unit_env);
  4362. if env<>'' then
  4363. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  4364. end;
  4365. {$ifdef Unix}
  4366. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4367. if fpcdir='' then
  4368. begin
  4369. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  4370. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  4371. else
  4372. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  4373. end;
  4374. {$else unix}
  4375. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4376. if fpcdir='' then
  4377. begin
  4378. fpcdir:=ExePath+'../';
  4379. if not(PathExists(fpcdir+'units',true)) and
  4380. not(PathExists(fpcdir+'rtl',true)) then
  4381. fpcdir:=fpcdir+'../';
  4382. end;
  4383. {$endif unix}
  4384. { first try development RTL, else use the default installation path }
  4385. if not disable_configfile then
  4386. begin
  4387. if PathExists(FpcDir+'rtl',true) then
  4388. if (tf_use_8_3 in Source_Info.Flags) or
  4389. (tf_use_8_3 in Target_Info.Flags) then
  4390. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4391. else
  4392. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4393. else
  4394. if (tf_use_8_3 in Source_Info.Flags) or
  4395. (tf_use_8_3 in Target_Info.Flags) then
  4396. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4397. else
  4398. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4399. end;
  4400. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4401. Do not add it when linking on the target because then we can maybe already find
  4402. .o files that are not for the target }
  4403. if (ExePath<>cfileutl.GetCurrentDir) and
  4404. not(cs_link_on_target in init_settings.globalswitches) then
  4405. UnitSearchPath.AddPath(ExePath,false);
  4406. { Add unit dir to the object and library path }
  4407. objectsearchpath.AddList(unitsearchpath,false);
  4408. librarysearchpath.AddList(unitsearchpath,false);
  4409. {$ifdef llvm}
  4410. { default to clang }
  4411. if (option.paratargetasm=as_none) then
  4412. begin
  4413. option.paratargetasm:=as_clang_llvm;
  4414. end;
  4415. {$endif llvm}
  4416. { maybe override assembler }
  4417. if (option.paratargetasm<>as_none) then
  4418. begin
  4419. if (option.paratargetasm=as_default) then
  4420. begin
  4421. option.paratargetasm:=target_info.assem;
  4422. end;
  4423. if not set_target_asm(option.paratargetasm) then
  4424. begin
  4425. if assigned(asminfos[option.paratargetasm]) then
  4426. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4427. else
  4428. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4429. set_target_asm(target_info.assemextern);
  4430. Message1(option_asm_forced,target_asm.idtxt);
  4431. end;
  4432. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4433. (option.paratargetdbg<>dbg_none) then
  4434. begin
  4435. Message1(option_confict_asm_debug,
  4436. asminfos[option.paratargetasm]^.idtxt);
  4437. option.paratargetdbg:=dbg_none;
  4438. exclude(init_settings.moduleswitches,cs_debuginfo);
  4439. end;
  4440. { Some assemblers, like clang, do not support
  4441. stabs debugging format, switch to dwardé in that case }
  4442. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4443. (option.paratargetdbg=dbg_stabs) then
  4444. begin
  4445. option.paratargetdbg:=dbg_dwarf2;
  4446. end;
  4447. end;
  4448. {TOptionheck a second time as we might have changed assembler just above }
  4449. option.checkoptionscompatibility;
  4450. { maybe override debug info format }
  4451. if (option.paratargetdbg<>dbg_none) then
  4452. if not set_target_dbg(option.paratargetdbg) then
  4453. Message(option_w_unsupported_debug_format);
  4454. { switch assembler if it's binary and we got -a on the cmdline }
  4455. if (af_outputbinary in target_asm.flags) and
  4456. ((cs_asm_leave in init_settings.globalswitches) or
  4457. { if -s is passed, we shouldn't call the internal assembler }
  4458. (cs_asm_extern in init_settings.globalswitches)) then
  4459. begin
  4460. Message(option_switch_bin_to_src_assembler);
  4461. {$ifdef llvm}
  4462. set_target_asm(as_clang_llvm);
  4463. {$else}
  4464. set_target_asm(target_info.assemextern);
  4465. {$endif}
  4466. { At least i8086 needs that for nasm and -CX
  4467. which is incompatible with internal linker }
  4468. option.checkoptionscompatibility;
  4469. end;
  4470. { Force use of external linker if there is no
  4471. internal linker or the linking is skipped }
  4472. if not(cs_link_extern in init_settings.globalswitches) and
  4473. ((target_info.link=ld_none) or
  4474. (cs_link_nolink in init_settings.globalswitches)) then
  4475. begin
  4476. include(init_settings.globalswitches,cs_link_extern);
  4477. end;
  4478. { turn off stripping if compiling with debuginfo or profile }
  4479. if (
  4480. (cs_debuginfo in init_settings.moduleswitches) or
  4481. (cs_profile in init_settings.moduleswitches)
  4482. ) and
  4483. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4484. exclude(init_settings.globalswitches,cs_link_strip);
  4485. { choose a reasonable tls model }
  4486. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4487. begin
  4488. if cs_create_pic in init_settings.moduleswitches then
  4489. init_settings.tlsmodel:=tlsm_global_dynamic
  4490. else
  4491. init_settings.tlsmodel:=tlsm_local_exec;
  4492. end;
  4493. { set Mac OS X version default macros if not specified explicitly }
  4494. option.MaybeSetDefaultMacVersionMacro;
  4495. {$ifdef XTENSA}
  4496. { set ESP32 or ESP8266 default SDK versions }
  4497. option.MaybeSetIdfVersionMacro;
  4498. {$endif XTENSA}
  4499. {$ifdef cpufpemu}
  4500. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4501. if fpu type not explicitly set }
  4502. if not(option.FPUSetExplicitly) and
  4503. ((target_info.system in [system_arm_wince,system_arm_gba,
  4504. system_m68k_amiga,system_m68k_atari,
  4505. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4506. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4507. system_z80_embedded,system_z80_zxspectrum])
  4508. {$ifdef arm}
  4509. or (target_info.abi=abi_eabi)
  4510. {$endif arm}
  4511. )
  4512. or (init_settings.fputype=fpu_soft)
  4513. then
  4514. begin
  4515. include(init_settings.moduleswitches,cs_fp_emulation);
  4516. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4517. init_settings.fputype:=fpu_soft;
  4518. end;
  4519. {$endif cpufpemu}
  4520. {$ifdef i386}
  4521. if target_info.system in systems_i386_default_486 then
  4522. begin
  4523. { Avoid use of MMX/CMOVcc instructions on older systems.
  4524. Some systems might not handle these instructions correctly,
  4525. Used emulators might also be problematic. PM }
  4526. if not option.CPUSetExplicitly then
  4527. init_settings.cputype:=cpu_486;
  4528. end;
  4529. case target_info.system of
  4530. system_i386_android:
  4531. begin
  4532. { set default cpu type to PentiumM for Android unless specified otherwise }
  4533. if not option.CPUSetExplicitly then
  4534. init_settings.cputype:=cpu_PentiumM;
  4535. if not option.OptCPUSetExplicitly then
  4536. init_settings.optimizecputype:=cpu_PentiumM;
  4537. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4538. if not option.FPUSetExplicitly then
  4539. init_settings.fputype:=fpu_ssse3;
  4540. end;
  4541. else
  4542. ;
  4543. end;
  4544. {$endif i386}
  4545. {$ifdef xtensa}
  4546. { xtensa-linux target does not support controller setting option -Wp }
  4547. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4548. begin
  4549. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4550. if (init_settings.fputype=fpu_soft) then
  4551. include(init_settings.moduleswitches,cs_fp_emulation);
  4552. end;
  4553. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4554. init_settings.cputype:=cpu_lx6;
  4555. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4556. begin
  4557. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4558. target_info.abi:=abi_xtensa_windowed
  4559. else
  4560. target_info.abi:=abi_xtensa_call0;
  4561. end;
  4562. {$endif xtensa}
  4563. {$ifdef arm}
  4564. case target_info.system of
  4565. system_arm_ios:
  4566. begin
  4567. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4568. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4569. }
  4570. if not option.CPUSetExplicitly then
  4571. init_settings.cputype:=cpu_armv7;
  4572. if not option.OptCPUSetExplicitly then
  4573. init_settings.optimizecputype:=cpu_armv7;
  4574. if not option.FPUSetExplicitly then
  4575. init_settings.fputype:=fpu_vfpv3;
  4576. end;
  4577. system_arm_android:
  4578. begin
  4579. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4580. if not option.CPUSetExplicitly then
  4581. init_settings.cputype:=cpu_armv5t;
  4582. if not option.OptCPUSetExplicitly then
  4583. init_settings.optimizecputype:=cpu_armv5t;
  4584. end;
  4585. else
  4586. ;
  4587. end;
  4588. { set ABI defaults }
  4589. case target_info.abi of
  4590. abi_eabihf:
  4591. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4592. begin
  4593. {$ifdef CPUARMV6}
  4594. { if the compiler is built for armv6, then
  4595. inherit this setting, e.g. Raspian is armhf but
  4596. only armv6, this makes rebuilds of the compiler
  4597. easier }
  4598. if not option.CPUSetExplicitly then
  4599. init_settings.cputype:=cpu_armv6;
  4600. if not option.OptCPUSetExplicitly then
  4601. init_settings.optimizecputype:=cpu_armv6;
  4602. {$else CPUARMV6}
  4603. if not option.CPUSetExplicitly then
  4604. init_settings.cputype:=cpu_armv7a;
  4605. if not option.OptCPUSetExplicitly then
  4606. init_settings.optimizecputype:=cpu_armv7a;
  4607. {$endif CPUARMV6}
  4608. { Set FPU type }
  4609. if not(option.FPUSetExplicitly) then
  4610. begin
  4611. if init_settings.cputype < cpu_armv7 then
  4612. init_settings.fputype:=fpu_vfpv2
  4613. else
  4614. init_settings.fputype:=fpu_vfpv3_d16;
  4615. end
  4616. else
  4617. begin
  4618. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4619. or (target_info.system = system_arm_ios) then
  4620. begin
  4621. Message(option_illegal_fpu_eabihf);
  4622. StopOptions(1);
  4623. end;
  4624. end;
  4625. end;
  4626. abi_eabi:
  4627. begin
  4628. if target_info.system=system_arm_linux then
  4629. begin
  4630. { this is what Debian uses }
  4631. if not option.CPUSetExplicitly then
  4632. init_settings.cputype:=cpu_armv4t;
  4633. if not option.OptCPUSetExplicitly then
  4634. init_settings.optimizecputype:=cpu_armv4t;
  4635. if not(option.FPUSetExplicitly) then
  4636. init_settings.fputype:=fpu_soft;
  4637. end;
  4638. end;
  4639. else
  4640. ;
  4641. end;
  4642. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4643. begin
  4644. def_system_macro('CPUTHUMB');
  4645. if not option.FPUSetExplicitly then
  4646. init_settings.fputype:=fpu_soft;
  4647. if not(init_settings.fputype in [fpu_none,fpu_soft,fpu_libgcc]) then
  4648. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],'Thumb');
  4649. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4650. 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';
  4651. {$else FPC_ARMAL or FPC_ARMHF}
  4652. if target_info.endian=endian_little then
  4653. 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';
  4654. {$endif FPC_ARMAL or FPC_ARMHF}
  4655. end;
  4656. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4657. def_system_macro('CPUTHUMB2');
  4658. {$endif arm}
  4659. {$ifdef aarch64}
  4660. case target_info.system of
  4661. system_aarch64_darwin:
  4662. begin
  4663. if not option.CPUSetExplicitly then
  4664. init_settings.cputype:=cpu_armv84a;
  4665. if not option.OptCPUSetExplicitly then
  4666. init_settings.optimizecputype:=cpu_armv84a;
  4667. end;
  4668. else
  4669. ;
  4670. end;
  4671. {$endif aarch64}
  4672. {$if defined(riscv32) or defined(riscv64)}
  4673. { RISC-V defaults }
  4674. if (target_info.abi = abi_riscv_hf) then
  4675. begin
  4676. {$ifdef riscv32}
  4677. if not option.CPUSetExplicitly then
  4678. init_settings.cputype:=cpu_rv32ima;
  4679. if not option.OptCPUSetExplicitly then
  4680. init_settings.optimizecputype:=cpu_rv32ima;
  4681. {$else}
  4682. if not option.CPUSetExplicitly then
  4683. init_settings.cputype:=cpu_rv64imac;
  4684. if not option.OptCPUSetExplicitly then
  4685. init_settings.optimizecputype:=cpu_rv64imac;
  4686. {$endif}
  4687. { Set FPU type }
  4688. if not(option.FPUSetExplicitly) then
  4689. init_settings.fputype:=fpu_fd
  4690. else
  4691. begin
  4692. if not (init_settings.fputype in [fpu_fd]) then
  4693. begin
  4694. Message(option_illegal_fpu_eabihf);
  4695. StopOptions(1);
  4696. end;
  4697. end;
  4698. end;
  4699. {$endif defined(riscv32) or defined(riscv64)}
  4700. {$ifdef jvm}
  4701. { set default CPU type to Dalvik when targeting Android }
  4702. if target_info.system=system_jvm_android32 then
  4703. begin
  4704. if not option.CPUSetExplicitly then
  4705. init_settings.cputype:=cpu_dalvik;
  4706. end;
  4707. {$endif jvm}
  4708. {$ifdef llvm}
  4709. { standard extension for llvm bitcode files }
  4710. target_info.asmext:='.ll';
  4711. { don't generate dwarf cfi, llvm will do that }
  4712. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4713. {$endif llvm}
  4714. {$ifdef mipsel}
  4715. case target_info.system of
  4716. system_mipsel_android:
  4717. begin
  4718. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4719. if not option.CPUSetExplicitly then
  4720. init_settings.cputype:=cpu_mips32;
  4721. if not option.OptCPUSetExplicitly then
  4722. init_settings.optimizecputype:=cpu_mips32;
  4723. if not option.FPUSetExplicitly then
  4724. init_settings.fputype:=fpu_mips2;
  4725. end;
  4726. system_mipsel_embedded:
  4727. begin
  4728. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4729. if not option.CPUSetExplicitly then
  4730. init_settings.cputype:=cpu_pic32mx;
  4731. if not option.OptCPUSetExplicitly then
  4732. init_settings.optimizecputype:=cpu_pic32mx;
  4733. if not option.FPUSetExplicitly then
  4734. init_settings.fputype:=fpu_soft;
  4735. end;
  4736. else
  4737. ;
  4738. end;
  4739. {$endif mipsel}
  4740. {$ifdef m68k}
  4741. if init_settings.cputype in cpu_coldfire then
  4742. def_system_macro('CPUCOLDFIRE');
  4743. case target_info.system of
  4744. system_m68k_linux,
  4745. system_m68k_netbsd:
  4746. begin
  4747. if not (option.FPUSetExplicitly) and
  4748. not (init_settings.cputype in cpu_coldfire) then
  4749. begin
  4750. { enable HW FPU for UNIX by default, but only for
  4751. original 68k, not Coldfire }
  4752. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4753. init_settings.fputype:=fpu_68881;
  4754. end;
  4755. end;
  4756. system_m68k_sinclairql:
  4757. begin
  4758. if not option.CPUSetExplicitly then
  4759. init_settings.cputype:=cpu_mc68000;
  4760. end;
  4761. system_m68k_palmos:
  4762. begin
  4763. if not option.CPUSetExplicitly then
  4764. init_settings.cputype:=cpu_mc68000;
  4765. if not (option.FPUSetExplicitly) then
  4766. begin
  4767. { No FPU for PalmOS by default }
  4768. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4769. init_settings.fputype:=fpu_none;
  4770. end;
  4771. end;
  4772. else
  4773. ;
  4774. end;
  4775. {$endif m68k}
  4776. {$ifdef wasm}
  4777. { if no explicit exception handling mode is set for WebAssembly, assume no exceptions }
  4778. if init_settings.targetswitches*[ts_wasm_no_exceptions,ts_wasm_js_exceptions,ts_wasm_native_exceptions,ts_wasm_bf_exceptions]=[] then
  4779. begin
  4780. def_system_macro(TargetSwitchStr[ts_wasm_no_exceptions].define);
  4781. include(init_settings.targetswitches,ts_wasm_no_exceptions);
  4782. end;
  4783. {$endif wasm}
  4784. { now we can define cpu and fpu type }
  4785. def_cpu_macros;
  4786. { Use init_settings cpu type for asm cpu type,
  4787. if asmcputype is cpu_none,
  4788. at least as long as there is no explicit
  4789. option to set it on command line PM }
  4790. if init_settings.asmcputype = cpu_none then
  4791. init_settings.asmcputype:=init_settings.cputype;
  4792. {$ifdef llvm}
  4793. def_system_macro('CPULLVM');
  4794. {$endif llvm}
  4795. {$if defined(cpucapabilities)}
  4796. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4797. begin
  4798. str(cpuflag,hs);
  4799. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4800. def_system_macro(hs)
  4801. else
  4802. undef_system_macro(hs);
  4803. end;
  4804. {$endif defined(cpucapabilities)}
  4805. {$if defined(fpucapabilities)}
  4806. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4807. begin
  4808. str(fpuflag,hs);
  4809. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4810. def_system_macro(hs)
  4811. else
  4812. undef_system_macro(hs);
  4813. end;
  4814. {$endif defined(fpucapabilities)}
  4815. if init_settings.fputype<>fpu_none then
  4816. begin
  4817. {$if defined(i386) or defined(i8086)}
  4818. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4819. {$endif}
  4820. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4821. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4822. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4823. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4824. {$endif}
  4825. {$if defined(m68k)}
  4826. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4827. {$endif}
  4828. {$ifdef x86_64}
  4829. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4830. { normally, win64 doesn't support the legacy fpu }
  4831. if target_info.system=system_x86_64_win64 then
  4832. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4833. else
  4834. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4835. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4836. {$endif}
  4837. end;
  4838. { Enable now for testing }
  4839. {$ifndef DISABLE_TLS_DIRECTORY}
  4840. if target_info.system in systems_windows then
  4841. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4842. {$endif not DISABLE_TLS_DIRECTORY}
  4843. {$ifndef DISABLE_WIN64_SEH}
  4844. if target_info.system=system_x86_64_win64 then
  4845. def_system_macro('FPC_USE_WIN64_SEH');
  4846. {$endif DISABLE_WIN64_SEH}
  4847. {$ifndef DISABLE_WIN32_SEH}
  4848. if target_info.system=system_i386_win32 then
  4849. def_system_macro('FPC_USE_WIN32_SEH');
  4850. {$endif not DISABLE_WIN32_SEH}
  4851. {$ifdef ARM}
  4852. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4853. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4854. not(cs_fp_emulation in init_settings.moduleswitches) then
  4855. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4856. {$endif ARM}
  4857. { inline bsf/bsr implementation }
  4858. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4859. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4860. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4861. {$endif}
  4862. { hardware FMA support }
  4863. {$if defined(i386) or defined(x86_64)}
  4864. if (fpu_capabilities[current_settings.fputype]*[FPUX86_HAS_FMA,FPUX86_HAS_FMA4])<>[] then
  4865. begin
  4866. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4867. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4868. end;
  4869. {$endif defined(i386) or defined(x86_64)}
  4870. {$if defined(arm)}
  4871. { it is determined during system unit compilation if clz is used for bsf or not,
  4872. this is not perfect but the current implementation bsf/bsr does not allow another
  4873. solution }
  4874. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4875. ((init_settings.instructionset=is_arm) or
  4876. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4877. begin
  4878. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4879. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4880. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4881. end;
  4882. {$endif}
  4883. {$if defined(xtensa)}
  4884. { it is determined during system unit compilation if nsau is used for bsr or not,
  4885. this is not perfect but the current implementation bsf/bsr does not allow another
  4886. solution }
  4887. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  4888. begin
  4889. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4890. end;
  4891. {$endif}
  4892. {$if defined(powerpc64)}
  4893. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4894. big endian (unless specified otherwise). As the gcc man page says:
  4895. "Overriding the default ABI requires special system support and is
  4896. likely to fail in spectacular ways" }
  4897. if not option.ABISetExplicitly then
  4898. begin
  4899. if (target_info.abi=abi_powerpc_sysv) and
  4900. (target_info.endian=endian_little) then
  4901. target_info.abi:=abi_powerpc_elfv2
  4902. else
  4903. if (target_info.abi=abi_powerpc_elfv2) and
  4904. (target_info.endian=endian_big) then
  4905. target_info.abi:=abi_powerpc_sysv
  4906. end;
  4907. {$endif}
  4908. {$if defined(powerpc) or defined(powerpc64)}
  4909. { define _CALL_ELF symbol like gcc }
  4910. case target_info.abi of
  4911. abi_powerpc_sysv:
  4912. set_system_compvar('_CALL_ELF','1');
  4913. abi_powerpc_elfv2:
  4914. set_system_compvar('_CALL_ELF','2');
  4915. else
  4916. ;
  4917. end;
  4918. {$endif}
  4919. { Section smartlinking conflicts with import sections on Windows }
  4920. if GenerateImportSection and
  4921. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  4922. exclude(target_info.flags,tf_smartlink_sections);
  4923. if not option.LinkTypeSetExplicitly then
  4924. set_default_link_type;
  4925. { Default alignment settings,
  4926. 1. load the defaults for the target
  4927. 2. adapt defaults specifically for the target
  4928. 3. override with generic optimizer setting (little size)
  4929. 4. override with the user specified -Oa }
  4930. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4931. {$ifdef arm}
  4932. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4933. begin
  4934. init_settings.alignment.procalign:=2;
  4935. init_settings.alignment.jumpalign:=2;
  4936. init_settings.alignment.coalescealign:=2;
  4937. init_settings.alignment.loopalign:=2;
  4938. end;
  4939. {$endif arm}
  4940. if (cs_opt_size in init_settings.optimizerswitches) then
  4941. begin
  4942. init_settings.alignment.procalign:=1;
  4943. init_settings.alignment.jumpalign:=1;
  4944. init_settings.alignment.coalescealign:=1;
  4945. init_settings.alignment.loopalign:=1;
  4946. {$ifdef x86}
  4947. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4948. all processors except x86 are really hurt by this or might even crash }
  4949. init_settings.alignment.constalignmax:=1;
  4950. {$endif x86}
  4951. end;
  4952. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4953. set_system_macro('FPC_VERSION',version_nr);
  4954. set_system_macro('FPC_RELEASE',release_nr);
  4955. set_system_macro('FPC_PATCH',patch_nr);
  4956. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4957. if target_info.system in systems_indirect_entry_information then
  4958. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4959. if not (tf_winlikewidestring in target_info.flags) then
  4960. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4961. if tf_supports_packages in target_info.flags then
  4962. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4963. if target_info.system in systems_indirect_var_imports then
  4964. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4965. if cs_compilesystem in init_settings.moduleswitches then
  4966. for i:=low(tfeature) to high(tfeature) do
  4967. if i in features then
  4968. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4969. {$push}
  4970. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4971. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  4972. (init_settings.controllertype<>ct_none) then
  4973. begin
  4974. with embedded_controllers[init_settings.controllertype] do
  4975. begin
  4976. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4977. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4978. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4979. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4980. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4981. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4982. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4983. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4984. end;
  4985. end;
  4986. {$pop}
  4987. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4988. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4989. option.free;
  4990. Option:=nil;
  4991. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  4992. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4993. if (tf_safecall_clearstack in target_info.flags) then
  4994. begin
  4995. include (cdecl_pocalls, pocall_safecall);
  4996. include (clearstack_pocalls, pocall_safecall)
  4997. end;
  4998. end;
  4999. initialization
  5000. coption:=toption;
  5001. finalization
  5002. if assigned(option) then
  5003. option.free;
  5004. end.