options.pas 96 KB

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