options.pas 115 KB

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