options.pas 137 KB

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