options.pas 90 KB

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