options.pas 149 KB

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