options.pas 139 KB

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