options.pas 92 KB

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