options.pas 143 KB

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