2
0

options.pas 90 KB

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