options.pas 153 KB

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