options.pas 105 KB

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