options.pas 129 KB

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