options.pas 90 KB

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