options.pas 170 KB

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