options.pas 159 KB

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