options.pas 158 KB

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