options.pas 129 KB

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