options.pas 130 KB

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