options.pas 120 KB

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