2
0

options.pas 101 KB

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