options.pas 113 KB

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