options.pas 150 KB

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