options.pas 151 KB

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