options.pas 141 KB

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