options.pas 149 KB

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