options.pas 162 KB

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