options.pas 138 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140
  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. begin
  1552. if do_release then
  1553. Message(option_gc_incompatible_with_release_flag)
  1554. else
  1555. include(init_settings.localswitches,cs_checkpointer);
  1556. end
  1557. else
  1558. UnsupportedPara('-gc');
  1559. end;
  1560. 'h' :
  1561. begin
  1562. if UnsetBool(More, j, opt, false) then
  1563. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1564. else
  1565. include(init_settings.globalswitches,cs_use_heaptrc);
  1566. end;
  1567. 'l' :
  1568. begin
  1569. if UnsetBool(More, j, opt, false) then
  1570. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1571. else
  1572. include(init_settings.globalswitches,cs_use_lineinfo);
  1573. end;
  1574. 'o' :
  1575. begin
  1576. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1577. IllegalPara(opt);
  1578. break;
  1579. end;
  1580. 'p' :
  1581. begin
  1582. if UnsetBool(More, j, opt, false) then
  1583. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1584. else
  1585. include(init_settings.globalswitches,cs_stabs_preservecase);
  1586. end;
  1587. 's' :
  1588. begin
  1589. paratargetdbg:=dbg_stabs;
  1590. end;
  1591. 't' :
  1592. begin
  1593. if UnsetBool(More, j, opt, false) then
  1594. localvartrashing := -1
  1595. else
  1596. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1597. end;
  1598. 'v' :
  1599. begin
  1600. if UnsetBool(More, j, opt, false) then
  1601. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1602. else
  1603. include(init_settings.globalswitches,cs_gdb_valgrind);
  1604. end;
  1605. 'w' :
  1606. begin
  1607. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1608. begin
  1609. case more[j+1] of
  1610. '2': paratargetdbg:=dbg_dwarf2;
  1611. '3': paratargetdbg:=dbg_dwarf3;
  1612. '4': paratargetdbg:=dbg_dwarf4;
  1613. end;
  1614. inc(j);
  1615. end
  1616. else
  1617. paratargetdbg:=dbg_dwarf2;
  1618. end;
  1619. else
  1620. IllegalPara(opt);
  1621. end;
  1622. inc(j);
  1623. end;
  1624. end;
  1625. 'h' :
  1626. begin
  1627. NoPressEnter:=true;
  1628. if (More <> '') and (More [1] = 'F') then
  1629. begin
  1630. FPCHelpLines := true;
  1631. Delete (More, 1, 1);
  1632. FPCBinaryPath := More;
  1633. end;
  1634. WriteHelpPages;
  1635. end;
  1636. 'i' :
  1637. begin
  1638. if (More='') or
  1639. (More [1] in ['a', 'c', 'f', 'i', 'o', 'r', 't', 'u', 'w']) then
  1640. WriteInfo (More)
  1641. else
  1642. QuickInfo:=QuickInfo+More;
  1643. end;
  1644. 'I' :
  1645. begin
  1646. if ispara then
  1647. ParaIncludePath.AddPath(More,false)
  1648. else
  1649. includesearchpath.AddPath(More,false);
  1650. end;
  1651. 'k' :
  1652. begin
  1653. if more<>'' then
  1654. ParaLinkOptions:=ParaLinkOptions+' '+More
  1655. else
  1656. IllegalPara(opt);
  1657. end;
  1658. 'l' :
  1659. ParaLogo:=not UnSetBool(more,0,opt,true);
  1660. {$ifdef PREPROCWRITE}
  1661. 'm' :
  1662. parapreprocess:=not UnSetBool(more,0,opt,true);
  1663. {$endif PREPROCWRITE}
  1664. 'M' :
  1665. begin
  1666. more:=Upper(more);
  1667. if not SetCompileMode(more, true) then
  1668. if not SetCompileModeSwitch(more, true) then
  1669. IllegalPara(opt);
  1670. end;
  1671. 'n' :
  1672. begin
  1673. if More='' then
  1674. disable_configfile:=true
  1675. else
  1676. IllegalPara(opt);
  1677. end;
  1678. 'o' :
  1679. begin
  1680. if More<>'' then
  1681. begin
  1682. DefaultReplacements(More);
  1683. D:=ExtractFilePath(More);
  1684. if (D<>'') then
  1685. OutputExeDir:=FixPath(D,True);
  1686. OutputFileName:=ExtractFileName(More);
  1687. end
  1688. else
  1689. IllegalPara(opt);
  1690. end;
  1691. 'O' :
  1692. begin
  1693. j:=1;
  1694. while j<=length(more) do
  1695. begin
  1696. case more[j] of
  1697. '1' :
  1698. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1699. '2' :
  1700. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1701. '3' :
  1702. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1703. '4' :
  1704. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1705. 'a' :
  1706. begin
  1707. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1708. IllegalPara(opt);
  1709. break;
  1710. end;
  1711. 's' :
  1712. include(init_settings.optimizerswitches,cs_opt_size);
  1713. 'p' :
  1714. begin
  1715. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1716. begin
  1717. OptCPUSetExplicitly:=true;
  1718. { Give warning for old i386 switches }
  1719. if (Length(More)-j=1) and
  1720. (More[j+1]>='1') and (More[j+1]<='5')then
  1721. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1722. else
  1723. IllegalPara(opt);
  1724. end;
  1725. break;
  1726. end;
  1727. 'o' :
  1728. begin
  1729. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1730. IllegalPara(opt);
  1731. break;
  1732. end;
  1733. '-' :
  1734. begin
  1735. init_settings.optimizerswitches:=[];
  1736. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1737. end;
  1738. { Obsolete switches }
  1739. 'g' :
  1740. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1741. 'G' :
  1742. Message1(option_obsolete_switch,'-OG');
  1743. 'r' :
  1744. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1745. 'u' :
  1746. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1747. 'w' :
  1748. begin
  1749. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1750. IllegalPara(opt);
  1751. break;
  1752. end;
  1753. 'W' :
  1754. begin
  1755. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1756. IllegalPara(opt);
  1757. break;
  1758. end;
  1759. else
  1760. IllegalPara(opt);
  1761. end;
  1762. inc(j);
  1763. end;
  1764. end;
  1765. 'p' :
  1766. begin
  1767. if UnsetBool(More, 0, opt, false) then
  1768. begin
  1769. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1770. undef_system_macro('FPC_PROFILE');
  1771. end
  1772. else
  1773. if Length(More)=0 then
  1774. IllegalPara(opt)
  1775. else
  1776. case more[1] of
  1777. 'g' : if UnsetBool(more, 1, opt, false) then
  1778. begin
  1779. exclude(init_settings.moduleswitches,cs_profile);
  1780. undef_system_macro('FPC_PROFILE');
  1781. end
  1782. else if (target_info.system in supported_targets_pg) then
  1783. begin
  1784. include(init_settings.moduleswitches,cs_profile);
  1785. def_system_macro('FPC_PROFILE');
  1786. end
  1787. else
  1788. UnsupportedPara('-pg');
  1789. else
  1790. IllegalPara(opt);
  1791. end;
  1792. end;
  1793. 'P' : ; { Ignore used by fpc.pp }
  1794. 'R' :
  1795. begin
  1796. if not SetAsmReadMode(More,init_settings.asmmode) then
  1797. IllegalPara(opt);
  1798. end;
  1799. 's' :
  1800. begin
  1801. if UnsetBool(More, 0, opt, false) then
  1802. begin
  1803. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1804. if more<>'' then
  1805. IllegalPara(opt);
  1806. end
  1807. else
  1808. begin
  1809. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1810. if more='h' then
  1811. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1812. else if more='t' then
  1813. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1814. else if more='r' then
  1815. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1816. else if more<>'' then
  1817. IllegalPara(opt);
  1818. end;
  1819. end;
  1820. 'S' :
  1821. begin
  1822. if more='' then
  1823. IllegalPara(opt);
  1824. if more[1]='I' then
  1825. begin
  1826. {$ifdef jvm}
  1827. UnsupportedPara('-SI');
  1828. {$endif}
  1829. if upper(more)='ICOM' then
  1830. init_settings.interfacetype:=it_interfacecom
  1831. else if upper(more)='ICORBA' then
  1832. init_settings.interfacetype:=it_interfacecorba
  1833. else
  1834. IllegalPara(opt);
  1835. end
  1836. else
  1837. begin
  1838. j:=1;
  1839. while j<=length(more) do
  1840. begin
  1841. case more[j] of
  1842. '2' : //an alternative to -Mobjfpc
  1843. SetCompileMode('OBJFPC',true);
  1844. 'a' :
  1845. If UnsetBool(More, j, opt, false) then
  1846. exclude(init_settings.localswitches,cs_do_assertion)
  1847. else
  1848. include(init_settings.localswitches,cs_do_assertion);
  1849. 'c' :
  1850. If UnsetBool(More, j, opt, false) then
  1851. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1852. else
  1853. include(init_settings.moduleswitches,cs_support_c_operators);
  1854. 'd' : //an alternative to -Mdelphi
  1855. SetCompileMode('DELPHI',true);
  1856. 'e' :
  1857. begin
  1858. SetErrorFlags(copy(more,j+1,length(more)));
  1859. break;
  1860. end;
  1861. 'f' :
  1862. begin
  1863. inc(j);
  1864. if more[j]='-' then
  1865. begin
  1866. if length(more)>j then
  1867. IllegalPara(opt)
  1868. else
  1869. features:=[];
  1870. end
  1871. else
  1872. begin
  1873. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  1874. j:=length(more)
  1875. else
  1876. IllegalPara(opt);
  1877. end;
  1878. end;
  1879. 'g' :
  1880. If UnsetBool(More, j, opt, false) then
  1881. exclude(init_settings.moduleswitches,cs_support_goto)
  1882. else
  1883. include(init_settings.moduleswitches,cs_support_goto);
  1884. 'h' :
  1885. If UnsetBool(More, j, opt, false) then
  1886. exclude(init_settings.localswitches,cs_refcountedstrings)
  1887. else
  1888. include(init_settings.localswitches,cs_refcountedstrings);
  1889. 'i' :
  1890. If UnsetBool(More, j, opt, false) then
  1891. exclude(init_settings.localswitches,cs_do_inline)
  1892. else
  1893. include(init_settings.localswitches,cs_do_inline);
  1894. 'k' :
  1895. If UnsetBool(More, j, opt, false) then
  1896. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1897. else
  1898. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1899. 'm' :
  1900. If UnsetBool(More, j, opt, false) then
  1901. exclude(init_settings.moduleswitches,cs_support_macro)
  1902. else
  1903. include(init_settings.moduleswitches,cs_support_macro);
  1904. 'o' : //an alternative to -Mtp
  1905. SetCompileMode('TP',true);
  1906. {$ifdef gpc_mode}
  1907. 'p' : //an alternative to -Mgpc
  1908. SetCompileMode('GPC',true);
  1909. {$endif}
  1910. 's' :
  1911. If UnsetBool(More, j, opt, false) then
  1912. exclude(init_settings.globalswitches,cs_constructor_name)
  1913. else
  1914. include(init_settings.globalswitches,cs_constructor_name);
  1915. 't' :
  1916. Message1(option_obsolete_switch,'-St');
  1917. 'v' :
  1918. If UnsetBool(More, j, opt, false) then
  1919. exclude(init_settings.globalswitches,cs_support_vectors)
  1920. else
  1921. include(init_settings.globalswitches,cs_support_vectors);
  1922. 'x' :
  1923. If UnsetBool(More, j, opt, false) then
  1924. SetCompileModeSwitch('EXCEPTIONS-',true)
  1925. else
  1926. SetCompileModeSwitch('EXCEPTIONS',true);
  1927. 'y' :
  1928. If UnsetBool(More, j, opt, false) then
  1929. exclude(init_settings.localswitches,cs_typed_addresses)
  1930. else
  1931. include(init_settings.localswitches,cs_typed_addresses);
  1932. '-' :
  1933. begin
  1934. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1935. cs_support_vectors,cs_load_fpcylix_unit];
  1936. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  1937. cs_typed_addresses];
  1938. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1939. cs_support_macro];
  1940. end;
  1941. else
  1942. IllegalPara(opt);
  1943. end;
  1944. inc(j);
  1945. end;
  1946. end;
  1947. end;
  1948. 'T' :
  1949. begin
  1950. more:=Upper(More);
  1951. if paratarget=system_none then
  1952. begin
  1953. { remove old target define }
  1954. TargetOptions(false);
  1955. { load new target }
  1956. paratarget:=find_system_by_string(More);
  1957. if paratarget<>system_none then
  1958. set_target(paratarget)
  1959. else
  1960. IllegalPara(opt);
  1961. { set new define }
  1962. TargetOptions(true);
  1963. end
  1964. else
  1965. if More<>upper(target_info.shortname) then
  1966. Message1(option_target_is_already_set,target_info.shortname);
  1967. end;
  1968. 'u' :
  1969. if is_identifier(more) then
  1970. undef_system_macro(more)
  1971. else
  1972. begin
  1973. if (more='') then
  1974. Message1(option_missing_arg,'-u')
  1975. else
  1976. Message1(option_malformed_para,opt);
  1977. StopOptions(1);
  1978. end;
  1979. 'U' :
  1980. begin
  1981. j:=1;
  1982. while j<=length(more) do
  1983. begin
  1984. case more[j] of
  1985. {$ifdef UNITALIASES}
  1986. 'a' :
  1987. begin
  1988. AddUnitAlias(Copy(More,j+1,255));
  1989. break;
  1990. end;
  1991. {$endif UNITALIASES}
  1992. 'n' :
  1993. exclude(init_settings.globalswitches,cs_check_unit_name);
  1994. 'p' :
  1995. begin
  1996. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1997. break;
  1998. end;
  1999. 'r' :
  2000. begin
  2001. do_release:=true;
  2002. if (cs_checkpointer in init_settings.localswitches) then
  2003. begin
  2004. Message(option_gc_incompatible_with_release_flag);
  2005. exclude(init_settings.localswitches,cs_checkpointer);
  2006. end;
  2007. end;
  2008. 's' :
  2009. include(init_settings.moduleswitches,cs_compilesystem);
  2010. '-' :
  2011. begin
  2012. exclude(init_settings.moduleswitches,cs_compilesystem);
  2013. exclude(init_settings.globalswitches,cs_check_unit_name);
  2014. end;
  2015. else
  2016. IllegalPara(opt);
  2017. end;
  2018. inc(j);
  2019. end;
  2020. end;
  2021. 'v' :
  2022. begin
  2023. if not setverbosity(More) then
  2024. IllegalPara(opt);
  2025. end;
  2026. 'V' : ; { Ignore used by fpc }
  2027. 'W' :
  2028. begin
  2029. j:=1;
  2030. while j<=length(More) do
  2031. begin
  2032. case More[j] of
  2033. 'A':
  2034. begin
  2035. if target_info.system in systems_all_windows then
  2036. begin
  2037. if UnsetBool(More, j, opt, false) then
  2038. SetApptype(app_cui)
  2039. else
  2040. SetApptype(app_native);
  2041. end
  2042. else
  2043. IllegalPara(opt);
  2044. end;
  2045. 'b':
  2046. begin
  2047. if target_info.system in systems_darwin then
  2048. begin
  2049. if UnsetBool(More, j, opt, false) then
  2050. SetApptype(app_cui)
  2051. else
  2052. SetApptype(app_bundle)
  2053. end
  2054. else
  2055. IllegalPara(opt);
  2056. end;
  2057. 'B':
  2058. begin
  2059. if target_info.system in systems_all_windows+systems_symbian then
  2060. begin
  2061. { -WB200000 means set trefered base address
  2062. to $200000, but does not change relocsection boolean
  2063. this way we can create both relocatble and
  2064. non relocatable DLL at a specific base address PM }
  2065. if (length(More)>j) then
  2066. begin
  2067. val('$'+Copy(More,j+1,255),imagebase,code);
  2068. if code<>0 then
  2069. IllegalPara(opt);
  2070. ImageBaseSetExplicity:=true;
  2071. end
  2072. else
  2073. begin
  2074. RelocSection:=true;
  2075. RelocSectionSetExplicitly:=true;
  2076. end;
  2077. break;
  2078. end
  2079. else
  2080. IllegalPara(opt);
  2081. end;
  2082. 'C':
  2083. begin
  2084. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2085. begin
  2086. if UnsetBool(More, j, opt, false) then
  2087. SetApptype(app_gui)
  2088. else
  2089. SetApptype(app_cui);
  2090. end
  2091. else
  2092. IllegalPara(opt);
  2093. end;
  2094. 'D':
  2095. begin
  2096. if target_info.system in systems_all_windows then
  2097. begin
  2098. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2099. UseDeffileForExportsSetExplicitly:=true;
  2100. end
  2101. else
  2102. IllegalPara(opt);
  2103. end;
  2104. 'e':
  2105. begin
  2106. if (target_info.system in systems_darwin) then
  2107. begin
  2108. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  2109. set_target_res(res_ext);
  2110. target_info.resobjext:='.fpcres';
  2111. end
  2112. else
  2113. IllegalPara(opt);
  2114. end;
  2115. 'F':
  2116. begin
  2117. if target_info.system in systems_os2 then
  2118. begin
  2119. if UnsetBool(More, j, opt, false) then
  2120. SetApptype(app_cui)
  2121. else
  2122. SetApptype(app_fs);
  2123. end
  2124. else
  2125. IllegalPara(opt);
  2126. end;
  2127. 'G':
  2128. begin
  2129. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2130. begin
  2131. if UnsetBool(More, j, opt, false) then
  2132. SetApptype(app_cui)
  2133. else
  2134. SetApptype(app_gui);
  2135. end
  2136. else
  2137. IllegalPara(opt);
  2138. end;
  2139. 'I':
  2140. begin
  2141. if target_info.system in systems_all_windows then
  2142. begin
  2143. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2144. GenerateImportSectionSetExplicitly:=true;
  2145. end
  2146. else
  2147. IllegalPara(opt);
  2148. end;
  2149. 'i':
  2150. begin
  2151. if (target_info.system in systems_darwin) then
  2152. begin
  2153. set_target_res(res_macho);
  2154. target_info.resobjext:=
  2155. targetinfos[target_info.system]^.resobjext;
  2156. end
  2157. else
  2158. IllegalPara(opt);
  2159. end;
  2160. 'm':
  2161. begin
  2162. {$if defined(i8086)}
  2163. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2164. begin
  2165. case Upper(Copy(More,j+1,255)) of
  2166. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2167. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2168. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2169. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2170. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2171. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2172. else
  2173. IllegalPara(opt);
  2174. end;
  2175. break;
  2176. end
  2177. else
  2178. {$endif defined(i8086)}
  2179. IllegalPara(opt);
  2180. end;
  2181. 'M':
  2182. begin
  2183. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim])) and
  2184. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2185. begin
  2186. break;
  2187. end
  2188. else
  2189. IllegalPara(opt);
  2190. end;
  2191. 'N':
  2192. begin
  2193. if target_info.system in systems_all_windows then
  2194. begin
  2195. RelocSection:=UnsetBool(More,j,opt,false);
  2196. RelocSectionSetExplicitly:=true;
  2197. end
  2198. else
  2199. IllegalPara(opt);
  2200. end;
  2201. 'p':
  2202. begin
  2203. if (target_info.system in systems_embedded) and
  2204. ControllerSupport then
  2205. begin
  2206. s:=upper(copy(more,j+1,length(more)-j));
  2207. if not(SetControllerType(s,init_settings.controllertype)) then
  2208. IllegalPara(opt);
  2209. break;
  2210. end
  2211. else
  2212. IllegalPara(opt);
  2213. end;
  2214. 'P':
  2215. begin
  2216. if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) and
  2217. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2218. begin
  2219. break;
  2220. end
  2221. else
  2222. IllegalPara(opt);
  2223. end;
  2224. 'R':
  2225. begin
  2226. if target_info.system in systems_all_windows then
  2227. begin
  2228. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2229. RelocSection:=not UnsetBool(More,j,opt,false);
  2230. RelocSectionSetExplicitly:=true;
  2231. end
  2232. else
  2233. IllegalPara(opt);
  2234. end;
  2235. 't':
  2236. begin
  2237. {$if defined(i8086)}
  2238. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2239. begin
  2240. case Upper(Copy(More,j+1,255)) of
  2241. 'EXE': SetAppType(app_cui);
  2242. 'COM': SetAppType(app_com);
  2243. else
  2244. IllegalPara(opt);
  2245. end;
  2246. break;
  2247. end
  2248. else
  2249. {$endif defined(i8086)}
  2250. IllegalPara(opt);
  2251. end;
  2252. 'T':
  2253. begin
  2254. if target_info.system in systems_macos then
  2255. begin
  2256. if UnsetBool(More, j, opt, false) then
  2257. SetApptype(app_cui)
  2258. else
  2259. SetApptype(app_tool);
  2260. end
  2261. else
  2262. IllegalPara(opt);
  2263. end;
  2264. 'X':
  2265. begin
  2266. if (target_info.system in systems_linux) then
  2267. begin
  2268. if UnsetBool(More, j, opt, false) then
  2269. exclude(init_settings.moduleswitches,cs_executable_stack)
  2270. else
  2271. include(init_settings.moduleswitches,cs_executable_stack)
  2272. end
  2273. else
  2274. IllegalPara(opt);
  2275. end;
  2276. else
  2277. IllegalPara(opt);
  2278. end;
  2279. inc(j);
  2280. end;
  2281. end;
  2282. 'X' :
  2283. begin
  2284. j:=1;
  2285. while j<=length(more) do
  2286. begin
  2287. case More[j] of
  2288. '9' :
  2289. begin
  2290. if target_info.system in systems_linux then
  2291. begin
  2292. if UnsetBool(More, j, opt, false) then
  2293. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2294. else
  2295. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2296. end
  2297. else
  2298. IllegalPara(opt);
  2299. end;
  2300. 'c' : Cshared:=TRUE;
  2301. 'd' : Dontlinkstdlibpath:=TRUE;
  2302. 'e' :
  2303. begin
  2304. If UnsetBool(More, j, opt, false) then
  2305. exclude(init_settings.globalswitches,cs_link_extern)
  2306. else
  2307. include(init_settings.globalswitches,cs_link_extern);
  2308. end;
  2309. 'f' :
  2310. include(init_settings.globalswitches,cs_link_pthread);
  2311. 'g' :
  2312. begin
  2313. If UnsetBool(More, j, opt, false) then
  2314. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2315. else
  2316. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2317. end;
  2318. 'i' :
  2319. begin
  2320. If UnsetBool(More, j, opt, false) then
  2321. include(init_settings.globalswitches,cs_link_extern)
  2322. else
  2323. exclude(init_settings.globalswitches,cs_link_extern);
  2324. end;
  2325. 'n' :
  2326. begin
  2327. If UnsetBool(More, j, opt, false) then
  2328. exclude(init_settings.globalswitches,cs_link_native)
  2329. else
  2330. include(init_settings.globalswitches,cs_link_native);
  2331. end;
  2332. 'm' :
  2333. begin
  2334. If UnsetBool(More, j, opt, false) then
  2335. exclude(init_settings.globalswitches,cs_link_map)
  2336. else
  2337. include(init_settings.globalswitches,cs_link_map);
  2338. end;
  2339. 'p' : ; { Ignore used by fpc.pp }
  2340. 'r' :
  2341. begin
  2342. if (target_info.system in suppported_targets_x_smallr) then
  2343. begin
  2344. rlinkpath:=Copy(more,2,length(More)-1);
  2345. DefaultReplacements(rlinkpath);
  2346. end
  2347. else
  2348. IgnoredPara('-Xr');
  2349. more:='';
  2350. end;
  2351. 'R' :
  2352. begin
  2353. sysrootpath:=copy(more,2,length(more)-1);
  2354. defaultreplacements(sysrootpath);
  2355. more:='';
  2356. end;
  2357. 's' :
  2358. begin
  2359. If UnsetBool(More, j, opt, false) then
  2360. exclude(init_settings.globalswitches,cs_link_strip)
  2361. else
  2362. include(init_settings.globalswitches,cs_link_strip);
  2363. end;
  2364. 't' :
  2365. include(init_settings.globalswitches,cs_link_staticflag);
  2366. 'v' :
  2367. begin
  2368. If UnsetBool(More, j, opt, false) then
  2369. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2370. else
  2371. include(init_settings.globalswitches,cs_link_opt_vtable);
  2372. end;
  2373. 'D' :
  2374. begin
  2375. def_system_macro('FPC_LINK_DYNAMIC');
  2376. undef_system_macro('FPC_LINK_SMART');
  2377. undef_system_macro('FPC_LINK_STATIC');
  2378. exclude(init_settings.globalswitches,cs_link_static);
  2379. exclude(init_settings.globalswitches,cs_link_smart);
  2380. include(init_settings.globalswitches,cs_link_shared);
  2381. LinkTypeSetExplicitly:=true;
  2382. end;
  2383. 'M' :
  2384. begin
  2385. mainaliasname:=Copy(more,2,length(More)-1);
  2386. More:='';
  2387. end;
  2388. 'P' :
  2389. begin
  2390. utilsprefix:=Copy(more,2,length(More)-1);
  2391. DefaultReplacements(utilsprefix);
  2392. More:='';
  2393. end;
  2394. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2395. // these are not aggregable.
  2396. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2397. IllegalPara(opt)
  2398. else
  2399. begin
  2400. case more[j+1] of
  2401. 'A' : begin
  2402. s:=Copy(more,3,length(More)-2);
  2403. if not LinkLibraryAliases.AddDep(s) Then
  2404. IllegalPara(opt);
  2405. end;
  2406. 'O' : begin
  2407. s:=Copy(more,3,length(More)-2);
  2408. if not LinkLibraryOrder.AddWeight(s) Then
  2409. IllegalPara(opt);
  2410. end;
  2411. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2412. else
  2413. IllegalPara(opt);
  2414. end; {case}
  2415. j:=length(more);
  2416. end; {else begin}
  2417. end;
  2418. 'S' :
  2419. begin
  2420. ForceStaticLinking;
  2421. end;
  2422. 'V' :
  2423. begin
  2424. if UnsetBool(More, j, opt, false) then
  2425. exclude(init_settings.globalswitches,cs_link_vlink)
  2426. else
  2427. begin
  2428. include(init_settings.globalswitches,cs_link_vlink);
  2429. include(init_settings.globalswitches,cs_link_extern);
  2430. end;
  2431. end;
  2432. 'X' :
  2433. begin
  2434. def_system_macro('FPC_LINK_SMART');
  2435. undef_system_macro('FPC_LINK_STATIC');
  2436. undef_system_macro('FPC_LINK_DYNAMIC');
  2437. exclude(init_settings.globalswitches,cs_link_static);
  2438. include(init_settings.globalswitches,cs_link_smart);
  2439. exclude(init_settings.globalswitches,cs_link_shared);
  2440. LinkTypeSetExplicitly:=true;
  2441. end;
  2442. '-' :
  2443. begin
  2444. exclude(init_settings.globalswitches,cs_link_staticflag);
  2445. exclude(init_settings.globalswitches,cs_link_strip);
  2446. exclude(init_settings.globalswitches,cs_link_map);
  2447. set_default_link_type;
  2448. end;
  2449. else
  2450. IllegalPara(opt);
  2451. end;
  2452. inc(j);
  2453. end;
  2454. end;
  2455. else
  2456. IllegalPara(opt);
  2457. end;
  2458. end;
  2459. '@' :
  2460. begin
  2461. Message(option_no_nested_response_file);
  2462. StopOptions(1);
  2463. end;
  2464. else
  2465. begin
  2466. if (length(param_file)<>0) then
  2467. Message2(option_only_one_source_support,param_file,opt);
  2468. param_file:=opt;
  2469. Message1(option_found_file,opt);
  2470. end;
  2471. end;
  2472. end;
  2473. procedure Toption.Interpret_file(const filename : TPathStr);
  2474. procedure RemoveSep(var fn:TPathStr);
  2475. var
  2476. i : longint;
  2477. begin
  2478. i:=0;
  2479. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2480. inc(i);
  2481. Delete(fn,1,i);
  2482. i:=length(fn);
  2483. while (i>0) and (fn[i] in [',',' ',#9]) do
  2484. dec(i);
  2485. fn:=copy(fn,1,i);
  2486. end;
  2487. function GetName(var fn:TPathStr):TPathStr;
  2488. var
  2489. i : longint;
  2490. begin
  2491. i:=0;
  2492. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2493. inc(i);
  2494. GetName:=Copy(fn,1,i);
  2495. Delete(fn,1,i);
  2496. end;
  2497. const
  2498. maxlevel = 15;
  2499. var
  2500. f : text;
  2501. s, tmp,
  2502. opts : TCmdStr;
  2503. skip : array[0..maxlevel] of boolean;
  2504. line,
  2505. level : longint;
  2506. option_read : boolean;
  2507. oldfilemode : byte;
  2508. ConfigFile: TPathStr;
  2509. begin
  2510. { avoid infinite loop }
  2511. Inc(FileLevel);
  2512. Option_read:=false;
  2513. If FileLevel>MaxLevel then
  2514. Message(option_too_many_cfg_files);
  2515. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2516. ConfigFile := ExpandFileName(filename);
  2517. { Maybe It's Directory ?} //Jaro Change:
  2518. if PathExists(ConfigFile,false) then
  2519. begin
  2520. Message1(option_config_is_dir,filename);
  2521. exit;
  2522. end;
  2523. { open file }
  2524. Message1(option_using_file,filename);
  2525. oldfilemode:=filemode;
  2526. filemode:=0;
  2527. assign(f,ConfigFile);
  2528. {$push}{$I-}
  2529. reset(f);
  2530. {$pop}
  2531. filemode:=oldfilemode;
  2532. if ioresult<>0 then
  2533. begin
  2534. Message1(option_unable_open_file,filename);
  2535. exit;
  2536. end;
  2537. Message1(option_start_reading_configfile,filename);
  2538. fillchar(skip,sizeof(skip),0);
  2539. level:=0;
  2540. line:=0;
  2541. while not eof(f) do
  2542. begin
  2543. readln(f,opts);
  2544. inc(line);
  2545. RemoveSep(opts);
  2546. if (opts<>'') and (opts[1]<>';') then
  2547. begin
  2548. if opts[1]='#' then
  2549. begin
  2550. Message1(option_interpreting_file_option,opts);
  2551. Delete(opts,1,1);
  2552. s:=upper(GetName(opts));
  2553. if (s='SECTION') then
  2554. begin
  2555. RemoveSep(opts);
  2556. s:=upper(GetName(opts));
  2557. if level=0 then
  2558. skip[level]:=not defined_macro(s) or (s='COMMON');
  2559. end
  2560. else
  2561. if (s='IFDEF') 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 not defined_macro(upper(GetName(opts))));
  2571. end
  2572. else
  2573. if (s='IFNDEF') then
  2574. begin
  2575. RemoveSep(opts);
  2576. if Level>=maxlevel then
  2577. begin
  2578. Message2(option_too_many_ifdef,filename,tostr(line));
  2579. stopOptions(1);
  2580. end;
  2581. inc(Level);
  2582. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2583. end
  2584. else
  2585. if (s='ELSE') then
  2586. begin
  2587. if Level=0 then
  2588. begin
  2589. Message2(option_else_without_if,filename,tostr(line));
  2590. stopOptions(1);
  2591. end
  2592. else
  2593. skip[level]:=skip[level-1] or (not skip[level])
  2594. end
  2595. else
  2596. if (s='ENDIF') then
  2597. begin
  2598. skip[level]:=false;
  2599. if Level=0 then
  2600. begin
  2601. Message2(option_too_many_endif,filename,tostr(line));
  2602. stopOptions(1);
  2603. end;
  2604. dec(level);
  2605. end
  2606. else
  2607. if (not skip[level]) then
  2608. begin
  2609. if (s='DEFINE') then
  2610. begin
  2611. RemoveSep(opts);
  2612. tmp:= GetName(opts);
  2613. if tmp <> '' then
  2614. def_system_macro(tmp);
  2615. Option_read:=true;
  2616. end
  2617. else
  2618. if (s='UNDEF') then
  2619. begin
  2620. RemoveSep(opts);
  2621. tmp:= GetName(opts);
  2622. if tmp <> '' then
  2623. undef_system_macro(tmp);
  2624. Option_read:=true;
  2625. end
  2626. else
  2627. if (s='WRITE') then
  2628. begin
  2629. Delete(opts,1,1);
  2630. DefaultReplacements(opts);
  2631. WriteLn(opts);
  2632. Option_read:=true;
  2633. end
  2634. else
  2635. if (s='INCLUDE') then
  2636. begin
  2637. Delete(opts,1,1);
  2638. DefaultReplacements(opts);
  2639. Interpret_file(opts);
  2640. Option_read:=true;
  2641. end
  2642. else
  2643. if (s='CFGDIR') then
  2644. begin
  2645. Delete(opts,1,1);
  2646. DefaultReplacements(opts);
  2647. ParaIncludeCfgPath.AddPath(opts,false);
  2648. Option_read:=true;
  2649. end;
  2650. end;
  2651. end
  2652. else
  2653. begin
  2654. if (opts[1]='-') or (opts[1]='@') then
  2655. begin
  2656. if (not skip[level]) then
  2657. interpret_option(opts,false);
  2658. Option_read:=true;
  2659. end
  2660. else
  2661. Message1(option_illegal_para,opts);
  2662. end;
  2663. end;
  2664. end;
  2665. if Level>0 then
  2666. Message(option_too_less_endif);
  2667. if Not Option_read then
  2668. Message1(option_no_option_found,filename)
  2669. else
  2670. Message1(option_end_reading_configfile,filename);
  2671. Close(f);
  2672. Dec(FileLevel);
  2673. end;
  2674. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2675. var
  2676. argstart,
  2677. env,
  2678. pc : pchar;
  2679. arglen : longint;
  2680. quote : set of char;
  2681. hs : TCmdStr;
  2682. begin
  2683. Message1(option_using_env,envname);
  2684. env:=GetEnvPChar(envname);
  2685. pc:=env;
  2686. if assigned(pc) then
  2687. begin
  2688. repeat
  2689. { skip leading spaces }
  2690. while pc^ in [' ',#9,#13] do
  2691. inc(pc);
  2692. case pc^ of
  2693. #0 :
  2694. break;
  2695. '"' :
  2696. begin
  2697. quote:=['"'];
  2698. inc(pc);
  2699. end;
  2700. '''' :
  2701. begin
  2702. quote:=[''''];
  2703. inc(pc);
  2704. end;
  2705. else
  2706. quote:=[' ',#9,#13];
  2707. end;
  2708. { scan until the end of the argument }
  2709. argstart:=pc;
  2710. while (pc^<>#0) and not(pc^ in quote) do
  2711. inc(pc);
  2712. { create argument }
  2713. arglen:=pc-argstart;
  2714. { TODO: FIXME: silent truncation of environment parameters }
  2715. if (arglen > 255) then
  2716. arglen := 255;
  2717. setlength(hs,arglen);
  2718. move(argstart^,hs[1],arglen);
  2719. interpret_option(hs,true);
  2720. { skip quote }
  2721. if pc^ in quote then
  2722. inc(pc);
  2723. until false;
  2724. end
  2725. else
  2726. Message1(option_no_option_found,'(env) '+envname);
  2727. FreeEnvPChar(env);
  2728. end;
  2729. procedure toption.read_parameters;
  2730. var
  2731. opts : TCmdStr;
  2732. paramindex : longint;
  2733. begin
  2734. paramindex:=0;
  2735. while paramindex<paramcount do
  2736. begin
  2737. inc(paramindex);
  2738. opts:=objpas.paramstr(paramindex);
  2739. if length(opts)>0 then
  2740. case opts[1] of
  2741. '@' :
  2742. if not firstpass then
  2743. begin
  2744. Delete(opts,1,1);
  2745. Message1(option_reading_further_from,opts);
  2746. interpret_file(opts);
  2747. end;
  2748. '!' :
  2749. if not firstpass then
  2750. begin
  2751. Delete(opts,1,1);
  2752. Message1(option_reading_further_from,'(env) '+opts);
  2753. interpret_envvar(opts);
  2754. end;
  2755. else
  2756. interpret_option(opts,true);
  2757. end;
  2758. end;
  2759. end;
  2760. procedure toption.parsecmd(cmd:TCmdStr);
  2761. var
  2762. i,ps : longint;
  2763. opts : TCmdStr;
  2764. begin
  2765. while (cmd<>'') do
  2766. begin
  2767. while cmd[1]=' ' do
  2768. delete(cmd,1,1);
  2769. i:=pos(' ',cmd);
  2770. if i=0 then
  2771. i:=2147483647;
  2772. opts:=Copy(cmd,1,i-1);
  2773. Delete(cmd,1,i);
  2774. case opts[1] of
  2775. '@' :
  2776. if not firstpass then
  2777. begin
  2778. Delete(opts,1,1);
  2779. Message1(option_reading_further_from,opts);
  2780. interpret_file(opts);
  2781. end;
  2782. '!' :
  2783. if not firstpass then
  2784. begin
  2785. Delete(opts,1,1);
  2786. Message1(option_reading_further_from,'(env) '+opts);
  2787. interpret_envvar(opts);
  2788. end;
  2789. '"' :
  2790. begin
  2791. Delete(opts,1,1);
  2792. ps:=pos('"',cmd);
  2793. if (i<>256) and (ps>0) then
  2794. begin
  2795. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2796. cmd:=copy(cmd,ps+1,255);
  2797. end;
  2798. interpret_option(opts,true);
  2799. end;
  2800. else
  2801. interpret_option(opts,true);
  2802. end;
  2803. end;
  2804. end;
  2805. procedure toption.writequickinfo;
  2806. var
  2807. s : string;
  2808. i : longint;
  2809. procedure addinfo(const hs:string);
  2810. begin
  2811. if s<>'' then
  2812. s:=s+' '+hs
  2813. else
  2814. s:=hs;
  2815. end;
  2816. begin
  2817. s:='';
  2818. i:=0;
  2819. while (i<length(quickinfo)) do
  2820. begin
  2821. inc(i);
  2822. case quickinfo[i] of
  2823. 'S' :
  2824. begin
  2825. inc(i);
  2826. case quickinfo[i] of
  2827. 'O' :
  2828. addinfo(lower(source_info.shortname));
  2829. 'P' :
  2830. addinfo(source_cpu_string);
  2831. else
  2832. IllegalPara('-i'+QuickInfo);
  2833. end;
  2834. end;
  2835. 'T' :
  2836. begin
  2837. inc(i);
  2838. case quickinfo[i] of
  2839. 'O' :
  2840. addinfo(lower(target_info.shortname));
  2841. 'P' :
  2842. AddInfo(target_cpu_string);
  2843. else
  2844. IllegalPara('-i'+QuickInfo);
  2845. end;
  2846. end;
  2847. 'V' :
  2848. AddInfo(version_string);
  2849. 'W' :
  2850. AddInfo(full_version_string);
  2851. 'D' :
  2852. AddInfo(date_string);
  2853. '_' :
  2854. ;
  2855. else
  2856. IllegalPara('-i'+QuickInfo);
  2857. end;
  2858. end;
  2859. if s<>'' then
  2860. begin
  2861. writeln(s);
  2862. stopoptions(0);
  2863. end;
  2864. end;
  2865. procedure TOption.TargetOptions(def:boolean);
  2866. var
  2867. s : string;
  2868. i : integer;
  2869. target_unsup_features : tfeatures;
  2870. begin
  2871. if def then
  2872. def_system_macro(target_info.shortname)
  2873. else
  2874. undef_system_macro(target_info.shortname);
  2875. s:=target_info.extradefines;
  2876. while (s<>'') do
  2877. begin
  2878. i:=pos(';',s);
  2879. if i=0 then
  2880. i:=length(s)+1;
  2881. if def then
  2882. def_system_macro(Copy(s,1,i-1))
  2883. else
  2884. undef_system_macro(Copy(s,1,i-1));
  2885. delete(s,1,i);
  2886. end;
  2887. if (tf_winlikewidestring in target_info.flags) then
  2888. if def then
  2889. def_system_macro('FPC_WINLIKEWIDESTRING')
  2890. else
  2891. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2892. if (tf_requires_proper_alignment in target_info.flags) then
  2893. if def then
  2894. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2895. else
  2896. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2897. if source_info.system<>target_info.system then
  2898. if def then
  2899. def_system_macro('FPC_CROSSCOMPILING')
  2900. else
  2901. undef_system_macro('FPC_CROSSCOMPILING');
  2902. if source_info.cpu<>target_info.cpu then
  2903. if def then
  2904. def_system_macro('FPC_CPUCROSSCOMPILING')
  2905. else
  2906. def_system_macro('FPC_CPUCROSSCOMPILING');
  2907. if (tf_no_generic_stackcheck in target_info.flags) then
  2908. if def then
  2909. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2910. else
  2911. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2912. if (tf_section_threadvars in target_info.flags) then
  2913. if def then
  2914. def_system_macro('FPC_SECTION_THREADVARS')
  2915. else
  2916. undef_system_macro('FPC_SECTION_THREADVARS');
  2917. { Code generation flags }
  2918. if (tf_pic_default in target_info.flags) then
  2919. if def then
  2920. include(init_settings.moduleswitches,cs_create_pic)
  2921. else
  2922. exclude(init_settings.moduleswitches,cs_create_pic);
  2923. { Resources support }
  2924. if (tf_has_winlike_resources in target_info.flags) then
  2925. if def then
  2926. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2927. else
  2928. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2929. { Features }
  2930. case target_info.system of
  2931. system_arm_gba:
  2932. target_unsup_features:=[f_dynlibs];
  2933. system_arm_nds:
  2934. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2935. system_i386_nativent:
  2936. // until these features are implemented, they are disabled in the compiler
  2937. target_unsup_features:=[f_stackcheck];
  2938. system_jvm_java32,
  2939. system_jvm_android32:
  2940. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2941. f_variants,f_objects,f_commandargs,
  2942. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2943. else
  2944. target_unsup_features:=[];
  2945. end;
  2946. if def then
  2947. features:=features-target_unsup_features
  2948. else
  2949. features:=features+target_unsup_features;
  2950. {$ifdef hasamiga}
  2951. { enable vlink as default linker on Amiga/MorphOS, but not for cross compilers (for now) }
  2952. if target_info.system in [system_m68k_amiga,system_powerpc_amiga,system_powerpc_morphos] then
  2953. include(init_settings.globalswitches,cs_link_vlink);
  2954. {$endif}
  2955. end;
  2956. procedure TOption.checkoptionscompatibility;
  2957. begin
  2958. {$ifdef i8086}
  2959. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  2960. begin
  2961. Message(option_com_files_require_tiny_model);
  2962. StopOptions(1);
  2963. end;
  2964. {$endif i8086}
  2965. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2966. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  2967. begin
  2968. { smartlink creation does not yet work with DWARF
  2969. debug info on most targets, but it works in internal assembler }
  2970. if (cs_create_smart in init_settings.moduleswitches) and
  2971. not (af_outputbinary in target_asm.flags) then
  2972. begin
  2973. Message(option_dwarf_smartlink_creation);
  2974. exclude(init_settings.moduleswitches,cs_create_smart);
  2975. end;
  2976. { smart linking does not yet work with DWARF debug info on most targets }
  2977. if (cs_link_smart in init_settings.globalswitches) then
  2978. begin
  2979. Message(option_dwarf_smart_linking);
  2980. ForceStaticLinking;
  2981. end;
  2982. end;
  2983. { external debug info is only supported for DWARF on darwin }
  2984. if (target_info.system in systems_darwin) and
  2985. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2986. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2987. begin
  2988. Message(option_debug_external_unsupported);
  2989. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2990. end;
  2991. { Also create a smartlinked version, on an assembler that
  2992. does not support smartlink sections like nasm?
  2993. This is not compatible with using internal linker. }
  2994. if ((cs_link_smart in init_settings.globalswitches) or
  2995. (cs_create_smart in init_settings.moduleswitches)) and
  2996. (af_needar in target_asm.flags) and
  2997. not (af_smartlink_sections in target_asm.flags) and
  2998. not (cs_link_extern in init_settings.globalswitches) and
  2999. (target_info.link<>ld_none) and
  3000. not (cs_link_nolink in init_settings.globalswitches) then
  3001. begin
  3002. Message(option_smart_link_requires_external_linker);
  3003. include(init_settings.globalswitches,cs_link_extern);
  3004. end;
  3005. end;
  3006. constructor TOption.create;
  3007. begin
  3008. LogoWritten:=false;
  3009. NoPressEnter:=false;
  3010. FirstPass:=false;
  3011. ABISetExplicitly:=false;
  3012. FPUSetExplicitly:=false;
  3013. CPUSetExplicitly:=false;
  3014. OptCPUSetExplicitly:=false;
  3015. FileLevel:=0;
  3016. Quickinfo:='';
  3017. ParaIncludeCfgPath:=TSearchPathList.Create;
  3018. ParaIncludePath:=TSearchPathList.Create;
  3019. ParaObjectPath:=TSearchPathList.Create;
  3020. ParaUnitPath:=TSearchPathList.Create;
  3021. ParaLibraryPath:=TSearchPathList.Create;
  3022. ParaFrameworkPath:=TSearchPathList.Create;
  3023. parapackagepath:=TSearchPathList.Create;
  3024. parapackages:=TFPHashObjectList.Create;
  3025. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3026. MacVersionSet:=false;
  3027. paratarget:=system_none;
  3028. paratargetasm:=as_none;
  3029. paratargetdbg:=dbg_none;
  3030. LinkTypeSetExplicitly:=false;
  3031. end;
  3032. destructor TOption.destroy;
  3033. begin
  3034. ParaIncludeCfgPath.Free;
  3035. ParaIncludePath.Free;
  3036. ParaObjectPath.Free;
  3037. ParaUnitPath.Free;
  3038. ParaLibraryPath.Free;
  3039. ParaFrameworkPath.Free;
  3040. parapackagepath.Free;
  3041. ParaPackages.Free;
  3042. end;
  3043. {****************************************************************************
  3044. Callable Routines
  3045. ****************************************************************************}
  3046. function check_configfile(fn:string; var foundfn:string):boolean;
  3047. function CfgFileExists(const fn:string):boolean;
  3048. begin
  3049. Comment(V_Tried,'Configfile search: '+fn);
  3050. CfgFileExists:=FileExists(fn);
  3051. end;
  3052. var
  3053. {$ifdef Unix}
  3054. hs,
  3055. {$endif Unix}
  3056. configpath : string;
  3057. begin
  3058. foundfn:=fn;
  3059. check_configfile:=true;
  3060. { retrieve configpath }
  3061. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3062. {$ifdef Unix}
  3063. if configpath='' then
  3064. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3065. {$endif}
  3066. {
  3067. Order to read configuration file :
  3068. try reading fpc.cfg in :
  3069. 1 - current dir
  3070. 2 - configpath
  3071. 3 - compiler path
  3072. }
  3073. if not FileExists(fn) then
  3074. begin
  3075. {$ifdef Unix}
  3076. hs:=GetEnvironmentVariable('HOME');
  3077. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3078. foundfn:=FixPath(hs,false)+'.'+fn
  3079. else
  3080. {$endif}
  3081. if CfgFileExists(configpath+fn) then
  3082. foundfn:=configpath+fn
  3083. else
  3084. {$ifdef WINDOWS}
  3085. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3086. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3087. else
  3088. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3089. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3090. else
  3091. {$endif WINDOWS}
  3092. {$ifndef Unix}
  3093. if CfgFileExists(exepath+fn) then
  3094. foundfn:=exepath+fn
  3095. else
  3096. {$else}
  3097. if CfgFileExists('/etc/'+fn) then
  3098. foundfn:='/etc/'+fn
  3099. else
  3100. {$endif}
  3101. check_configfile:=false;
  3102. end;
  3103. end;
  3104. procedure read_arguments(cmd:TCmdStr);
  3105. var
  3106. env: ansistring;
  3107. i : tfeature;
  3108. j : longint;
  3109. abi : tabi;
  3110. {$if defined(cpucapabilities)}
  3111. cpuflag : tcpuflags;
  3112. hs : string;
  3113. {$endif defined(cpucapabilities)}
  3114. begin
  3115. option:=coption.create;
  3116. disable_configfile:=false;
  3117. { Non-core target defines }
  3118. Option.TargetOptions(true);
  3119. { get default messagefile }
  3120. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3121. { default configfile can be specified on the commandline,
  3122. remove it first }
  3123. if (cmd<>'') and (cmd[1]='[') then
  3124. begin
  3125. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3126. Delete(cmd,1,pos(']',cmd));
  3127. end
  3128. else
  3129. ppccfg:='fpc.cfg';
  3130. { first pass reading of parameters, only -i -v -T etc.}
  3131. option.firstpass:=true;
  3132. if cmd<>'' then
  3133. option.parsecmd(cmd)
  3134. else
  3135. begin
  3136. option.read_parameters;
  3137. { Write only quickinfo }
  3138. if option.quickinfo<>'' then
  3139. option.writequickinfo;
  3140. end;
  3141. option.firstpass:=false;
  3142. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3143. Option.TargetOptions(true);
  3144. { target is set here, for wince the default app type is gui }
  3145. if target_info.system in systems_wince then
  3146. SetApptype(app_gui)
  3147. else
  3148. SetApptype(apptype);
  3149. { default defines }
  3150. def_system_macro(target_info.shortname);
  3151. def_system_macro('FPC');
  3152. def_system_macro('VER'+version_nr);
  3153. def_system_macro('VER'+version_nr+'_'+release_nr);
  3154. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3155. { Temporary defines, until things settle down }
  3156. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3157. def_system_macro('FPC_HAS_CONSTREF');
  3158. def_system_macro('FPC_STATICRIPFIXED');
  3159. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3160. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3161. { abs(long) is handled internally on all CPUs }
  3162. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3163. {$if defined(x86_64) or defined(powerpc64) or defined(cpuaarch64)}
  3164. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3165. {$endif x86_64 or powerpc64 or aarch64}
  3166. def_system_macro('FPC_HAS_UNICODESTRING');
  3167. def_system_macro('FPC_RTTI_PACKSET1');
  3168. def_system_macro('FPC_HAS_CPSTRING');
  3169. {$ifdef x86_64}
  3170. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3171. {$endif x86_64}
  3172. def_system_macro('FPC_HAS_CEXTENDED');
  3173. def_system_macro('FPC_HAS_RESSTRINITS');
  3174. { these cpus have an inline rol/ror implementaion }
  3175. {$ifdef cpurox}
  3176. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3177. {$endif}
  3178. { these cpus have an inline sar implementaion }
  3179. { currently, all supported CPUs have an internal sar implementation }
  3180. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc) or defined(mips)}
  3181. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3182. { $endif}
  3183. {$ifdef powerpc64}
  3184. def_system_macro('FPC_HAS_LWSYNC');
  3185. {$endif}
  3186. def_system_macro('FPC_HAS_MEMBAR');
  3187. def_system_macro('FPC_SETBASE_USED');
  3188. {$ifdef SUPPORT_GET_FRAME}
  3189. def_system_macro('INTERNAL_BACKTRACE');
  3190. {$endif SUPPORT_GET_FRAME}
  3191. def_system_macro('STR_CONCAT_PROCS');
  3192. {$warnings off}
  3193. if pocall_default = pocall_register then
  3194. def_system_macro('REGCALL');
  3195. {$warnings on}
  3196. { don't remove this, it's also for fpdoc necessary (FK) }
  3197. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3198. { using a case is pretty useless here (FK) }
  3199. { some stuff for TP compatibility }
  3200. {$ifdef i386}
  3201. def_system_macro('CPU86');
  3202. def_system_macro('CPU87');
  3203. def_system_macro('CPU386');
  3204. {$endif}
  3205. { new processor stuff }
  3206. {$ifdef i386}
  3207. def_system_macro('CPUI386');
  3208. def_system_macro('CPU32');
  3209. def_system_macro('CPUX86');
  3210. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3211. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3212. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3213. {$endif}
  3214. {$ifdef m68k}
  3215. def_system_macro('CPU68');
  3216. def_system_macro('CPU68K');
  3217. def_system_macro('CPUM68K');
  3218. def_system_macro('CPU32');
  3219. def_system_macro('FPC_CURRENCY_IS_INT64');
  3220. def_system_macro('FPC_COMP_IS_INT64');
  3221. {$endif}
  3222. {$ifdef powerpc}
  3223. def_system_macro('CPUPOWERPC');
  3224. def_system_macro('CPUPOWERPC32');
  3225. def_system_macro('CPU32');
  3226. def_system_macro('FPC_CURRENCY_IS_INT64');
  3227. def_system_macro('FPC_COMP_IS_INT64');
  3228. {$endif}
  3229. {$ifdef POWERPC64}
  3230. def_system_macro('CPUPOWERPC');
  3231. def_system_macro('CPUPOWERPC64');
  3232. def_system_macro('CPU64');
  3233. def_system_macro('FPC_CURRENCY_IS_INT64');
  3234. def_system_macro('FPC_COMP_IS_INT64');
  3235. {$endif}
  3236. {$ifdef x86_64}
  3237. def_system_macro('CPUX86_64');
  3238. def_system_macro('CPUAMD64');
  3239. def_system_macro('CPU64');
  3240. def_system_macro('CPUX64');
  3241. { not supported for now, afaik (FK)
  3242. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3243. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3244. { normally, win64 doesn't support the legacy fpu }
  3245. if target_info.system=system_x86_64_win64 then
  3246. begin
  3247. def_system_macro('FPC_CURRENCY_IS_INT64');
  3248. def_system_macro('FPC_COMP_IS_INT64');
  3249. end;
  3250. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3251. {$endif}
  3252. {$ifdef sparc}
  3253. def_system_macro('CPUSPARC');
  3254. def_system_macro('CPUSPARC32');
  3255. def_system_macro('CPU32');
  3256. def_system_macro('FPC_CURRENCY_IS_INT64');
  3257. def_system_macro('FPC_COMP_IS_INT64');
  3258. {$endif}
  3259. {$ifdef arm}
  3260. def_system_macro('CPUARM');
  3261. def_system_macro('CPU32');
  3262. def_system_macro('FPC_CURRENCY_IS_INT64');
  3263. def_system_macro('FPC_COMP_IS_INT64');
  3264. {$endif arm}
  3265. {$ifdef avr}
  3266. def_system_macro('CPUAVR');
  3267. def_system_macro('CPU16');
  3268. def_system_macro('FPC_CURRENCY_IS_INT64');
  3269. def_system_macro('FPC_COMP_IS_INT64');
  3270. {$endif avr}
  3271. {$ifdef jvm}
  3272. def_system_macro('CPUJVM');
  3273. def_system_macro('CPU32');
  3274. def_system_macro('FPC_CURRENCY_IS_INT64');
  3275. def_system_macro('FPC_COMP_IS_INT64');
  3276. {$endif jvm}
  3277. {$ifdef mipsel}
  3278. def_system_macro('CPUMIPS');
  3279. def_system_macro('CPUMIPS32');
  3280. def_system_macro('CPUMIPSEL');
  3281. def_system_macro('CPUMIPSEL32');
  3282. def_system_macro('CPU32');
  3283. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3284. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3285. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3286. def_system_macro('FPC_CURRENCY_IS_INT64');
  3287. def_system_macro('FPC_COMP_IS_INT64');
  3288. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3289. { On most systems, locals are accessed relative to base pointer,
  3290. but for MIPS cpu, they are accessed relative to stack pointer.
  3291. This needs adaptation for so low level routines,
  3292. like MethodPointerLocal and related objects unit functions. }
  3293. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3294. {$endif mipsel}
  3295. {$ifdef mipseb}
  3296. def_system_macro('CPUMIPS');
  3297. def_system_macro('CPUMIPS32');
  3298. def_system_macro('CPUMIPSEB');
  3299. def_system_macro('CPUMIPSEB32');
  3300. def_system_macro('CPU32');
  3301. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3302. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3303. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3304. def_system_macro('FPC_CURRENCY_IS_INT64');
  3305. def_system_macro('FPC_COMP_IS_INT64');
  3306. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3307. { See comment above for mipsel }
  3308. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3309. {$endif}
  3310. {$ifdef i8086}
  3311. def_system_macro('CPU86'); { Borland compatibility }
  3312. def_system_macro('CPU87'); { Borland compatibility }
  3313. def_system_macro('CPUI8086');
  3314. def_system_macro('CPU16');
  3315. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3316. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3317. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3318. case init_settings.x86memorymodel of
  3319. mm_tiny: def_system_macro('FPC_MM_TINY');
  3320. mm_small: def_system_macro('FPC_MM_SMALL');
  3321. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3322. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3323. mm_large: def_system_macro('FPC_MM_LARGE');
  3324. mm_huge: def_system_macro('FPC_MM_HUGE');
  3325. end;
  3326. {$endif i8086}
  3327. {$ifdef aarch64}
  3328. def_system_macro('CPUAARCH64');
  3329. def_system_macro('CPU64');
  3330. def_system_macro('FPC_CURRENCY_IS_INT64');
  3331. def_system_macro('FPC_COMP_IS_INT64');
  3332. {$endif aarch64}
  3333. {$if defined(cpu8bitalu)}
  3334. def_system_macro('CPUINT8');
  3335. {$elseif defined(cpu16bitalu)}
  3336. def_system_macro('CPUINT16');
  3337. {$elseif defined(cpu32bitalu)}
  3338. def_system_macro('CPUINT32');
  3339. {$elseif defined(cpu64bitalu)}
  3340. def_system_macro('CPUINT64');
  3341. {$endif defined(cpu64bitalu)}
  3342. if tf_cld in target_info.flags then
  3343. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3344. InternalError(2013092801);
  3345. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3346. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3347. InternalError(2013092801);
  3348. { Set up a default prefix for binutils when cross-compiling }
  3349. if source_info.system<>target_info.system then
  3350. case target_info.system of
  3351. { Use standard Android NDK prefixes }
  3352. system_arm_android:
  3353. utilsprefix:='arm-linux-androideabi-';
  3354. system_i386_android:
  3355. utilsprefix:='i686-linux-android-';
  3356. system_mipsel_android:
  3357. utilsprefix:='mipsel-linux-android-';
  3358. end;
  3359. { Set up default value for the heap }
  3360. if target_info.system in systems_embedded then
  3361. begin
  3362. case target_info.system of
  3363. {$ifdef AVR}
  3364. system_avr_embedded:
  3365. if init_settings.controllertype=ct_avrsim then
  3366. heapsize:=8192
  3367. else
  3368. heapsize:=128;
  3369. {$endif AVR}
  3370. system_arm_embedded:
  3371. heapsize:=256;
  3372. system_mipsel_embedded:
  3373. heapsize:=256;
  3374. else
  3375. heapsize:=256;
  3376. end;
  3377. end;
  3378. { read configuration file }
  3379. if (not disable_configfile) and
  3380. (ppccfg<>'') then
  3381. read_configfile:=check_configfile(ppccfg,ppccfg)
  3382. else
  3383. read_configfile := false;
  3384. { Read commandline and configfile }
  3385. param_file:='';
  3386. { read configfile }
  3387. if read_configfile then
  3388. option.interpret_file(ppccfg);
  3389. { read parameters again to override config file }
  3390. if cmd<>'' then
  3391. option.parsecmd(cmd)
  3392. else
  3393. begin
  3394. { Write help pages if no parameters are passed }
  3395. if (paramcount=0) then
  3396. Option.WriteHelpPages;
  3397. option.read_parameters;
  3398. { Write only quickinfo }
  3399. if option.quickinfo<>'' then
  3400. option.writequickinfo;
  3401. end;
  3402. { check the compatibility of different options and adjust them if necessary
  3403. (and print possible errors)
  3404. }
  3405. option.checkoptionscompatibility;
  3406. { Stop if errors in options }
  3407. if ErrorCount>0 then
  3408. StopOptions(1);
  3409. { endian define }
  3410. case target_info.endian of
  3411. endian_little :
  3412. begin
  3413. def_system_macro('ENDIAN_LITTLE');
  3414. def_system_macro('FPC_LITTLE_ENDIAN');
  3415. end;
  3416. endian_big :
  3417. begin
  3418. def_system_macro('ENDIAN_BIG');
  3419. def_system_macro('FPC_BIG_ENDIAN');
  3420. end;
  3421. end;
  3422. { define abi }
  3423. for abi:=low(tabi) to high(tabi) do
  3424. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3425. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3426. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3427. systems since most code needs to behave the same on both}
  3428. if target_info.abi = abi_eabihf then
  3429. def_system_macro('FPC_ABI_EABI');
  3430. { Write logo }
  3431. if option.ParaLogo then
  3432. option.writelogo;
  3433. { Check file to compile }
  3434. if param_file='' then
  3435. begin
  3436. Message(option_no_source_found);
  3437. StopOptions(1);
  3438. end;
  3439. {$ifndef Unix}
  3440. param_file:=FixFileName(param_file);
  3441. {$endif not unix}
  3442. inputfilepath:=ExtractFilePath(param_file);
  3443. inputfilename:=ExtractFileName(param_file);
  3444. if ExtractFileExt(inputfilename)='' then
  3445. begin
  3446. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3447. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3448. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3449. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3450. else if ((m_mac in current_settings.modeswitches) or
  3451. (tf_p_ext_support in target_info.flags))
  3452. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3453. inputfilename:=ChangeFileExt(inputfilename,pext);
  3454. end;
  3455. { Check output dir }
  3456. if (OutputExeDir<>'') and
  3457. not PathExists(OutputExeDir,false) then
  3458. begin
  3459. Message1(general_e_path_does_not_exist,OutputExeDir);
  3460. StopOptions(1);
  3461. end;
  3462. { Add paths specified with parameters to the searchpaths }
  3463. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3464. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3465. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3466. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3467. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3468. packagesearchpath.addlist(option.parapackagepath,true);
  3469. for j:=0 to option.parapackages.count-1 do
  3470. add_package(option.parapackages.NameOfIndex(j),true,true);
  3471. { add unit environment and exepath to the unit search path }
  3472. if inputfilepath<>'' then
  3473. Unitsearchpath.AddPath(inputfilepath,true);
  3474. if not disable_configfile then
  3475. begin
  3476. env:=GetEnvironmentVariable(target_info.unit_env);
  3477. if env<>'' then
  3478. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3479. end;
  3480. {$ifdef Unix}
  3481. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3482. if fpcdir='' then
  3483. begin
  3484. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3485. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3486. else
  3487. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3488. end;
  3489. {$else unix}
  3490. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3491. if fpcdir='' then
  3492. begin
  3493. fpcdir:=ExePath+'../';
  3494. if not(PathExists(fpcdir+'units',true)) and
  3495. not(PathExists(fpcdir+'rtl',true)) then
  3496. fpcdir:=fpcdir+'../';
  3497. end;
  3498. {$endif unix}
  3499. { first try development RTL, else use the default installation path }
  3500. if not disable_configfile then
  3501. begin
  3502. if PathExists(FpcDir+'rtl',true) then
  3503. if (tf_use_8_3 in Source_Info.Flags) or
  3504. (tf_use_8_3 in Target_Info.Flags) then
  3505. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3506. else
  3507. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3508. else
  3509. if (tf_use_8_3 in Source_Info.Flags) or
  3510. (tf_use_8_3 in Target_Info.Flags) then
  3511. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3512. else
  3513. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3514. end;
  3515. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3516. Do not add it when linking on the target because then we can maybe already find
  3517. .o files that are not for the target }
  3518. if (ExePath<>cfileutl.GetCurrentDir) and
  3519. not(cs_link_on_target in init_settings.globalswitches) then
  3520. UnitSearchPath.AddPath(ExePath,false);
  3521. { Add unit dir to the object and library path }
  3522. objectsearchpath.AddList(unitsearchpath,false);
  3523. librarysearchpath.AddList(unitsearchpath,false);
  3524. {$ifdef llvm}
  3525. { force llvm assembler writer }
  3526. option.paratargetasm:=as_llvm;
  3527. {$endif llvm}
  3528. { maybe override assembler }
  3529. if (option.paratargetasm<>as_none) then
  3530. begin
  3531. if not set_target_asm(option.paratargetasm) then
  3532. begin
  3533. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name);
  3534. set_target_asm(target_info.assemextern);
  3535. Message1(option_asm_forced,target_asm.idtxt);
  3536. end;
  3537. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3538. (option.paratargetdbg<>dbg_none) then
  3539. begin
  3540. Message1(option_confict_asm_debug,
  3541. asminfos[option.paratargetasm]^.idtxt);
  3542. option.paratargetdbg:=dbg_none;
  3543. exclude(init_settings.moduleswitches,cs_debuginfo);
  3544. end;
  3545. end;
  3546. {TOptionheck a second time as we might have changed assembler just above }
  3547. option.checkoptionscompatibility;
  3548. { maybe override debug info format }
  3549. if (option.paratargetdbg<>dbg_none) then
  3550. if not set_target_dbg(option.paratargetdbg) then
  3551. Message(option_w_unsupported_debug_format);
  3552. { switch assembler if it's binary and we got -a on the cmdline }
  3553. if (cs_asm_leave in init_settings.globalswitches) and
  3554. (af_outputbinary in target_asm.flags) then
  3555. begin
  3556. Message(option_switch_bin_to_src_assembler);
  3557. set_target_asm(target_info.assemextern);
  3558. { At least i8086 needs that for nasm and -CX
  3559. which is incompatible with internal linker }
  3560. option.checkoptionscompatibility;
  3561. end;
  3562. { Force use of external linker if there is no
  3563. internal linker or the linking is skipped }
  3564. if not(cs_link_extern in init_settings.globalswitches) and
  3565. ((target_info.link=ld_none) or
  3566. (cs_link_nolink in init_settings.globalswitches)) then
  3567. begin
  3568. include(init_settings.globalswitches,cs_link_extern);
  3569. end;
  3570. { turn off stripping if compiling with debuginfo or profile }
  3571. if (
  3572. (cs_debuginfo in init_settings.moduleswitches) or
  3573. (cs_profile in init_settings.moduleswitches)
  3574. ) and
  3575. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3576. exclude(init_settings.globalswitches,cs_link_strip);
  3577. { set Mac OS X version default macros if not specified explicitly }
  3578. option.MaybeSetDefaultMacVersionMacro;
  3579. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3580. if fpu type not explicitly set }
  3581. if not(option.FPUSetExplicitly) and
  3582. ((target_info.system in [system_arm_wince,system_arm_gba,
  3583. system_m68k_amiga,system_m68k_atari,system_m68k_linux,
  3584. system_arm_nds,system_arm_embedded])
  3585. {$ifdef arm}
  3586. or (target_info.abi=abi_eabi)
  3587. {$endif arm}
  3588. )
  3589. {$if defined(arm) or defined (m68k)}
  3590. or (init_settings.fputype=fpu_soft)
  3591. {$endif arm or m68k}
  3592. then
  3593. begin
  3594. {$ifdef cpufpemu}
  3595. include(init_settings.moduleswitches,cs_fp_emulation);
  3596. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3597. init_settings.fputype:=fpu_soft;
  3598. {$endif cpufpemu}
  3599. end;
  3600. {$ifdef i386}
  3601. case target_info.system of
  3602. system_i386_android:
  3603. begin
  3604. { set default cpu type to PentiumM for Android unless specified otherwise }
  3605. if not option.CPUSetExplicitly then
  3606. init_settings.cputype:=cpu_PentiumM;
  3607. if not option.OptCPUSetExplicitly then
  3608. init_settings.optimizecputype:=cpu_PentiumM;
  3609. { set default fpu type to SSSE3 for Android unless specified otherwise }
  3610. if not option.FPUSetExplicitly then
  3611. init_settings.fputype:=fpu_ssse3;
  3612. end;
  3613. end;
  3614. {$endif i386}
  3615. {$ifdef arm}
  3616. case target_info.system of
  3617. system_arm_darwin:
  3618. begin
  3619. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  3620. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  3621. }
  3622. if not option.CPUSetExplicitly then
  3623. init_settings.cputype:=cpu_armv7;
  3624. if not option.OptCPUSetExplicitly then
  3625. init_settings.optimizecputype:=cpu_armv7;
  3626. if not option.FPUSetExplicitly then
  3627. init_settings.fputype:=fpu_vfpv3;
  3628. end;
  3629. system_arm_android:
  3630. begin
  3631. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3632. if not option.CPUSetExplicitly then
  3633. init_settings.cputype:=cpu_armv5t;
  3634. if not option.OptCPUSetExplicitly then
  3635. init_settings.optimizecputype:=cpu_armv5t;
  3636. end;
  3637. end;
  3638. { ARMHF defaults }
  3639. if (target_info.abi = abi_eabihf) then
  3640. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3641. begin
  3642. {$ifdef CPUARMV6}
  3643. { if the compiler is built for armv6, then
  3644. inherit this setting, e.g. Raspian is armhf but
  3645. only armv6, this makes rebuilds of the compiler
  3646. easier }
  3647. if not option.CPUSetExplicitly then
  3648. init_settings.cputype:=cpu_armv6;
  3649. if not option.OptCPUSetExplicitly then
  3650. init_settings.optimizecputype:=cpu_armv6;
  3651. {$else CPUARMV6}
  3652. if not option.CPUSetExplicitly then
  3653. init_settings.cputype:=cpu_armv7a;
  3654. if not option.OptCPUSetExplicitly then
  3655. init_settings.optimizecputype:=cpu_armv7a;
  3656. {$endif CPUARMV6}
  3657. { Set FPU type }
  3658. if not(option.FPUSetExplicitly) then
  3659. begin
  3660. init_settings.fputype:=fpu_vfpv3_d16
  3661. end
  3662. else
  3663. begin
  3664. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4]) then
  3665. begin
  3666. Message(option_illegal_fpu_eabihf);
  3667. StopOptions(1);
  3668. end;
  3669. end;
  3670. end;
  3671. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3672. begin
  3673. def_system_macro('CPUTHUMB');
  3674. if not option.FPUSetExplicitly then
  3675. init_settings.fputype:=fpu_soft;
  3676. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3677. 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';
  3678. {$else FPC_ARMAL or FPC_ARMHF}
  3679. if target_info.endian=endian_little then
  3680. 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';
  3681. {$endif FPC_ARMAL or FPC_ARMHF}
  3682. end;
  3683. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3684. def_system_macro('CPUTHUMB2');
  3685. {$endif arm}
  3686. {$ifdef jvm}
  3687. { set default CPU type to Dalvik when targeting Android }
  3688. if target_info.system=system_jvm_android32 then
  3689. begin
  3690. if not option.CPUSetExplicitly then
  3691. init_settings.cputype:=cpu_dalvik;
  3692. end;
  3693. {$endif jvm}
  3694. {$ifdef llvm}
  3695. { standard extension for llvm bitcode files }
  3696. target_info.asmext:='.ll';
  3697. { don't generate dwarf cfi, llvm will do that }
  3698. exclude(target_info.flags,tf_needs_dwarf_cfi);
  3699. {$endif llvm}
  3700. {$ifdef mipsel}
  3701. case target_info.system of
  3702. system_mipsel_android:
  3703. begin
  3704. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3705. if not option.CPUSetExplicitly then
  3706. init_settings.cputype:=cpu_mips32;
  3707. if not option.OptCPUSetExplicitly then
  3708. init_settings.optimizecputype:=cpu_mips32;
  3709. if not option.FPUSetExplicitly then
  3710. init_settings.fputype:=fpu_mips2;
  3711. end;
  3712. system_mipsel_embedded:
  3713. begin
  3714. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3715. if not option.CPUSetExplicitly then
  3716. init_settings.cputype:=cpu_pic32mx;
  3717. if not option.OptCPUSetExplicitly then
  3718. init_settings.optimizecputype:=cpu_pic32mx;
  3719. if not option.FPUSetExplicitly then
  3720. init_settings.fputype:=fpu_soft;
  3721. end;
  3722. end;
  3723. {$endif mipsel}
  3724. {$ifdef m68k}
  3725. if init_settings.cputype in cpu_coldfire then
  3726. def_system_macro('CPUCOLDFIRE');
  3727. {$endif m68k}
  3728. { now we can define cpu and fpu type }
  3729. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3730. { Use init_settings cpu type for asm cpu type,
  3731. if asmcputype is cpu_none,
  3732. at least as long as there is no explicit
  3733. option to set it on command line PM }
  3734. if init_settings.asmcputype = cpu_none then
  3735. init_settings.asmcputype:=init_settings.cputype;
  3736. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3737. {$ifdef llvm}
  3738. def_system_macro('CPULLVM');
  3739. {$endif llvm}
  3740. {$if defined(cpucapabilities)}
  3741. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3742. begin
  3743. str(cpuflag,hs);
  3744. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3745. def_system_macro(hs)
  3746. else
  3747. undef_system_macro(hs);
  3748. end;
  3749. {$endif defined(cpucapabilities)}
  3750. if init_settings.fputype<>fpu_none then
  3751. begin
  3752. {$if defined(i386) or defined(i8086)}
  3753. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3754. {$endif}
  3755. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3756. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3757. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  3758. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3759. {$endif}
  3760. {$if defined(m68k)}
  3761. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3762. {$endif}
  3763. {$ifdef x86_64}
  3764. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3765. { normally, win64 doesn't support the legacy fpu }
  3766. if target_info.system=system_x86_64_win64 then
  3767. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3768. else
  3769. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3770. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3771. {$endif}
  3772. end;
  3773. { Enable now for testing }
  3774. {$ifndef DISABLE_TLS_DIRECTORY}
  3775. if target_info.system in systems_windows then
  3776. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3777. {$endif not DISABLE_TLS_DIRECTORY}
  3778. {$ifndef DISABLE_WIN64_SEH}
  3779. if target_info.system=system_x86_64_win64 then
  3780. def_system_macro('FPC_USE_WIN64_SEH');
  3781. {$endif DISABLE_WIN64_SEH}
  3782. {$ifdef TEST_WIN32_SEH}
  3783. if target_info.system=system_i386_win32 then
  3784. def_system_macro('FPC_USE_WIN32_SEH');
  3785. {$endif TEST_WIN32_SEH}
  3786. {$ifdef ARM}
  3787. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3788. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3789. not(cs_fp_emulation in init_settings.moduleswitches) then
  3790. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3791. {$endif ARM}
  3792. { inline bsf/bsr implementation }
  3793. {$if not defined(llvm) and (defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64))}
  3794. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3795. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3796. {$endif}
  3797. { hardware FMA support }
  3798. {$if defined(i386) or defined(x86_64)}
  3799. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  3800. begin
  3801. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  3802. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  3803. end;
  3804. {$endif defined(i386) or defined(x86_64)}
  3805. {$if defined(arm)}
  3806. { it is determined during system unit compilation if clz is used for bsf or not,
  3807. this is not perfect but the current implementation bsf/bsr does not allow another
  3808. solution }
  3809. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3810. ((init_settings.instructionset=is_arm) or
  3811. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3812. begin
  3813. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3814. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3815. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3816. end;
  3817. {$endif}
  3818. {$if defined(powerpc64)}
  3819. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  3820. big endian (unless specified otherwise). As the gcc man page says:
  3821. "Overriding the default ABI requires special system support and is
  3822. likely to fail in spectacular ways" }
  3823. if not option.ABISetExplicitly then
  3824. begin
  3825. if (target_info.abi=abi_powerpc_sysv) and
  3826. (target_info.endian=endian_little) then
  3827. target_info.abi:=abi_powerpc_elfv2
  3828. else
  3829. if (target_info.abi=abi_powerpc_elfv2) and
  3830. (target_info.endian=endian_big) then
  3831. target_info.abi:=abi_powerpc_sysv
  3832. end;
  3833. {$endif}
  3834. {$if defined(powerpc) or defined(powerpc64)}
  3835. { define _CALL_ELF symbol like gcc }
  3836. case target_info.abi of
  3837. abi_powerpc_sysv:
  3838. set_system_compvar('_CALL_ELF','1');
  3839. abi_powerpc_elfv2:
  3840. set_system_compvar('_CALL_ELF','2');
  3841. end;
  3842. {$endif}
  3843. { Section smartlinking conflicts with import sections on Windows }
  3844. if GenerateImportSection and
  3845. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3846. exclude(target_info.flags,tf_smartlink_sections);
  3847. if not option.LinkTypeSetExplicitly then
  3848. set_default_link_type;
  3849. { Default alignment settings,
  3850. 1. load the defaults for the target
  3851. 2. override with generic optimizer setting (little size)
  3852. 3. override with the user specified -Oa }
  3853. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3854. if (cs_opt_size in init_settings.optimizerswitches) then
  3855. begin
  3856. init_settings.alignment.procalign:=1;
  3857. init_settings.alignment.jumpalign:=1;
  3858. init_settings.alignment.loopalign:=1;
  3859. {$ifdef x86}
  3860. { constalignmax=1 keeps the executable and thus the memory foot print small but
  3861. all processors except x86 are really hurt by this or might even crash }
  3862. init_settings.alignment.constalignmax:=1;
  3863. {$endif x86}
  3864. end;
  3865. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3866. set_system_macro('FPC_VERSION',version_nr);
  3867. set_system_macro('FPC_RELEASE',release_nr);
  3868. set_system_macro('FPC_PATCH',patch_nr);
  3869. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3870. if target_info.system in systems_indirect_entry_information then
  3871. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  3872. if not (tf_winlikewidestring in target_info.flags) then
  3873. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3874. if tf_supports_packages in target_info.flags then
  3875. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  3876. if target_info.system in systems_indirect_var_imports then
  3877. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  3878. for i:=low(tfeature) to high(tfeature) do
  3879. if i in features then
  3880. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3881. if ControllerSupport and (target_info.system in systems_embedded) and
  3882. (init_settings.controllertype<>ct_none) then
  3883. begin
  3884. with embedded_controllers[init_settings.controllertype] do
  3885. begin
  3886. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  3887. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  3888. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  3889. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  3890. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  3891. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  3892. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  3893. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  3894. end;
  3895. end;
  3896. option.free;
  3897. Option:=nil;
  3898. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  3899. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal];
  3900. if (tf_safecall_clearstack in target_info.flags) then
  3901. begin
  3902. include (cdecl_pocalls, pocall_safecall);
  3903. include (clearstack_pocalls, pocall_safecall)
  3904. end;
  3905. end;
  3906. initialization
  3907. coption:=toption;
  3908. finalization
  3909. if assigned(option) then
  3910. option.free;
  3911. end.