options.pas 130 KB

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