options.pas 156 KB

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