options.pas 103 KB

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