options.pas 155 KB

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