options.pas 133 KB

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