options.pas 90 KB

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