options.pas 146 KB

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