options.pas 170 KB

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