options.pas 127 KB

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