options.pas 160 KB

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