options.pas 118 KB

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