options.pas 127 KB

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