options.pas 92 KB

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