options.pas 142 KB

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