options.pas 90 KB

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