options.pas 121 KB

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