options.pas 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791
  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. 'n' :
  1539. begin
  1540. If UnsetBool(More, j) then
  1541. include(init_settings.globalswitches,cs_link_native)
  1542. else
  1543. exclude(init_settings.globalswitches,cs_link_native);
  1544. end;
  1545. 'm' :
  1546. begin
  1547. If UnsetBool(More, j) then
  1548. exclude(init_settings.globalswitches,cs_link_map)
  1549. else
  1550. include(init_settings.globalswitches,cs_link_map);
  1551. end;
  1552. 'p' : ; { Ignore used by fpc.pp }
  1553. 'r' :
  1554. begin
  1555. if (target_info.system in suppported_targets_x_smallr) then
  1556. begin
  1557. rlinkpath:=Copy(more,2,length(More)-1);
  1558. DefaultReplacements(rlinkpath);
  1559. end
  1560. else
  1561. IgnoredPara('-Xr');
  1562. more:='';
  1563. end;
  1564. 'R' :
  1565. begin
  1566. sysrootpath:=copy(more,2,length(more)-1);
  1567. defaultreplacements(sysrootpath);
  1568. more:='';
  1569. end;
  1570. 's' :
  1571. begin
  1572. If UnsetBool(More, j) then
  1573. exclude(init_settings.globalswitches,cs_link_strip)
  1574. else
  1575. include(init_settings.globalswitches,cs_link_strip);
  1576. end;
  1577. 't' :
  1578. include(init_settings.globalswitches,cs_link_staticflag);
  1579. 'v' :
  1580. begin
  1581. If UnsetBool(More, j) then
  1582. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1583. else
  1584. include(init_settings.globalswitches,cs_link_opt_vtable);
  1585. end;
  1586. 'D' :
  1587. begin
  1588. def_system_macro('FPC_LINK_DYNAMIC');
  1589. undef_system_macro('FPC_LINK_SMART');
  1590. undef_system_macro('FPC_LINK_STATIC');
  1591. exclude(init_settings.globalswitches,cs_link_static);
  1592. exclude(init_settings.globalswitches,cs_link_smart);
  1593. include(init_settings.globalswitches,cs_link_shared);
  1594. LinkTypeSetExplicitly:=true;
  1595. end;
  1596. 'M' :
  1597. begin
  1598. mainaliasname:=Copy(more,2,length(More)-1);
  1599. More:='';
  1600. end;
  1601. 'P' :
  1602. begin
  1603. utilsprefix:=Copy(more,2,length(More)-1);
  1604. DefaultReplacements(utilsprefix);
  1605. More:='';
  1606. end;
  1607. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1608. // these are not aggregable.
  1609. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1610. IllegalPara(opt)
  1611. else
  1612. begin
  1613. case more[j+1] of
  1614. 'A' : begin
  1615. s:=Copy(more,3,length(More)-2);
  1616. if not LinkLibraryAliases.AddDep(s) Then
  1617. IllegalPara(opt);
  1618. end;
  1619. 'O' : begin
  1620. s:=Copy(more,3,length(More)-2);
  1621. if not LinkLibraryOrder.AddWeight(s) Then
  1622. IllegalPara(opt);
  1623. end;
  1624. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1625. else
  1626. IllegalPara(opt);
  1627. end; {case}
  1628. j:=length(more);
  1629. end; {else begin}
  1630. end;
  1631. 'S' :
  1632. begin
  1633. ForceStaticLinking;
  1634. end;
  1635. 'X' :
  1636. begin
  1637. def_system_macro('FPC_LINK_SMART');
  1638. undef_system_macro('FPC_LINK_STATIC');
  1639. undef_system_macro('FPC_LINK_DYNAMIC');
  1640. exclude(init_settings.globalswitches,cs_link_static);
  1641. include(init_settings.globalswitches,cs_link_smart);
  1642. exclude(init_settings.globalswitches,cs_link_shared);
  1643. LinkTypeSetExplicitly:=true;
  1644. end;
  1645. '-' :
  1646. begin
  1647. exclude(init_settings.globalswitches,cs_link_staticflag);
  1648. exclude(init_settings.globalswitches,cs_link_strip);
  1649. exclude(init_settings.globalswitches,cs_link_map);
  1650. set_default_link_type;
  1651. end;
  1652. else
  1653. IllegalPara(opt);
  1654. end;
  1655. inc(j);
  1656. end;
  1657. end;
  1658. else
  1659. IllegalPara(opt);
  1660. end;
  1661. end;
  1662. '@' :
  1663. begin
  1664. Message(option_no_nested_response_file);
  1665. StopOptions(1);
  1666. end;
  1667. else
  1668. begin
  1669. if (length(param_file)<>0) then
  1670. Message2(option_only_one_source_support,param_file,opt);
  1671. param_file:=opt;
  1672. Message1(option_found_file,opt);
  1673. end;
  1674. end;
  1675. end;
  1676. procedure Toption.Interpret_file(const filename : string);
  1677. procedure RemoveSep(var fn:string);
  1678. var
  1679. i : longint;
  1680. begin
  1681. i:=0;
  1682. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1683. inc(i);
  1684. Delete(fn,1,i);
  1685. i:=length(fn);
  1686. while (i>0) and (fn[i] in [',',' ',#9]) do
  1687. dec(i);
  1688. fn:=copy(fn,1,i);
  1689. end;
  1690. function GetName(var fn:string):string;
  1691. var
  1692. i : longint;
  1693. begin
  1694. i:=0;
  1695. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1696. inc(i);
  1697. GetName:=Copy(fn,1,i);
  1698. Delete(fn,1,i);
  1699. end;
  1700. const
  1701. maxlevel = 15;
  1702. var
  1703. f : text;
  1704. s, tmp,
  1705. opts : string;
  1706. skip : array[0..maxlevel] of boolean;
  1707. line,
  1708. level : longint;
  1709. option_read : boolean;
  1710. begin
  1711. { avoid infinite loop }
  1712. Inc(FileLevel);
  1713. Option_read:=false;
  1714. If FileLevel>MaxLevel then
  1715. Message(option_too_many_cfg_files);
  1716. { Maybe It's Directory ?} //Jaro Change:
  1717. if PathExists(filename,false) then
  1718. begin
  1719. Message1(option_config_is_dir,filename);
  1720. exit;
  1721. end;
  1722. { open file }
  1723. Message1(option_using_file,filename);
  1724. assign(f,ExpandFileName(filename));
  1725. {$I-}
  1726. reset(f);
  1727. {$I+}
  1728. if ioresult<>0 then
  1729. begin
  1730. Message1(option_unable_open_file,filename);
  1731. exit;
  1732. end;
  1733. Message1(option_start_reading_configfile,filename);
  1734. fillchar(skip,sizeof(skip),0);
  1735. level:=0;
  1736. line:=0;
  1737. while not eof(f) do
  1738. begin
  1739. readln(f,opts);
  1740. inc(line);
  1741. RemoveSep(opts);
  1742. if (opts<>'') and (opts[1]<>';') then
  1743. begin
  1744. if opts[1]='#' then
  1745. begin
  1746. Message1(option_interpreting_file_option,opts);
  1747. Delete(opts,1,1);
  1748. s:=upper(GetName(opts));
  1749. if (s='SECTION') then
  1750. begin
  1751. RemoveSep(opts);
  1752. s:=upper(GetName(opts));
  1753. if level=0 then
  1754. skip[level]:=not defined_macro(s) or (s='COMMON');
  1755. end
  1756. else
  1757. if (s='IFDEF') then
  1758. begin
  1759. RemoveSep(opts);
  1760. if Level>=maxlevel then
  1761. begin
  1762. Message2(option_too_many_ifdef,filename,tostr(line));
  1763. stopOptions(1);
  1764. end;
  1765. inc(Level);
  1766. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1767. end
  1768. else
  1769. if (s='IFNDEF') then
  1770. begin
  1771. RemoveSep(opts);
  1772. if Level>=maxlevel then
  1773. begin
  1774. Message2(option_too_many_ifdef,filename,tostr(line));
  1775. stopOptions(1);
  1776. end;
  1777. inc(Level);
  1778. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1779. end
  1780. else
  1781. if (s='ELSE') then
  1782. begin
  1783. if Level=0 then
  1784. begin
  1785. Message2(option_else_without_if,filename,tostr(line));
  1786. stopOptions(1);
  1787. end
  1788. else
  1789. skip[level]:=skip[level-1] or (not skip[level])
  1790. end
  1791. else
  1792. if (s='ENDIF') then
  1793. begin
  1794. skip[level]:=false;
  1795. if Level=0 then
  1796. begin
  1797. Message2(option_too_many_endif,filename,tostr(line));
  1798. stopOptions(1);
  1799. end;
  1800. dec(level);
  1801. end
  1802. else
  1803. if (not skip[level]) then
  1804. begin
  1805. if (s='DEFINE') then
  1806. begin
  1807. RemoveSep(opts);
  1808. tmp:= GetName(opts);
  1809. if tmp <> '' then
  1810. def_system_macro(tmp);
  1811. end
  1812. else
  1813. if (s='UNDEF') then
  1814. begin
  1815. RemoveSep(opts);
  1816. tmp:= GetName(opts);
  1817. if tmp <> '' then
  1818. undef_system_macro(tmp);
  1819. end
  1820. else
  1821. if (s='WRITE') then
  1822. begin
  1823. Delete(opts,1,1);
  1824. WriteLn(opts);
  1825. end
  1826. else
  1827. if (s='INCLUDE') then
  1828. begin
  1829. Delete(opts,1,1);
  1830. Interpret_file(opts);
  1831. end;
  1832. end;
  1833. end
  1834. else
  1835. begin
  1836. if (opts[1]='-') or (opts[1]='@') then
  1837. begin
  1838. if (not skip[level]) then
  1839. interpret_option(opts,false);
  1840. Option_read:=true;
  1841. end
  1842. else
  1843. Message1(option_illegal_para,opts);
  1844. end;
  1845. end;
  1846. end;
  1847. if Level>0 then
  1848. Message(option_too_less_endif);
  1849. if Not Option_read then
  1850. Message1(option_no_option_found,filename)
  1851. else
  1852. Message1(option_end_reading_configfile,filename);
  1853. Close(f);
  1854. Dec(FileLevel);
  1855. end;
  1856. procedure Toption.Interpret_envvar(const envname : string);
  1857. var
  1858. argstart,
  1859. env,
  1860. pc : pchar;
  1861. arglen : longint;
  1862. quote : set of char;
  1863. hs : string;
  1864. begin
  1865. Message1(option_using_env,envname);
  1866. env:=GetEnvPChar(envname);
  1867. pc:=env;
  1868. if assigned(pc) then
  1869. begin
  1870. repeat
  1871. { skip leading spaces }
  1872. while pc^ in [' ',#9,#13] do
  1873. inc(pc);
  1874. case pc^ of
  1875. #0 :
  1876. break;
  1877. '"' :
  1878. begin
  1879. quote:=['"'];
  1880. inc(pc);
  1881. end;
  1882. '''' :
  1883. begin
  1884. quote:=[''''];
  1885. inc(pc);
  1886. end;
  1887. else
  1888. quote:=[' ',#9,#13];
  1889. end;
  1890. { scan until the end of the argument }
  1891. argstart:=pc;
  1892. while (pc^<>#0) and not(pc^ in quote) do
  1893. inc(pc);
  1894. { create argument }
  1895. arglen:=pc-argstart;
  1896. { TODO: FIXME: silent truncation of environment parameters }
  1897. if (arglen > 255) then
  1898. arglen := 255;
  1899. setlength(hs,arglen);
  1900. move(argstart^,hs[1],arglen);
  1901. interpret_option(hs,true);
  1902. { skip quote }
  1903. if pc^ in quote then
  1904. inc(pc);
  1905. until false;
  1906. end
  1907. else
  1908. Message1(option_no_option_found,'(env) '+envname);
  1909. FreeEnvPChar(env);
  1910. end;
  1911. procedure toption.read_parameters;
  1912. var
  1913. opts : string;
  1914. paramindex : longint;
  1915. begin
  1916. paramindex:=0;
  1917. while paramindex<paramcount do
  1918. begin
  1919. inc(paramindex);
  1920. opts:=system.paramstr(paramindex);
  1921. case opts[1] of
  1922. '@' :
  1923. if not firstpass then
  1924. begin
  1925. Delete(opts,1,1);
  1926. Message1(option_reading_further_from,opts);
  1927. interpret_file(opts);
  1928. end;
  1929. '!' :
  1930. if not firstpass then
  1931. begin
  1932. Delete(opts,1,1);
  1933. Message1(option_reading_further_from,'(env) '+opts);
  1934. interpret_envvar(opts);
  1935. end;
  1936. else
  1937. interpret_option(opts,true);
  1938. end;
  1939. end;
  1940. end;
  1941. procedure toption.parsecmd(cmd:string);
  1942. var
  1943. i,ps : longint;
  1944. opts : string;
  1945. begin
  1946. while (cmd<>'') do
  1947. begin
  1948. while cmd[1]=' ' do
  1949. delete(cmd,1,1);
  1950. i:=pos(' ',cmd);
  1951. if i=0 then
  1952. i:=256;
  1953. opts:=Copy(cmd,1,i-1);
  1954. Delete(cmd,1,i);
  1955. case opts[1] of
  1956. '@' :
  1957. if not firstpass then
  1958. begin
  1959. Delete(opts,1,1);
  1960. Message1(option_reading_further_from,opts);
  1961. interpret_file(opts);
  1962. end;
  1963. '!' :
  1964. if not firstpass then
  1965. begin
  1966. Delete(opts,1,1);
  1967. Message1(option_reading_further_from,'(env) '+opts);
  1968. interpret_envvar(opts);
  1969. end;
  1970. '"' :
  1971. begin
  1972. Delete(opts,1,1);
  1973. ps:=pos('"',cmd);
  1974. if (i<>256) and (ps>0) then
  1975. begin
  1976. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1977. cmd:=copy(cmd,ps+1,255);
  1978. end;
  1979. interpret_option(opts,true);
  1980. end;
  1981. else
  1982. interpret_option(opts,true);
  1983. end;
  1984. end;
  1985. end;
  1986. procedure toption.writequickinfo;
  1987. var
  1988. s : string;
  1989. i : longint;
  1990. procedure addinfo(const hs:string);
  1991. begin
  1992. if s<>'' then
  1993. s:=s+' '+hs
  1994. else
  1995. s:=hs;
  1996. end;
  1997. begin
  1998. s:='';
  1999. i:=0;
  2000. while (i<length(quickinfo)) do
  2001. begin
  2002. inc(i);
  2003. case quickinfo[i] of
  2004. 'S' :
  2005. begin
  2006. inc(i);
  2007. case quickinfo[i] of
  2008. 'O' :
  2009. addinfo(lower(source_info.shortname));
  2010. 'P' :
  2011. addinfo(source_cpu_string);
  2012. else
  2013. IllegalPara('-i'+QuickInfo);
  2014. end;
  2015. end;
  2016. 'T' :
  2017. begin
  2018. inc(i);
  2019. case quickinfo[i] of
  2020. 'O' :
  2021. addinfo(lower(target_info.shortname));
  2022. 'P' :
  2023. AddInfo(target_cpu_string);
  2024. else
  2025. IllegalPara('-i'+QuickInfo);
  2026. end;
  2027. end;
  2028. 'V' :
  2029. AddInfo(version_string);
  2030. 'W' :
  2031. AddInfo(full_version_string);
  2032. 'D' :
  2033. AddInfo(date_string);
  2034. '_' :
  2035. ;
  2036. else
  2037. IllegalPara('-i'+QuickInfo);
  2038. end;
  2039. end;
  2040. if s<>'' then
  2041. begin
  2042. writeln(s);
  2043. stopoptions(0);
  2044. end;
  2045. end;
  2046. procedure TOption.TargetOptions(def:boolean);
  2047. var
  2048. s : string;
  2049. i : integer;
  2050. target_unsup_features : tfeatures;
  2051. begin
  2052. if def then
  2053. def_system_macro(target_info.shortname)
  2054. else
  2055. undef_system_macro(target_info.shortname);
  2056. s:=target_info.extradefines;
  2057. while (s<>'') do
  2058. begin
  2059. i:=pos(';',s);
  2060. if i=0 then
  2061. i:=length(s)+1;
  2062. if def then
  2063. def_system_macro(Copy(s,1,i-1))
  2064. else
  2065. undef_system_macro(Copy(s,1,i-1));
  2066. delete(s,1,i);
  2067. end;
  2068. if (tf_winlikewidestring in target_info.flags) then
  2069. if def then
  2070. def_system_macro('FPC_WINLIKEWIDESTRING')
  2071. else
  2072. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2073. if (tf_requires_proper_alignment in target_info.flags) then
  2074. if def then
  2075. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2076. else
  2077. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2078. if source_info.system<>target_info.system then
  2079. if def then
  2080. def_system_macro('FPC_CROSSCOMPILING')
  2081. else
  2082. undef_system_macro('FPC_CROSSCOMPILING');
  2083. if source_info.cpu<>target_info.cpu then
  2084. if def then
  2085. def_system_macro('FPC_CPUCROSSCOMPILING')
  2086. else
  2087. def_system_macro('FPC_CPUCROSSCOMPILING');
  2088. if (tf_no_generic_stackcheck in target_info.flags) then
  2089. if def then
  2090. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2091. else
  2092. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2093. { Code generation flags }
  2094. if def and
  2095. (tf_pic_default in target_info.flags) then
  2096. include(init_settings.moduleswitches,cs_create_pic)
  2097. else
  2098. exclude(init_settings.moduleswitches,cs_create_pic);
  2099. { Resources support }
  2100. if (tf_has_winlike_resources in target_info.flags) then
  2101. if def then
  2102. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2103. else
  2104. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2105. { Features }
  2106. case target_info.system of
  2107. system_arm_gba:
  2108. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2109. system_arm_nds:
  2110. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs]
  2111. else
  2112. target_unsup_features:=[];
  2113. end;
  2114. if def then
  2115. features:=features-target_unsup_features
  2116. else
  2117. features:=features+target_unsup_features;
  2118. end;
  2119. procedure TOption.checkoptionscompatibility;
  2120. begin
  2121. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2122. not(target_info.system in systems_darwin) then
  2123. begin
  2124. { smart linking does not yet work with DWARF debug info on most targets }
  2125. if (cs_link_smart in init_settings.globalswitches) then
  2126. begin
  2127. Message(option_dwarf_smart_linking);
  2128. ForceStaticLinking;
  2129. end;
  2130. end;
  2131. end;
  2132. constructor TOption.create;
  2133. begin
  2134. LogoWritten:=false;
  2135. NoPressEnter:=false;
  2136. FirstPass:=false;
  2137. FileLevel:=0;
  2138. Quickinfo:='';
  2139. ParaIncludePath:=TSearchPathList.Create;
  2140. ParaObjectPath:=TSearchPathList.Create;
  2141. ParaUnitPath:=TSearchPathList.Create;
  2142. ParaLibraryPath:=TSearchPathList.Create;
  2143. ParaFrameworkPath:=TSearchPathList.Create;
  2144. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2145. end;
  2146. destructor TOption.destroy;
  2147. begin
  2148. ParaIncludePath.Free;
  2149. ParaObjectPath.Free;
  2150. ParaUnitPath.Free;
  2151. ParaLibraryPath.Free;
  2152. ParaFrameworkPath.Free;
  2153. end;
  2154. {****************************************************************************
  2155. Callable Routines
  2156. ****************************************************************************}
  2157. function check_configfile(const fn:string;var foundfn:string):boolean;
  2158. function CfgFileExists(const fn:string):boolean;
  2159. begin
  2160. Comment(V_Tried,'Configfile search: '+fn);
  2161. CfgFileExists:=FileExists(fn);
  2162. end;
  2163. var
  2164. {$ifdef Unix}
  2165. hs,
  2166. {$endif Unix}
  2167. configpath : string;
  2168. begin
  2169. foundfn:=fn;
  2170. check_configfile:=true;
  2171. { retrieve configpath }
  2172. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2173. {$ifdef Unix}
  2174. if configpath='' then
  2175. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2176. {$endif}
  2177. {
  2178. Order to read configuration file :
  2179. try reading fpc.cfg in :
  2180. 1 - current dir
  2181. 2 - configpath
  2182. 3 - compiler path
  2183. }
  2184. if not FileExists(fn) then
  2185. begin
  2186. {$ifdef Unix}
  2187. hs:=GetEnvironmentVariable('HOME');
  2188. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2189. foundfn:=FixPath(hs,false)+'.'+fn
  2190. else
  2191. {$endif}
  2192. if CfgFileExists(configpath+fn) then
  2193. foundfn:=configpath+fn
  2194. else
  2195. {$ifndef Unix}
  2196. if CfgFileExists(exepath+fn) then
  2197. foundfn:=exepath+fn
  2198. else
  2199. {$else}
  2200. if CfgFileExists('/etc/'+fn) then
  2201. foundfn:='/etc/'+fn
  2202. else
  2203. {$endif}
  2204. check_configfile:=false;
  2205. end;
  2206. end;
  2207. procedure read_arguments(cmd:string);
  2208. var
  2209. env: ansistring;
  2210. i : tfeature;
  2211. abi : tabi;
  2212. begin
  2213. option:=coption.create;
  2214. disable_configfile:=false;
  2215. { Non-core target defines }
  2216. Option.TargetOptions(true);
  2217. { get default messagefile }
  2218. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2219. { default configfile can be specified on the commandline,
  2220. remove it first }
  2221. if (cmd<>'') and (cmd[1]='[') then
  2222. begin
  2223. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2224. Delete(cmd,1,pos(']',cmd));
  2225. end
  2226. else
  2227. ppccfg:='fpc.cfg';
  2228. { first pass reading of parameters, only -i -v -T etc.}
  2229. option.firstpass:=true;
  2230. if cmd<>'' then
  2231. option.parsecmd(cmd)
  2232. else
  2233. begin
  2234. option.read_parameters;
  2235. { Write only quickinfo }
  2236. if option.quickinfo<>'' then
  2237. option.writequickinfo;
  2238. end;
  2239. option.firstpass:=false;
  2240. { target is set here, for wince the default app type is gui }
  2241. if target_info.system in system_wince then
  2242. apptype:=app_gui;
  2243. { default defines }
  2244. def_system_macro(target_info.shortname);
  2245. def_system_macro('FPC');
  2246. def_system_macro('VER'+version_nr);
  2247. def_system_macro('VER'+version_nr+'_'+release_nr);
  2248. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2249. { Temporary defines, until things settle down }
  2250. def_system_macro('RESSTRSECTIONS');
  2251. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2252. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2253. def_system_macro('FPC_HAS_VARSETS');
  2254. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2255. def_system_macro('FPC_HAS_STR_CURRENCY');
  2256. def_system_macro('FPC_REAL2REAL_FIXED');
  2257. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2258. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2259. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2260. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2261. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2262. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2263. {$endif}
  2264. def_system_macro('FPC_HAS_UNICODESTRING');
  2265. def_system_macro('FPC_RTTI_PACKSET1');
  2266. {$ifdef x86_64}
  2267. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2268. {$endif x86_64}
  2269. { these cpus have an inline rol/ror implementaion }
  2270. {$if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64)}
  2271. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2272. {$endif}
  2273. {$ifdef powerpc64}
  2274. def_system_macro('FPC_HAS_LWSYNC');
  2275. {$endif}
  2276. def_system_macro('FPC_HAS_MEMBAR');
  2277. def_system_macro('FPC_SETBASE_USED');
  2278. {$if defined(x86) or defined(arm)}
  2279. def_system_macro('INTERNAL_BACKTRACE');
  2280. {$endif}
  2281. def_system_macro('STR_CONCAT_PROCS');
  2282. {$warnings off}
  2283. if pocall_default = pocall_register then
  2284. def_system_macro('REGCALL');
  2285. {$warnings on}
  2286. { don't remove this, it's also for fpdoc necessary (FK) }
  2287. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2288. { using a case is pretty useless here (FK) }
  2289. { some stuff for TP compatibility }
  2290. {$ifdef i386}
  2291. def_system_macro('CPU86');
  2292. def_system_macro('CPU87');
  2293. def_system_macro('CPU386');
  2294. {$endif}
  2295. { new processor stuff }
  2296. {$ifdef i386}
  2297. def_system_macro('CPUI386');
  2298. def_system_macro('CPU32');
  2299. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2300. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2301. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2302. {$endif}
  2303. {$ifdef m68k}
  2304. def_system_macro('CPU68');
  2305. def_system_macro('CPU68K');
  2306. def_system_macro('CPUM68K');
  2307. def_system_macro('CPU32');
  2308. def_system_macro('FPC_CURRENCY_IS_INT64');
  2309. def_system_macro('FPC_COMP_IS_INT64');
  2310. {$endif}
  2311. {$ifdef ALPHA}
  2312. def_system_macro('CPUALPHA');
  2313. def_system_macro('CPU64');
  2314. {$endif}
  2315. {$ifdef powerpc}
  2316. def_system_macro('CPUPOWERPC');
  2317. def_system_macro('CPUPOWERPC32');
  2318. def_system_macro('CPU32');
  2319. def_system_macro('FPC_CURRENCY_IS_INT64');
  2320. def_system_macro('FPC_COMP_IS_INT64');
  2321. {$endif}
  2322. {$ifdef POWERPC64}
  2323. def_system_macro('CPUPOWERPC');
  2324. def_system_macro('CPUPOWERPC64');
  2325. def_system_macro('CPU64');
  2326. def_system_macro('FPC_CURRENCY_IS_INT64');
  2327. def_system_macro('FPC_COMP_IS_INT64');
  2328. {$endif}
  2329. {$ifdef iA64}
  2330. def_system_macro('CPUIA64');
  2331. def_system_macro('CPU64');
  2332. {$endif}
  2333. {$ifdef x86_64}
  2334. def_system_macro('CPUX86_64');
  2335. def_system_macro('CPUAMD64');
  2336. def_system_macro('CPU64');
  2337. { not supported for now, afaik (FK)
  2338. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2339. { win64 doesn't support the legacy fpu }
  2340. if target_info.system=system_x86_64_win64 then
  2341. begin
  2342. def_system_macro('FPC_CURRENCY_IS_INT64');
  2343. def_system_macro('FPC_COMP_IS_INT64');
  2344. end;
  2345. {$endif}
  2346. {$ifdef sparc}
  2347. def_system_macro('CPUSPARC');
  2348. def_system_macro('CPUSPARC32');
  2349. def_system_macro('CPU32');
  2350. def_system_macro('FPC_CURRENCY_IS_INT64');
  2351. def_system_macro('FPC_COMP_IS_INT64');
  2352. {$endif}
  2353. {$ifdef vis}
  2354. def_system_macro('CPUVIS');
  2355. def_system_macro('CPU32');
  2356. {$endif}
  2357. {$ifdef arm}
  2358. def_system_macro('CPUARM');
  2359. def_system_macro('CPU32');
  2360. def_system_macro('FPC_CURRENCY_IS_INT64');
  2361. def_system_macro('FPC_COMP_IS_INT64');
  2362. {$endif arm}
  2363. {$ifdef avr}
  2364. def_system_macro('CPUAVR');
  2365. def_system_macro('CPU16');
  2366. def_system_macro('FPC_CURRENCY_IS_INT64');
  2367. def_system_macro('FPC_COMP_IS_INT64');
  2368. {$endif avr}
  2369. { read configuration file }
  2370. if (not disable_configfile) and
  2371. (ppccfg<>'') then
  2372. read_configfile:=check_configfile(ppccfg,ppccfg)
  2373. else
  2374. read_configfile := false;
  2375. { Read commandline and configfile }
  2376. param_file:='';
  2377. { read configfile }
  2378. if read_configfile then
  2379. option.interpret_file(ppccfg);
  2380. { read parameters again to override config file }
  2381. if cmd<>'' then
  2382. option.parsecmd(cmd)
  2383. else
  2384. begin
  2385. { Write help pages if no parameters are passed }
  2386. if (paramcount=0) then
  2387. Option.WriteHelpPages;
  2388. option.read_parameters;
  2389. { Write only quickinfo }
  2390. if option.quickinfo<>'' then
  2391. option.writequickinfo;
  2392. end;
  2393. { check the compatibility of different options and adjust them if necessary
  2394. (and print possible errors)
  2395. }
  2396. option.checkoptionscompatibility;
  2397. { Stop if errors in options }
  2398. if ErrorCount>0 then
  2399. StopOptions(1);
  2400. { endian define }
  2401. case target_info.endian of
  2402. endian_little :
  2403. begin
  2404. def_system_macro('ENDIAN_LITTLE');
  2405. def_system_macro('FPC_LITTLE_ENDIAN');
  2406. end;
  2407. endian_big :
  2408. begin
  2409. def_system_macro('ENDIAN_BIG');
  2410. def_system_macro('FPC_BIG_ENDIAN');
  2411. end;
  2412. end;
  2413. { define abi }
  2414. for abi:=low(tabi) to high(tabi) do
  2415. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2416. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2417. { Write logo }
  2418. if option.ParaLogo then
  2419. option.writelogo;
  2420. { Check file to compile }
  2421. if param_file='' then
  2422. begin
  2423. Message(option_no_source_found);
  2424. StopOptions(1);
  2425. end;
  2426. {$ifndef Unix}
  2427. param_file:=FixFileName(param_file);
  2428. {$endif not unix}
  2429. inputfilepath:=ExtractFilePath(param_file);
  2430. inputfilename:=ExtractFileName(param_file);
  2431. if ExtractFileExt(inputfilename)='' then
  2432. begin
  2433. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2434. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2435. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2436. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2437. else if ((m_mac in current_settings.modeswitches) or
  2438. (tf_p_ext_support in target_info.flags))
  2439. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2440. inputfilename:=ChangeFileExt(inputfilename,pext);
  2441. end;
  2442. { Check output dir }
  2443. if (OutputExeDir<>'') and
  2444. not PathExists(OutputExeDir,false) then
  2445. begin
  2446. Message1(general_e_path_does_not_exist,OutputExeDir);
  2447. StopOptions(1);
  2448. end;
  2449. { Add paths specified with parameters to the searchpaths }
  2450. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2451. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2452. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2453. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2454. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2455. { add unit environment and exepath to the unit search path }
  2456. if inputfilepath<>'' then
  2457. Unitsearchpath.AddPath(inputfilepath,true);
  2458. if not disable_configfile then
  2459. begin
  2460. env:=GetEnvironmentVariable(target_info.unit_env);
  2461. if env<>'' then
  2462. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2463. end;
  2464. {$ifdef Unix}
  2465. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2466. if fpcdir='' then
  2467. begin
  2468. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2469. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2470. else
  2471. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2472. end;
  2473. {$else unix}
  2474. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2475. if fpcdir='' then
  2476. begin
  2477. fpcdir:=ExePath+'../';
  2478. if not(PathExists(fpcdir+'units',true)) and
  2479. not(PathExists(fpcdir+'rtl',true)) then
  2480. fpcdir:=fpcdir+'../';
  2481. end;
  2482. {$endif unix}
  2483. { first try development RTL, else use the default installation path }
  2484. if not disable_configfile then
  2485. begin
  2486. if PathExists(FpcDir+'rtl',true) then
  2487. if tf_use_8_3 in Source_Info.Flags then
  2488. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2489. else
  2490. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2491. else
  2492. if tf_use_8_3 in Source_Info.Flags then
  2493. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2494. else
  2495. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2496. end;
  2497. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2498. Do not add it when linking on the target because then we can maybe already find
  2499. .o files that are not for the target }
  2500. if (ExePath<>GetCurrentDir) and
  2501. not(cs_link_on_target in init_settings.globalswitches) then
  2502. UnitSearchPath.AddPath(ExePath,false);
  2503. { Add unit dir to the object and library path }
  2504. objectsearchpath.AddList(unitsearchpath,false);
  2505. librarysearchpath.AddList(unitsearchpath,false);
  2506. { maybe override assembler }
  2507. if (paratargetasm<>as_none) then
  2508. begin
  2509. if not set_target_asm(paratargetasm) then
  2510. begin
  2511. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2512. set_target_asm(target_info.assemextern);
  2513. Message1(option_asm_forced,target_asm.idtxt);
  2514. end;
  2515. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2516. (paratargetdbg<>dbg_none) then
  2517. begin
  2518. Message1(option_confict_asm_debug,
  2519. asminfos[paratargetasm]^.idtxt);
  2520. paratargetdbg:=dbg_none;
  2521. exclude(init_settings.moduleswitches,cs_debuginfo);
  2522. end;
  2523. end;
  2524. { maybe override debug info format }
  2525. if (paratargetdbg<>dbg_none) then
  2526. set_target_dbg(paratargetdbg);
  2527. { switch assembler if it's binary and we got -a on the cmdline }
  2528. if (cs_asm_leave in init_settings.globalswitches) and
  2529. (af_outputbinary in target_asm.flags) then
  2530. begin
  2531. Message(option_switch_bin_to_src_assembler);
  2532. set_target_asm(target_info.assemextern);
  2533. end;
  2534. { Force use of external linker if there is no
  2535. internal linker or the linking is skipped }
  2536. if not(cs_link_extern in init_settings.globalswitches) and
  2537. (not assigned(target_info.link) or
  2538. (cs_link_nolink in init_settings.globalswitches)) then
  2539. include(init_settings.globalswitches,cs_link_extern);
  2540. { turn off stripping if compiling with debuginfo or profile }
  2541. if (
  2542. (cs_debuginfo in init_settings.moduleswitches) or
  2543. (cs_profile in init_settings.moduleswitches)
  2544. ) and
  2545. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2546. exclude(init_settings.globalswitches,cs_link_strip);
  2547. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds}
  2548. if (target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2549. system_m68k_linux,system_arm_nds,system_arm_darwin,system_arm_embedded])
  2550. {$ifdef arm}
  2551. or (init_settings.fputype=fpu_soft)
  2552. or (target_info.abi=abi_eabi)
  2553. {$endif arm}
  2554. then
  2555. begin
  2556. {$ifdef cpufpemu}
  2557. include(init_settings.moduleswitches,cs_fp_emulation);
  2558. { cs_fp_emulation and fpu_soft are equal on arm }
  2559. init_settings.fputype:=fpu_soft;
  2560. {$endif cpufpemu}
  2561. end;
  2562. { now we can define cpu and fpu type }
  2563. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2564. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2565. if init_settings.fputype<>fpu_none then
  2566. begin
  2567. {$if defined(i386)}
  2568. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2569. {$endif}
  2570. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2571. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2572. {$if not defined(i386) and not defined(x86_64)}
  2573. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2574. {$endif}
  2575. {$ifdef x86_64}
  2576. { win64 doesn't support the legacy fpu }
  2577. if target_info.system=system_x86_64_win64 then
  2578. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2579. else
  2580. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2581. {$endif}
  2582. end;
  2583. {$ifdef ARM}
  2584. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2585. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2586. not(cs_fp_emulation in init_settings.moduleswitches) then
  2587. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2588. {$endif ARM}
  2589. { Section smartlinking conflicts with import sections on Windows }
  2590. if GenerateImportSection and
  2591. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2592. exclude(target_info.flags,tf_smartlink_sections);
  2593. if not LinkTypeSetExplicitly then
  2594. set_default_link_type;
  2595. { Default alignment settings,
  2596. 1. load the defaults for the target
  2597. 2. override with generic optimizer setting (little size)
  2598. 3. override with the user specified -Oa }
  2599. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2600. if (cs_opt_size in current_settings.optimizerswitches) then
  2601. begin
  2602. init_settings.alignment.procalign:=1;
  2603. init_settings.alignment.jumpalign:=1;
  2604. init_settings.alignment.loopalign:=1;
  2605. end;
  2606. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2607. set_system_macro('FPC_VERSION',version_nr);
  2608. set_system_macro('FPC_RELEASE',release_nr);
  2609. set_system_macro('FPC_PATCH',patch_nr);
  2610. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  2611. if not(target_info.system in system_windows) then
  2612. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  2613. for i:=low(tfeature) to high(tfeature) do
  2614. if i in features then
  2615. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2616. option.free;
  2617. Option:=nil;
  2618. end;
  2619. initialization
  2620. coption:=toption;
  2621. finalization
  2622. if assigned(option) then
  2623. option.free;
  2624. end.