options.pas 134 KB

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