options.pas 129 KB

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