options.pas 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223
  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. 'T' :
  879. begin
  880. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches) then
  881. IllegalPara(opt);
  882. break;
  883. end;
  884. else
  885. IllegalPara(opt);
  886. end;
  887. inc(j);
  888. end;
  889. end;
  890. 'd' :
  891. if more <> '' then
  892. begin
  893. l:=Pos(':=',more);
  894. if l>0 then
  895. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  896. else
  897. def_system_macro(more);
  898. end;
  899. 'D' :
  900. begin
  901. include(init_settings.globalswitches,cs_link_deffile);
  902. j:=1;
  903. while j<=length(more) do
  904. begin
  905. case more[j] of
  906. 'd' :
  907. begin
  908. description:=Copy(more,j+1,255);
  909. break;
  910. end;
  911. 'v' :
  912. begin
  913. dllversion:=Copy(more,j+1,255);
  914. l:=pos('.',dllversion);
  915. dllminor:=0;
  916. error:=0;
  917. if l>0 then
  918. begin
  919. val(copy(dllversion,l+1,255),minor,error);
  920. if (error=0) and
  921. (minor>=0) and (minor<=$ffff) then
  922. dllminor:=minor
  923. else
  924. if error=0 then
  925. error:=1;
  926. end;
  927. if l=0 then
  928. l:=256;
  929. dllmajor:=1;
  930. if error=0 then
  931. val(copy(dllversion,1,l-1),major,error);
  932. if (error=0) and (major>=0) and (major<=$ffff) then
  933. dllmajor:=major
  934. else
  935. if error=0 then
  936. error:=1;
  937. if error<>0 then
  938. Message1(scan_w_wrong_version_ignored,dllversion);
  939. break;
  940. end;
  941. 'w' :
  942. usewindowapi:=true;
  943. '-' :
  944. begin
  945. exclude(init_settings.globalswitches,cs_link_deffile);
  946. usewindowapi:=false;
  947. end;
  948. else
  949. IllegalPara(opt);
  950. end;
  951. inc(j);
  952. end;
  953. end;
  954. 'e' :
  955. exepath:=FixPath(More,true);
  956. 'E' :
  957. begin
  958. if UnsetBool(More, 0) then
  959. exclude(init_settings.globalswitches,cs_link_nolink)
  960. else
  961. include(init_settings.globalswitches,cs_link_nolink);
  962. end;
  963. 'f' :
  964. begin
  965. if more='PIC' then
  966. begin
  967. if tf_no_pic_supported in target_info.flags then
  968. message(scan_w_pic_ignored)
  969. else
  970. include(init_settings.moduleswitches,cs_create_pic)
  971. end
  972. else
  973. IllegalPara(opt);
  974. end;
  975. 'F' :
  976. begin
  977. if more='' then
  978. IllegalPara(opt);
  979. c:=more[1];
  980. Delete(more,1,1);
  981. DefaultReplacements(More);
  982. case c of
  983. 'a' :
  984. autoloadunits:=more;
  985. 'c' :
  986. begin
  987. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  988. init_settings.sourcecodepage:=CP_UTF8
  989. else if not(cpavailable(more)) then
  990. Message1(option_code_page_not_available,more)
  991. else
  992. init_settings.sourcecodepage:=codepagebyname(more);
  993. include(init_settings.moduleswitches,cs_explicit_codepage);
  994. end;
  995. 'C' :
  996. RCCompiler := More;
  997. 'd' :
  998. if UnsetBool(more, 0) then
  999. init_settings.disabledircache:=false
  1000. else
  1001. init_settings.disabledircache:=true;
  1002. 'D' :
  1003. utilsdirectory:=FixPath(More,true);
  1004. 'e' :
  1005. SetRedirectFile(More);
  1006. 'E' :
  1007. OutputExeDir:=FixPath(More,true);
  1008. 'f' :
  1009. if (target_info.system in systems_darwin) then
  1010. if ispara then
  1011. ParaFrameworkPath.AddPath(More,false)
  1012. else
  1013. frameworksearchpath.AddPath(More,true)
  1014. else
  1015. IllegalPara(opt);
  1016. 'i' :
  1017. begin
  1018. if ispara then
  1019. ParaIncludePath.AddPath(More,false)
  1020. else
  1021. includesearchpath.AddPath(More,true);
  1022. end;
  1023. 'm' :
  1024. begin
  1025. s:=ExtractFileDir(more);
  1026. if TryStrToInt(ExtractFileName(more),j) then
  1027. begin
  1028. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1029. if assigned(unicodemapping) then
  1030. registermapping(unicodemapping)
  1031. else
  1032. IllegalPara(opt);
  1033. end
  1034. else
  1035. IllegalPara(opt);
  1036. end;
  1037. 'g' :
  1038. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1039. 'l' :
  1040. begin
  1041. if ispara then
  1042. ParaLibraryPath.AddPath(sysrootpath,More,false)
  1043. else
  1044. LibrarySearchPath.AddPath(sysrootpath,More,true);
  1045. end;
  1046. 'L' :
  1047. begin
  1048. if More<>'' then
  1049. ParaDynamicLinker:=More
  1050. else
  1051. IllegalPara(opt);
  1052. end;
  1053. 'o' :
  1054. begin
  1055. if ispara then
  1056. ParaObjectPath.AddPath(More,false)
  1057. else
  1058. ObjectSearchPath.AddPath(More,true);
  1059. end;
  1060. 'r' :
  1061. Msgfilename:=More;
  1062. 'R' :
  1063. ResCompiler := More;
  1064. 'u' :
  1065. begin
  1066. if ispara then
  1067. ParaUnitPath.AddPath(More,false)
  1068. else
  1069. unitsearchpath.AddPath(More,true);
  1070. end;
  1071. 'U' :
  1072. OutputUnitDir:=FixPath(More,true);
  1073. 'W',
  1074. 'w':
  1075. begin
  1076. if More<>'' then
  1077. begin
  1078. DefaultReplacements(More);
  1079. D:=ExtractFilePath(More);
  1080. if (D<>'') then
  1081. D:=FixPath(D,True);
  1082. D:=D+ExtractFileName(More);
  1083. if (c='W') then
  1084. WpoFeedbackOutput:=D
  1085. else
  1086. WpoFeedbackInput:=D;
  1087. end
  1088. else
  1089. IllegalPara(opt);
  1090. end;
  1091. else
  1092. IllegalPara(opt);
  1093. end;
  1094. end;
  1095. 'g' :
  1096. begin
  1097. if UnsetBool(More, 0) then
  1098. begin
  1099. exclude(init_settings.moduleswitches,cs_debuginfo);
  1100. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1101. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1102. exclude(init_settings.localswitches,cs_checkpointer);
  1103. localvartrashing := -1;
  1104. end
  1105. else
  1106. begin
  1107. include(init_settings.moduleswitches,cs_debuginfo);
  1108. if paratargetdbg=dbg_none then
  1109. paratargetdbg:=target_info.dbg;
  1110. end;
  1111. if not RelocSectionSetExplicitly then
  1112. RelocSection:=false;
  1113. j:=1;
  1114. while j<=length(more) do
  1115. begin
  1116. case more[j] of
  1117. 'c' :
  1118. begin
  1119. if UnsetBool(More, j) then
  1120. exclude(init_settings.localswitches,cs_checkpointer)
  1121. else if (target_info.system in supported_targets_gc) then
  1122. include(init_settings.localswitches,cs_checkpointer)
  1123. else
  1124. UnsupportedPara('-gc');
  1125. end;
  1126. 'h' :
  1127. begin
  1128. if UnsetBool(More, j) then
  1129. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1130. else
  1131. include(init_settings.globalswitches,cs_use_heaptrc);
  1132. end;
  1133. 'l' :
  1134. begin
  1135. if UnsetBool(More, j) then
  1136. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1137. else
  1138. include(init_settings.globalswitches,cs_use_lineinfo);
  1139. end;
  1140. 'o' :
  1141. begin
  1142. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1143. IllegalPara(opt);
  1144. break;
  1145. end;
  1146. 'p' :
  1147. begin
  1148. if UnsetBool(More, j) then
  1149. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1150. else
  1151. include(init_settings.globalswitches,cs_stabs_preservecase);
  1152. end;
  1153. 's' :
  1154. begin
  1155. paratargetdbg:=dbg_stabs;
  1156. end;
  1157. 't' :
  1158. begin
  1159. if UnsetBool(More, j) then
  1160. localvartrashing := -1
  1161. else
  1162. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1163. end;
  1164. 'v' :
  1165. begin
  1166. if UnsetBool(More, j) then
  1167. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1168. else
  1169. include(init_settings.globalswitches,cs_gdb_valgrind);
  1170. end;
  1171. 'w' :
  1172. begin
  1173. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1174. begin
  1175. case more[j+1] of
  1176. '2': paratargetdbg:=dbg_dwarf2;
  1177. '3': paratargetdbg:=dbg_dwarf3;
  1178. '4': paratargetdbg:=dbg_dwarf4;
  1179. end;
  1180. inc(j);
  1181. end
  1182. else
  1183. paratargetdbg:=dbg_dwarf2;
  1184. end;
  1185. else
  1186. IllegalPara(opt);
  1187. end;
  1188. inc(j);
  1189. end;
  1190. end;
  1191. 'h' :
  1192. begin
  1193. NoPressEnter:=true;
  1194. if (More <> '') and (More [1] = 'F') then
  1195. begin
  1196. FPCHelpLines := true;
  1197. Delete (More, 1, 1);
  1198. FPCBinaryPath := More;
  1199. end;
  1200. WriteHelpPages;
  1201. end;
  1202. 'i' :
  1203. begin
  1204. if More='' then
  1205. WriteInfo
  1206. else
  1207. QuickInfo:=QuickInfo+More;
  1208. end;
  1209. 'I' :
  1210. begin
  1211. if ispara then
  1212. ParaIncludePath.AddPath(More,false)
  1213. else
  1214. includesearchpath.AddPath(More,false);
  1215. end;
  1216. 'k' :
  1217. begin
  1218. if more<>'' then
  1219. ParaLinkOptions:=ParaLinkOptions+' '+More
  1220. else
  1221. IllegalPara(opt);
  1222. end;
  1223. 'l' :
  1224. ParaLogo:=not UnSetBool(more,0);
  1225. 'm' :
  1226. parapreprocess:=not UnSetBool(more,0);
  1227. 'M' :
  1228. begin
  1229. more:=Upper(more);
  1230. if not SetCompileMode(more, true) then
  1231. if not SetCompileModeSwitch(more, true) then
  1232. IllegalPara(opt);
  1233. end;
  1234. 'n' :
  1235. begin
  1236. if More='' then
  1237. disable_configfile:=true
  1238. else
  1239. IllegalPara(opt);
  1240. end;
  1241. 'o' :
  1242. begin
  1243. if More<>'' then
  1244. begin
  1245. DefaultReplacements(More);
  1246. D:=ExtractFilePath(More);
  1247. if (D<>'') then
  1248. OutputExeDir:=FixPath(D,True);
  1249. OutputFileName:=ExtractFileName(More);
  1250. end
  1251. else
  1252. IllegalPara(opt);
  1253. end;
  1254. 'O' :
  1255. begin
  1256. j:=1;
  1257. while j<=length(more) do
  1258. begin
  1259. case more[j] of
  1260. '1' :
  1261. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1262. '2' :
  1263. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1264. '3' :
  1265. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1266. 'a' :
  1267. begin
  1268. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1269. IllegalPara(opt);
  1270. break;
  1271. end;
  1272. 's' :
  1273. include(init_settings.optimizerswitches,cs_opt_size);
  1274. 'p' :
  1275. begin
  1276. if not Setcputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1277. begin
  1278. OptCPUSetExplicitly:=true;
  1279. { Give warning for old i386 switches }
  1280. if (Length(More)-j=1) and
  1281. (More[j+1]>='1') and (More[j+1]<='5')then
  1282. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1283. else
  1284. IllegalPara(opt);
  1285. end;
  1286. break;
  1287. end;
  1288. 'o' :
  1289. begin
  1290. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1291. IllegalPara(opt);
  1292. break;
  1293. end;
  1294. '-' :
  1295. begin
  1296. init_settings.optimizerswitches:=[];
  1297. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1298. end;
  1299. { Obsolete switches }
  1300. 'g' :
  1301. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1302. 'G' :
  1303. Message1(option_obsolete_switch,'-OG');
  1304. 'r' :
  1305. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1306. 'u' :
  1307. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1308. 'w' :
  1309. begin
  1310. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1311. IllegalPara(opt);
  1312. break;
  1313. end;
  1314. 'W' :
  1315. begin
  1316. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1317. IllegalPara(opt);
  1318. break;
  1319. end;
  1320. else
  1321. IllegalPara(opt);
  1322. end;
  1323. inc(j);
  1324. end;
  1325. end;
  1326. 'p' :
  1327. begin
  1328. if UnsetBool(More, 0) then
  1329. begin
  1330. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1331. undef_system_macro('FPC_PROFILE');
  1332. end
  1333. else
  1334. if Length(More)=0 then
  1335. IllegalPara(opt)
  1336. else
  1337. case more[1] of
  1338. 'g' : if UnsetBool(more, 1) then
  1339. begin
  1340. exclude(init_settings.moduleswitches,cs_profile);
  1341. undef_system_macro('FPC_PROFILE');
  1342. end
  1343. else if (target_info.system in supported_targets_pg) then
  1344. begin
  1345. include(init_settings.moduleswitches,cs_profile);
  1346. def_system_macro('FPC_PROFILE');
  1347. end
  1348. else
  1349. UnsupportedPara('-pg');
  1350. else
  1351. IllegalPara(opt);
  1352. end;
  1353. end;
  1354. 'P' : ; { Ignore used by fpc.pp }
  1355. 'R' :
  1356. begin
  1357. if not SetAsmReadMode(More,init_settings.asmmode) then
  1358. IllegalPara(opt);
  1359. end;
  1360. 's' :
  1361. begin
  1362. if UnsetBool(More, 0) then
  1363. begin
  1364. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1365. if more<>'' then
  1366. IllegalPara(opt);
  1367. end
  1368. else
  1369. begin
  1370. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1371. if more='h' then
  1372. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1373. else if more='t' then
  1374. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1375. else if more='r' then
  1376. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1377. else if more<>'' then
  1378. IllegalPara(opt);
  1379. end;
  1380. end;
  1381. 'S' :
  1382. begin
  1383. if more='' then
  1384. IllegalPara(opt);
  1385. if more[1]='I' then
  1386. begin
  1387. if upper(more)='ICOM' then
  1388. init_settings.interfacetype:=it_interfacecom
  1389. else if upper(more)='ICORBA' then
  1390. init_settings.interfacetype:=it_interfacecorba
  1391. else
  1392. IllegalPara(opt);
  1393. end
  1394. else
  1395. begin
  1396. j:=1;
  1397. while j<=length(more) do
  1398. begin
  1399. case more[j] of
  1400. '2' : //an alternative to -Mobjfpc
  1401. SetCompileMode('OBJFPC',true);
  1402. 'a' :
  1403. If UnsetBool(More, j) then
  1404. exclude(init_settings.localswitches,cs_do_assertion)
  1405. else
  1406. include(init_settings.localswitches,cs_do_assertion);
  1407. 'c' :
  1408. If UnsetBool(More, j) then
  1409. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1410. else
  1411. include(init_settings.moduleswitches,cs_support_c_operators);
  1412. 'd' : //an alternative to -Mdelphi
  1413. SetCompileMode('DELPHI',true);
  1414. 'e' :
  1415. begin
  1416. SetErrorFlags(copy(more,j+1,length(more)));
  1417. break;
  1418. end;
  1419. 'f' :
  1420. begin
  1421. inc(j);
  1422. if more[j]='-' then
  1423. begin
  1424. features:=[];
  1425. if length(more)>j then
  1426. IllegalPara(opt);
  1427. end
  1428. else
  1429. begin
  1430. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1431. j:=length(more)
  1432. else
  1433. IllegalPara(opt);
  1434. end;
  1435. end;
  1436. 'g' :
  1437. If UnsetBool(More, j) then
  1438. exclude(init_settings.moduleswitches,cs_support_goto)
  1439. else
  1440. include(init_settings.moduleswitches,cs_support_goto);
  1441. 'h' :
  1442. If UnsetBool(More, j) then
  1443. exclude(init_settings.localswitches,cs_ansistrings)
  1444. else
  1445. include(init_settings.localswitches,cs_ansistrings);
  1446. 'i' :
  1447. If UnsetBool(More, j) then
  1448. exclude(init_settings.localswitches,cs_do_inline)
  1449. else
  1450. include(init_settings.localswitches,cs_do_inline);
  1451. 'k' :
  1452. If UnsetBool(More, j) then
  1453. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1454. else
  1455. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1456. 'm' :
  1457. If UnsetBool(More, j) then
  1458. exclude(init_settings.moduleswitches,cs_support_macro)
  1459. else
  1460. include(init_settings.moduleswitches,cs_support_macro);
  1461. 'o' : //an alternative to -Mtp
  1462. SetCompileMode('TP',true);
  1463. {$ifdef gpc_mode}
  1464. 'p' : //an alternative to -Mgpc
  1465. SetCompileMode('GPC',true);
  1466. {$endif}
  1467. 's' :
  1468. If UnsetBool(More, j) then
  1469. exclude(init_settings.globalswitches,cs_constructor_name)
  1470. else
  1471. include(init_settings.globalswitches,cs_constructor_name);
  1472. 't' :
  1473. Message1(option_obsolete_switch,'-St');
  1474. 'v' :
  1475. If UnsetBool(More, j) then
  1476. exclude(init_settings.globalswitches,cs_support_vectors)
  1477. else
  1478. include(init_settings.globalswitches,cs_support_vectors);
  1479. 'x' :
  1480. If UnsetBool(More, j) then
  1481. exclude(init_settings.globalswitches,cs_support_exceptions)
  1482. else
  1483. include(init_settings.globalswitches,cs_support_exceptions);
  1484. 'y' :
  1485. If UnsetBool(More, j) then
  1486. exclude(init_settings.localswitches,cs_typed_addresses)
  1487. else
  1488. include(init_settings.localswitches,cs_typed_addresses);
  1489. '-' :
  1490. begin
  1491. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1492. cs_support_vectors,cs_load_fpcylix_unit];
  1493. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_ansistrings,
  1494. cs_typed_addresses];
  1495. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1496. cs_support_macro];
  1497. end;
  1498. else
  1499. IllegalPara(opt);
  1500. end;
  1501. inc(j);
  1502. end;
  1503. end;
  1504. end;
  1505. 'T' :
  1506. begin
  1507. more:=Upper(More);
  1508. if paratarget=system_none then
  1509. begin
  1510. { remove old target define }
  1511. TargetOptions(false);
  1512. { load new target }
  1513. paratarget:=find_system_by_string(More);
  1514. if paratarget<>system_none then
  1515. set_target(paratarget)
  1516. else
  1517. IllegalPara(opt);
  1518. { set new define }
  1519. TargetOptions(true);
  1520. end
  1521. else
  1522. if More<>upper(target_info.shortname) then
  1523. Message1(option_target_is_already_set,target_info.shortname);
  1524. end;
  1525. 'u' :
  1526. if more <> '' then
  1527. undef_system_macro(more);
  1528. 'U' :
  1529. begin
  1530. j:=1;
  1531. while j<=length(more) do
  1532. begin
  1533. case more[j] of
  1534. {$ifdef UNITALIASES}
  1535. 'a' :
  1536. begin
  1537. AddUnitAlias(Copy(More,j+1,255));
  1538. break;
  1539. end;
  1540. {$endif UNITALIASES}
  1541. 'n' :
  1542. exclude(init_settings.globalswitches,cs_check_unit_name);
  1543. 'p' :
  1544. begin
  1545. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1546. break;
  1547. end;
  1548. 'r' :
  1549. do_release:=true;
  1550. 's' :
  1551. include(init_settings.moduleswitches,cs_compilesystem);
  1552. '-' :
  1553. begin
  1554. exclude(init_settings.moduleswitches,cs_compilesystem);
  1555. exclude(init_settings.globalswitches,cs_check_unit_name);
  1556. end;
  1557. else
  1558. IllegalPara(opt);
  1559. end;
  1560. inc(j);
  1561. end;
  1562. end;
  1563. 'v' :
  1564. begin
  1565. if not setverbosity(More) then
  1566. IllegalPara(opt);
  1567. end;
  1568. 'V' : ; { Ignore used by fpc }
  1569. 'W' :
  1570. begin
  1571. j:=1;
  1572. while j<=length(More) do
  1573. begin
  1574. case More[j] of
  1575. 'A':
  1576. begin
  1577. if target_info.system in systems_all_windows then
  1578. begin
  1579. if UnsetBool(More, j) then
  1580. apptype:=app_cui
  1581. else
  1582. apptype:=app_native;
  1583. end
  1584. else
  1585. IllegalPara(opt);
  1586. end;
  1587. 'b':
  1588. begin
  1589. if target_info.system in systems_darwin then
  1590. begin
  1591. if UnsetBool(More, j) then
  1592. apptype:=app_cui
  1593. else
  1594. apptype:=app_bundle
  1595. end
  1596. else
  1597. IllegalPara(opt);
  1598. end;
  1599. 'B':
  1600. begin
  1601. if target_info.system in systems_all_windows+systems_symbian then
  1602. begin
  1603. { -WB200000 means set trefered base address
  1604. to $200000, but does not change relocsection boolean
  1605. this way we can create both relocatble and
  1606. non relocatable DLL at a specific base address PM }
  1607. if (length(More)>j) then
  1608. begin
  1609. val('$'+Copy(More,j+1,255),imagebase,code);
  1610. if code<>0 then
  1611. IllegalPara(opt);
  1612. ImageBaseSetExplicity:=true;
  1613. end
  1614. else
  1615. begin
  1616. RelocSection:=true;
  1617. RelocSectionSetExplicitly:=true;
  1618. end;
  1619. break;
  1620. end
  1621. else
  1622. IllegalPara(opt);
  1623. end;
  1624. 'C':
  1625. begin
  1626. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1627. begin
  1628. if UnsetBool(More, j) then
  1629. apptype:=app_gui
  1630. else
  1631. apptype:=app_cui;
  1632. end
  1633. else
  1634. IllegalPara(opt);
  1635. end;
  1636. 'D':
  1637. begin
  1638. if target_info.system in systems_all_windows then
  1639. begin
  1640. UseDeffileForExports:=not UnsetBool(More, j);
  1641. UseDeffileForExportsSetExplicitly:=true;
  1642. end
  1643. else
  1644. IllegalPara(opt);
  1645. end;
  1646. 'e':
  1647. begin
  1648. if (target_info.system in systems_darwin) then
  1649. begin
  1650. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1651. set_target_res(res_ext);
  1652. target_info.resobjext:='.fpcres';
  1653. end
  1654. else
  1655. IllegalPara(opt);
  1656. end;
  1657. 'F':
  1658. begin
  1659. if target_info.system in systems_os2 then
  1660. begin
  1661. if UnsetBool(More, j) then
  1662. apptype:=app_cui
  1663. else
  1664. apptype:=app_fs;
  1665. end
  1666. else
  1667. IllegalPara(opt);
  1668. end;
  1669. 'G':
  1670. begin
  1671. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1672. begin
  1673. if UnsetBool(More, j) then
  1674. apptype:=app_cui
  1675. else
  1676. apptype:=app_gui;
  1677. end
  1678. else
  1679. IllegalPara(opt);
  1680. end;
  1681. 'I':
  1682. begin
  1683. if target_info.system in systems_all_windows then
  1684. begin
  1685. GenerateImportSection:=not UnsetBool(More,j);
  1686. GenerateImportSectionSetExplicitly:=true;
  1687. end
  1688. else
  1689. IllegalPara(opt);
  1690. end;
  1691. 'i':
  1692. begin
  1693. if (target_info.system in systems_darwin) then
  1694. begin
  1695. set_target_res(res_macho);
  1696. target_info.resobjext:=
  1697. targetinfos[target_info.system]^.resobjext;
  1698. end
  1699. else
  1700. IllegalPara(opt);
  1701. end;
  1702. 'M':
  1703. begin
  1704. if (target_info.system in (systems_darwin-[system_i386_iphonesim])) and
  1705. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  1706. begin
  1707. break;
  1708. end
  1709. else
  1710. IllegalPara(opt);
  1711. end;
  1712. 'N':
  1713. begin
  1714. if target_info.system in systems_all_windows then
  1715. begin
  1716. RelocSection:=UnsetBool(More,j);
  1717. RelocSectionSetExplicitly:=true;
  1718. end
  1719. else
  1720. IllegalPara(opt);
  1721. end;
  1722. 'p':
  1723. begin
  1724. {$if defined(arm) or defined(avr)}
  1725. if (target_info.system in systems_embedded) then
  1726. begin
  1727. s:=upper(copy(more,j+1,length(more)-j));
  1728. if not(SetControllerType(s,init_settings.controllertype)) then
  1729. IllegalPara(opt);
  1730. break;
  1731. end
  1732. else
  1733. {$endif defined(arm) or defined(avr)}
  1734. IllegalPara(opt);
  1735. end;
  1736. 'P':
  1737. begin
  1738. if (target_info.system in [system_i386_iphonesim,system_arm_darwin]) and
  1739. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  1740. begin
  1741. break;
  1742. end
  1743. else
  1744. IllegalPara(opt);
  1745. end;
  1746. 'R':
  1747. begin
  1748. if target_info.system in systems_all_windows then
  1749. begin
  1750. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1751. RelocSection:=not UnsetBool(More,j);
  1752. RelocSectionSetExplicitly:=true;
  1753. end
  1754. else
  1755. IllegalPara(opt);
  1756. end;
  1757. 'T':
  1758. begin
  1759. if target_info.system in systems_macos then
  1760. begin
  1761. if UnsetBool(More, j) then
  1762. apptype:=app_cui
  1763. else
  1764. apptype:=app_tool;
  1765. end
  1766. else
  1767. IllegalPara(opt);
  1768. end;
  1769. 'X':
  1770. begin
  1771. if (target_info.system in systems_linux) then
  1772. begin
  1773. if UnsetBool(More, j) then
  1774. exclude(init_settings.moduleswitches,cs_executable_stack)
  1775. else
  1776. include(init_settings.moduleswitches,cs_executable_stack)
  1777. end
  1778. else
  1779. IllegalPara(opt);
  1780. end
  1781. else
  1782. IllegalPara(opt);
  1783. end;
  1784. inc(j);
  1785. end;
  1786. end;
  1787. 'X' :
  1788. begin
  1789. j:=1;
  1790. while j<=length(more) do
  1791. begin
  1792. case More[j] of
  1793. 'c' : Cshared:=TRUE;
  1794. 'd' : Dontlinkstdlibpath:=TRUE;
  1795. 'e' :
  1796. begin
  1797. If UnsetBool(More, j) then
  1798. exclude(init_settings.globalswitches,cs_link_extern)
  1799. else
  1800. include(init_settings.globalswitches,cs_link_extern);
  1801. end;
  1802. 'f' :
  1803. include(init_settings.globalswitches,cs_link_pthread);
  1804. 'g' :
  1805. begin
  1806. If UnsetBool(More, j) then
  1807. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1808. else
  1809. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1810. end;
  1811. 'i' :
  1812. begin
  1813. If UnsetBool(More, j) then
  1814. include(init_settings.globalswitches,cs_link_extern)
  1815. else
  1816. exclude(init_settings.globalswitches,cs_link_extern);
  1817. end;
  1818. 'n' :
  1819. begin
  1820. If UnsetBool(More, j) then
  1821. exclude(init_settings.globalswitches,cs_link_native)
  1822. else
  1823. include(init_settings.globalswitches,cs_link_native);
  1824. end;
  1825. 'm' :
  1826. begin
  1827. If UnsetBool(More, j) then
  1828. exclude(init_settings.globalswitches,cs_link_map)
  1829. else
  1830. include(init_settings.globalswitches,cs_link_map);
  1831. end;
  1832. 'p' : ; { Ignore used by fpc.pp }
  1833. 'r' :
  1834. begin
  1835. if (target_info.system in suppported_targets_x_smallr) then
  1836. begin
  1837. rlinkpath:=Copy(more,2,length(More)-1);
  1838. DefaultReplacements(rlinkpath);
  1839. end
  1840. else
  1841. IgnoredPara('-Xr');
  1842. more:='';
  1843. end;
  1844. 'R' :
  1845. begin
  1846. sysrootpath:=copy(more,2,length(more)-1);
  1847. defaultreplacements(sysrootpath);
  1848. more:='';
  1849. end;
  1850. 's' :
  1851. begin
  1852. If UnsetBool(More, j) then
  1853. exclude(init_settings.globalswitches,cs_link_strip)
  1854. else
  1855. include(init_settings.globalswitches,cs_link_strip);
  1856. end;
  1857. 't' :
  1858. include(init_settings.globalswitches,cs_link_staticflag);
  1859. 'v' :
  1860. begin
  1861. If UnsetBool(More, j) then
  1862. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1863. else
  1864. include(init_settings.globalswitches,cs_link_opt_vtable);
  1865. end;
  1866. 'D' :
  1867. begin
  1868. def_system_macro('FPC_LINK_DYNAMIC');
  1869. undef_system_macro('FPC_LINK_SMART');
  1870. undef_system_macro('FPC_LINK_STATIC');
  1871. exclude(init_settings.globalswitches,cs_link_static);
  1872. exclude(init_settings.globalswitches,cs_link_smart);
  1873. include(init_settings.globalswitches,cs_link_shared);
  1874. LinkTypeSetExplicitly:=true;
  1875. end;
  1876. 'M' :
  1877. begin
  1878. mainaliasname:=Copy(more,2,length(More)-1);
  1879. More:='';
  1880. end;
  1881. 'P' :
  1882. begin
  1883. utilsprefix:=Copy(more,2,length(More)-1);
  1884. DefaultReplacements(utilsprefix);
  1885. More:='';
  1886. end;
  1887. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1888. // these are not aggregable.
  1889. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1890. IllegalPara(opt)
  1891. else
  1892. begin
  1893. case more[j+1] of
  1894. 'A' : begin
  1895. s:=Copy(more,3,length(More)-2);
  1896. if not LinkLibraryAliases.AddDep(s) Then
  1897. IllegalPara(opt);
  1898. end;
  1899. 'O' : begin
  1900. s:=Copy(more,3,length(More)-2);
  1901. if not LinkLibraryOrder.AddWeight(s) Then
  1902. IllegalPara(opt);
  1903. end;
  1904. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1905. else
  1906. IllegalPara(opt);
  1907. end; {case}
  1908. j:=length(more);
  1909. end; {else begin}
  1910. end;
  1911. 'S' :
  1912. begin
  1913. ForceStaticLinking;
  1914. end;
  1915. 'X' :
  1916. begin
  1917. def_system_macro('FPC_LINK_SMART');
  1918. undef_system_macro('FPC_LINK_STATIC');
  1919. undef_system_macro('FPC_LINK_DYNAMIC');
  1920. exclude(init_settings.globalswitches,cs_link_static);
  1921. include(init_settings.globalswitches,cs_link_smart);
  1922. exclude(init_settings.globalswitches,cs_link_shared);
  1923. LinkTypeSetExplicitly:=true;
  1924. end;
  1925. '-' :
  1926. begin
  1927. exclude(init_settings.globalswitches,cs_link_staticflag);
  1928. exclude(init_settings.globalswitches,cs_link_strip);
  1929. exclude(init_settings.globalswitches,cs_link_map);
  1930. set_default_link_type;
  1931. end;
  1932. else
  1933. IllegalPara(opt);
  1934. end;
  1935. inc(j);
  1936. end;
  1937. end;
  1938. else
  1939. IllegalPara(opt);
  1940. end;
  1941. end;
  1942. '@' :
  1943. begin
  1944. Message(option_no_nested_response_file);
  1945. StopOptions(1);
  1946. end;
  1947. else
  1948. begin
  1949. if (length(param_file)<>0) then
  1950. Message2(option_only_one_source_support,param_file,opt);
  1951. param_file:=opt;
  1952. Message1(option_found_file,opt);
  1953. end;
  1954. end;
  1955. end;
  1956. procedure Toption.Interpret_file(const filename : TPathStr);
  1957. procedure RemoveSep(var fn:TPathStr);
  1958. var
  1959. i : longint;
  1960. begin
  1961. i:=0;
  1962. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1963. inc(i);
  1964. Delete(fn,1,i);
  1965. i:=length(fn);
  1966. while (i>0) and (fn[i] in [',',' ',#9]) do
  1967. dec(i);
  1968. fn:=copy(fn,1,i);
  1969. end;
  1970. function GetName(var fn:TPathStr):TPathStr;
  1971. var
  1972. i : longint;
  1973. begin
  1974. i:=0;
  1975. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1976. inc(i);
  1977. GetName:=Copy(fn,1,i);
  1978. Delete(fn,1,i);
  1979. end;
  1980. const
  1981. maxlevel = 15;
  1982. var
  1983. f : text;
  1984. s, tmp,
  1985. opts : TCmdStr;
  1986. skip : array[0..maxlevel] of boolean;
  1987. line,
  1988. level : longint;
  1989. option_read : boolean;
  1990. begin
  1991. { avoid infinite loop }
  1992. Inc(FileLevel);
  1993. Option_read:=false;
  1994. If FileLevel>MaxLevel then
  1995. Message(option_too_many_cfg_files);
  1996. { Maybe It's Directory ?} //Jaro Change:
  1997. if PathExists(filename,false) then
  1998. begin
  1999. Message1(option_config_is_dir,filename);
  2000. exit;
  2001. end;
  2002. { open file }
  2003. Message1(option_using_file,filename);
  2004. assign(f,ExpandFileName(filename));
  2005. {$push}{$I-}
  2006. reset(f);
  2007. {$pop}
  2008. if ioresult<>0 then
  2009. begin
  2010. Message1(option_unable_open_file,filename);
  2011. exit;
  2012. end;
  2013. Message1(option_start_reading_configfile,filename);
  2014. fillchar(skip,sizeof(skip),0);
  2015. level:=0;
  2016. line:=0;
  2017. while not eof(f) do
  2018. begin
  2019. readln(f,opts);
  2020. inc(line);
  2021. RemoveSep(opts);
  2022. if (opts<>'') and (opts[1]<>';') then
  2023. begin
  2024. if opts[1]='#' then
  2025. begin
  2026. Message1(option_interpreting_file_option,opts);
  2027. Delete(opts,1,1);
  2028. s:=upper(GetName(opts));
  2029. if (s='SECTION') then
  2030. begin
  2031. RemoveSep(opts);
  2032. s:=upper(GetName(opts));
  2033. if level=0 then
  2034. skip[level]:=not defined_macro(s) or (s='COMMON');
  2035. end
  2036. else
  2037. if (s='IFDEF') then
  2038. begin
  2039. RemoveSep(opts);
  2040. if Level>=maxlevel then
  2041. begin
  2042. Message2(option_too_many_ifdef,filename,tostr(line));
  2043. stopOptions(1);
  2044. end;
  2045. inc(Level);
  2046. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2047. end
  2048. else
  2049. if (s='IFNDEF') then
  2050. begin
  2051. RemoveSep(opts);
  2052. if Level>=maxlevel then
  2053. begin
  2054. Message2(option_too_many_ifdef,filename,tostr(line));
  2055. stopOptions(1);
  2056. end;
  2057. inc(Level);
  2058. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2059. end
  2060. else
  2061. if (s='ELSE') then
  2062. begin
  2063. if Level=0 then
  2064. begin
  2065. Message2(option_else_without_if,filename,tostr(line));
  2066. stopOptions(1);
  2067. end
  2068. else
  2069. skip[level]:=skip[level-1] or (not skip[level])
  2070. end
  2071. else
  2072. if (s='ENDIF') then
  2073. begin
  2074. skip[level]:=false;
  2075. if Level=0 then
  2076. begin
  2077. Message2(option_too_many_endif,filename,tostr(line));
  2078. stopOptions(1);
  2079. end;
  2080. dec(level);
  2081. end
  2082. else
  2083. if (not skip[level]) then
  2084. begin
  2085. if (s='DEFINE') then
  2086. begin
  2087. RemoveSep(opts);
  2088. tmp:= GetName(opts);
  2089. if tmp <> '' then
  2090. def_system_macro(tmp);
  2091. end
  2092. else
  2093. if (s='UNDEF') then
  2094. begin
  2095. RemoveSep(opts);
  2096. tmp:= GetName(opts);
  2097. if tmp <> '' then
  2098. undef_system_macro(tmp);
  2099. end
  2100. else
  2101. if (s='WRITE') then
  2102. begin
  2103. Delete(opts,1,1);
  2104. WriteLn(opts);
  2105. end
  2106. else
  2107. if (s='INCLUDE') then
  2108. begin
  2109. Delete(opts,1,1);
  2110. Interpret_file(opts);
  2111. end;
  2112. end;
  2113. end
  2114. else
  2115. begin
  2116. if (opts[1]='-') or (opts[1]='@') then
  2117. begin
  2118. if (not skip[level]) then
  2119. interpret_option(opts,false);
  2120. Option_read:=true;
  2121. end
  2122. else
  2123. Message1(option_illegal_para,opts);
  2124. end;
  2125. end;
  2126. end;
  2127. if Level>0 then
  2128. Message(option_too_less_endif);
  2129. if Not Option_read then
  2130. Message1(option_no_option_found,filename)
  2131. else
  2132. Message1(option_end_reading_configfile,filename);
  2133. Close(f);
  2134. Dec(FileLevel);
  2135. end;
  2136. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2137. var
  2138. argstart,
  2139. env,
  2140. pc : pchar;
  2141. arglen : longint;
  2142. quote : set of char;
  2143. hs : TCmdStr;
  2144. begin
  2145. Message1(option_using_env,envname);
  2146. env:=GetEnvPChar(envname);
  2147. pc:=env;
  2148. if assigned(pc) then
  2149. begin
  2150. repeat
  2151. { skip leading spaces }
  2152. while pc^ in [' ',#9,#13] do
  2153. inc(pc);
  2154. case pc^ of
  2155. #0 :
  2156. break;
  2157. '"' :
  2158. begin
  2159. quote:=['"'];
  2160. inc(pc);
  2161. end;
  2162. '''' :
  2163. begin
  2164. quote:=[''''];
  2165. inc(pc);
  2166. end;
  2167. else
  2168. quote:=[' ',#9,#13];
  2169. end;
  2170. { scan until the end of the argument }
  2171. argstart:=pc;
  2172. while (pc^<>#0) and not(pc^ in quote) do
  2173. inc(pc);
  2174. { create argument }
  2175. arglen:=pc-argstart;
  2176. { TODO: FIXME: silent truncation of environment parameters }
  2177. if (arglen > 255) then
  2178. arglen := 255;
  2179. setlength(hs,arglen);
  2180. move(argstart^,hs[1],arglen);
  2181. interpret_option(hs,true);
  2182. { skip quote }
  2183. if pc^ in quote then
  2184. inc(pc);
  2185. until false;
  2186. end
  2187. else
  2188. Message1(option_no_option_found,'(env) '+envname);
  2189. FreeEnvPChar(env);
  2190. end;
  2191. procedure toption.read_parameters;
  2192. var
  2193. opts : TCmdStr;
  2194. paramindex : longint;
  2195. begin
  2196. paramindex:=0;
  2197. while paramindex<paramcount do
  2198. begin
  2199. inc(paramindex);
  2200. opts:=objpas.paramstr(paramindex);
  2201. if length(opts)>0 then
  2202. case opts[1] of
  2203. '@' :
  2204. if not firstpass then
  2205. begin
  2206. Delete(opts,1,1);
  2207. Message1(option_reading_further_from,opts);
  2208. interpret_file(opts);
  2209. end;
  2210. '!' :
  2211. if not firstpass then
  2212. begin
  2213. Delete(opts,1,1);
  2214. Message1(option_reading_further_from,'(env) '+opts);
  2215. interpret_envvar(opts);
  2216. end;
  2217. else
  2218. interpret_option(opts,true);
  2219. end;
  2220. end;
  2221. end;
  2222. procedure toption.parsecmd(cmd:TCmdStr);
  2223. var
  2224. i,ps : longint;
  2225. opts : TCmdStr;
  2226. begin
  2227. while (cmd<>'') do
  2228. begin
  2229. while cmd[1]=' ' do
  2230. delete(cmd,1,1);
  2231. i:=pos(' ',cmd);
  2232. if i=0 then
  2233. i:=2147483647;
  2234. opts:=Copy(cmd,1,i-1);
  2235. Delete(cmd,1,i);
  2236. case opts[1] of
  2237. '@' :
  2238. if not firstpass then
  2239. begin
  2240. Delete(opts,1,1);
  2241. Message1(option_reading_further_from,opts);
  2242. interpret_file(opts);
  2243. end;
  2244. '!' :
  2245. if not firstpass then
  2246. begin
  2247. Delete(opts,1,1);
  2248. Message1(option_reading_further_from,'(env) '+opts);
  2249. interpret_envvar(opts);
  2250. end;
  2251. '"' :
  2252. begin
  2253. Delete(opts,1,1);
  2254. ps:=pos('"',cmd);
  2255. if (i<>256) and (ps>0) then
  2256. begin
  2257. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2258. cmd:=copy(cmd,ps+1,255);
  2259. end;
  2260. interpret_option(opts,true);
  2261. end;
  2262. else
  2263. interpret_option(opts,true);
  2264. end;
  2265. end;
  2266. end;
  2267. procedure toption.writequickinfo;
  2268. var
  2269. s : string;
  2270. i : longint;
  2271. procedure addinfo(const hs:string);
  2272. begin
  2273. if s<>'' then
  2274. s:=s+' '+hs
  2275. else
  2276. s:=hs;
  2277. end;
  2278. begin
  2279. s:='';
  2280. i:=0;
  2281. while (i<length(quickinfo)) do
  2282. begin
  2283. inc(i);
  2284. case quickinfo[i] of
  2285. 'S' :
  2286. begin
  2287. inc(i);
  2288. case quickinfo[i] of
  2289. 'O' :
  2290. addinfo(lower(source_info.shortname));
  2291. 'P' :
  2292. addinfo(source_cpu_string);
  2293. else
  2294. IllegalPara('-i'+QuickInfo);
  2295. end;
  2296. end;
  2297. 'T' :
  2298. begin
  2299. inc(i);
  2300. case quickinfo[i] of
  2301. 'O' :
  2302. addinfo(lower(target_info.shortname));
  2303. 'P' :
  2304. AddInfo(target_cpu_string);
  2305. else
  2306. IllegalPara('-i'+QuickInfo);
  2307. end;
  2308. end;
  2309. 'V' :
  2310. AddInfo(version_string);
  2311. 'W' :
  2312. AddInfo(full_version_string);
  2313. 'D' :
  2314. AddInfo(date_string);
  2315. '_' :
  2316. ;
  2317. else
  2318. IllegalPara('-i'+QuickInfo);
  2319. end;
  2320. end;
  2321. if s<>'' then
  2322. begin
  2323. writeln(s);
  2324. stopoptions(0);
  2325. end;
  2326. end;
  2327. procedure TOption.TargetOptions(def:boolean);
  2328. var
  2329. s : string;
  2330. i : integer;
  2331. target_unsup_features : tfeatures;
  2332. begin
  2333. if def then
  2334. def_system_macro(target_info.shortname)
  2335. else
  2336. undef_system_macro(target_info.shortname);
  2337. s:=target_info.extradefines;
  2338. while (s<>'') do
  2339. begin
  2340. i:=pos(';',s);
  2341. if i=0 then
  2342. i:=length(s)+1;
  2343. if def then
  2344. def_system_macro(Copy(s,1,i-1))
  2345. else
  2346. undef_system_macro(Copy(s,1,i-1));
  2347. delete(s,1,i);
  2348. end;
  2349. if (tf_winlikewidestring in target_info.flags) then
  2350. if def then
  2351. def_system_macro('FPC_WINLIKEWIDESTRING')
  2352. else
  2353. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2354. if (tf_requires_proper_alignment in target_info.flags) then
  2355. if def then
  2356. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2357. else
  2358. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2359. if source_info.system<>target_info.system then
  2360. if def then
  2361. def_system_macro('FPC_CROSSCOMPILING')
  2362. else
  2363. undef_system_macro('FPC_CROSSCOMPILING');
  2364. if source_info.cpu<>target_info.cpu then
  2365. if def then
  2366. def_system_macro('FPC_CPUCROSSCOMPILING')
  2367. else
  2368. def_system_macro('FPC_CPUCROSSCOMPILING');
  2369. if (tf_no_generic_stackcheck in target_info.flags) then
  2370. if def then
  2371. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2372. else
  2373. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2374. { Code generation flags }
  2375. if def and
  2376. (tf_pic_default in target_info.flags) then
  2377. include(init_settings.moduleswitches,cs_create_pic)
  2378. else
  2379. exclude(init_settings.moduleswitches,cs_create_pic);
  2380. { Resources support }
  2381. if (tf_has_winlike_resources in target_info.flags) then
  2382. if def then
  2383. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2384. else
  2385. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2386. { Features }
  2387. case target_info.system of
  2388. system_arm_gba:
  2389. target_unsup_features:=[f_dynlibs];
  2390. system_arm_nds:
  2391. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2392. system_i386_nativent:
  2393. // until these features are implemented, they are disabled in the compiler
  2394. target_unsup_features:=[f_stackcheck];
  2395. else
  2396. target_unsup_features:=[];
  2397. end;
  2398. if def then
  2399. features:=features-target_unsup_features
  2400. else
  2401. features:=features+target_unsup_features;
  2402. end;
  2403. procedure TOption.checkoptionscompatibility;
  2404. begin
  2405. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2406. not(target_info.system in systems_darwin) then
  2407. begin
  2408. { smartlink creation does not yet work with DWARF
  2409. debug info on most targets, but it works in internal assembler }
  2410. if (cs_create_smart in init_settings.moduleswitches) and
  2411. not (af_outputbinary in target_asm.flags) then
  2412. begin
  2413. Message(option_dwarf_smartlink_creation);
  2414. exclude(init_settings.moduleswitches,cs_create_smart);
  2415. end;
  2416. { smart linking does not yet work with DWARF debug info on most targets }
  2417. if (cs_link_smart in init_settings.globalswitches) then
  2418. begin
  2419. Message(option_dwarf_smart_linking);
  2420. ForceStaticLinking;
  2421. end;
  2422. end;
  2423. { external debug info is only supported for DWARF on darwin }
  2424. if (target_info.system in systems_darwin) and
  2425. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2426. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2427. begin
  2428. Message(option_debug_external_unsupported);
  2429. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2430. end;
  2431. end;
  2432. constructor TOption.create;
  2433. begin
  2434. LogoWritten:=false;
  2435. NoPressEnter:=false;
  2436. FirstPass:=false;
  2437. FPUSetExplicitly:=false;
  2438. CPUSetExplicitly:=false;
  2439. OptCPUSetExplicitly:=false;
  2440. FileLevel:=0;
  2441. Quickinfo:='';
  2442. ParaIncludePath:=TSearchPathList.Create;
  2443. ParaObjectPath:=TSearchPathList.Create;
  2444. ParaUnitPath:=TSearchPathList.Create;
  2445. ParaLibraryPath:=TSearchPathList.Create;
  2446. ParaFrameworkPath:=TSearchPathList.Create;
  2447. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2448. MacVersionSet:=false;
  2449. end;
  2450. destructor TOption.destroy;
  2451. begin
  2452. ParaIncludePath.Free;
  2453. ParaObjectPath.Free;
  2454. ParaUnitPath.Free;
  2455. ParaLibraryPath.Free;
  2456. ParaFrameworkPath.Free;
  2457. end;
  2458. {****************************************************************************
  2459. Callable Routines
  2460. ****************************************************************************}
  2461. function check_configfile(const fn:string;var foundfn:string):boolean;
  2462. function CfgFileExists(const fn:string):boolean;
  2463. begin
  2464. Comment(V_Tried,'Configfile search: '+fn);
  2465. CfgFileExists:=FileExists(fn);
  2466. end;
  2467. var
  2468. {$ifdef Unix}
  2469. hs,
  2470. {$endif Unix}
  2471. configpath : string;
  2472. begin
  2473. foundfn:=fn;
  2474. check_configfile:=true;
  2475. { retrieve configpath }
  2476. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2477. {$ifdef Unix}
  2478. if configpath='' then
  2479. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2480. {$endif}
  2481. {
  2482. Order to read configuration file :
  2483. try reading fpc.cfg in :
  2484. 1 - current dir
  2485. 2 - configpath
  2486. 3 - compiler path
  2487. }
  2488. if not FileExists(fn) then
  2489. begin
  2490. {$ifdef Unix}
  2491. hs:=GetEnvironmentVariable('HOME');
  2492. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2493. foundfn:=FixPath(hs,false)+'.'+fn
  2494. else
  2495. {$endif}
  2496. if CfgFileExists(configpath+fn) then
  2497. foundfn:=configpath+fn
  2498. else
  2499. {$ifdef WINDOWS}
  2500. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  2501. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  2502. else
  2503. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  2504. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  2505. else
  2506. {$endif WINDOWS}
  2507. {$ifndef Unix}
  2508. if CfgFileExists(exepath+fn) then
  2509. foundfn:=exepath+fn
  2510. else
  2511. {$else}
  2512. if CfgFileExists('/etc/'+fn) then
  2513. foundfn:='/etc/'+fn
  2514. else
  2515. {$endif}
  2516. check_configfile:=false;
  2517. end;
  2518. end;
  2519. procedure read_arguments(cmd:TCmdStr);
  2520. var
  2521. env: ansistring;
  2522. i : tfeature;
  2523. abi : tabi;
  2524. begin
  2525. option:=coption.create;
  2526. disable_configfile:=false;
  2527. { Non-core target defines }
  2528. Option.TargetOptions(true);
  2529. { get default messagefile }
  2530. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2531. { default configfile can be specified on the commandline,
  2532. remove it first }
  2533. if (cmd<>'') and (cmd[1]='[') then
  2534. begin
  2535. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2536. Delete(cmd,1,pos(']',cmd));
  2537. end
  2538. else
  2539. ppccfg:='fpc.cfg';
  2540. { first pass reading of parameters, only -i -v -T etc.}
  2541. option.firstpass:=true;
  2542. if cmd<>'' then
  2543. option.parsecmd(cmd)
  2544. else
  2545. begin
  2546. option.read_parameters;
  2547. { Write only quickinfo }
  2548. if option.quickinfo<>'' then
  2549. option.writequickinfo;
  2550. end;
  2551. option.firstpass:=false;
  2552. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  2553. Option.TargetOptions(true);
  2554. { target is set here, for wince the default app type is gui }
  2555. if target_info.system in systems_wince then
  2556. apptype:=app_gui;
  2557. { default defines }
  2558. def_system_macro(target_info.shortname);
  2559. def_system_macro('FPC');
  2560. def_system_macro('VER'+version_nr);
  2561. def_system_macro('VER'+version_nr+'_'+release_nr);
  2562. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2563. { Temporary defines, until things settle down }
  2564. def_system_macro('RESSTRSECTIONS');
  2565. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2566. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2567. def_system_macro('FPC_HAS_VARSETS');
  2568. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2569. def_system_macro('FPC_HAS_STR_CURRENCY');
  2570. def_system_macro('FPC_REAL2REAL_FIXED');
  2571. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2572. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2573. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2574. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2575. def_system_macro('FPC_HAS_CONSTREF');
  2576. def_system_macro('FPC_STATICRIPFIXED');
  2577. def_system_macro('FPC_VARIANTCOPY_FIXED');
  2578. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  2579. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2580. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2581. {$endif}
  2582. def_system_macro('FPC_HAS_UNICODESTRING');
  2583. def_system_macro('FPC_RTTI_PACKSET1');
  2584. def_system_macro('FPC_HAS_CPSTRING');
  2585. {$ifdef x86_64}
  2586. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2587. {$endif x86_64}
  2588. def_system_macro('FPC_HAS_CEXTENDED');
  2589. def_system_macro('FPC_HAS_RESSTRINITS');
  2590. { these cpus have an inline rol/ror implementaion }
  2591. {$ifdef cpurox}
  2592. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2593. {$endif}
  2594. { these cpus have an inline sar implementaion }
  2595. { currently, all supported CPUs have an internal sar implementation }
  2596. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc)}
  2597. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2598. { $endif}
  2599. { inline bsf/bsr implementation }
  2600. {$if defined(x86) or defined(x86_64)}
  2601. def_system_macro('FPC_HAS_INTERNAL_BSX');
  2602. {$endif}
  2603. {$ifdef powerpc64}
  2604. def_system_macro('FPC_HAS_LWSYNC');
  2605. {$endif}
  2606. def_system_macro('FPC_HAS_MEMBAR');
  2607. def_system_macro('FPC_SETBASE_USED');
  2608. {$if defined(x86) or defined(arm)}
  2609. def_system_macro('INTERNAL_BACKTRACE');
  2610. {$endif}
  2611. def_system_macro('STR_CONCAT_PROCS');
  2612. {$warnings off}
  2613. if pocall_default = pocall_register then
  2614. def_system_macro('REGCALL');
  2615. {$warnings on}
  2616. { don't remove this, it's also for fpdoc necessary (FK) }
  2617. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2618. { using a case is pretty useless here (FK) }
  2619. { some stuff for TP compatibility }
  2620. {$ifdef i386}
  2621. def_system_macro('CPU86');
  2622. def_system_macro('CPU87');
  2623. def_system_macro('CPU386');
  2624. {$endif}
  2625. { new processor stuff }
  2626. {$ifdef i386}
  2627. def_system_macro('CPUI386');
  2628. def_system_macro('CPU32');
  2629. def_system_macro('CPUX86');
  2630. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2631. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2632. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2633. {$endif}
  2634. {$ifdef m68k}
  2635. def_system_macro('CPU68');
  2636. def_system_macro('CPU68K');
  2637. def_system_macro('CPUM68K');
  2638. def_system_macro('CPU32');
  2639. def_system_macro('FPC_CURRENCY_IS_INT64');
  2640. def_system_macro('FPC_COMP_IS_INT64');
  2641. {$endif}
  2642. {$ifdef ALPHA}
  2643. def_system_macro('CPUALPHA');
  2644. def_system_macro('CPU64');
  2645. {$endif}
  2646. {$ifdef powerpc}
  2647. def_system_macro('CPUPOWERPC');
  2648. def_system_macro('CPUPOWERPC32');
  2649. def_system_macro('CPU32');
  2650. def_system_macro('FPC_CURRENCY_IS_INT64');
  2651. def_system_macro('FPC_COMP_IS_INT64');
  2652. {$endif}
  2653. {$ifdef POWERPC64}
  2654. def_system_macro('CPUPOWERPC');
  2655. def_system_macro('CPUPOWERPC64');
  2656. def_system_macro('CPU64');
  2657. def_system_macro('FPC_CURRENCY_IS_INT64');
  2658. def_system_macro('FPC_COMP_IS_INT64');
  2659. {$endif}
  2660. {$ifdef iA64}
  2661. def_system_macro('CPUIA64');
  2662. def_system_macro('CPU64');
  2663. {$endif}
  2664. {$ifdef x86_64}
  2665. def_system_macro('CPUX86_64');
  2666. def_system_macro('CPUAMD64');
  2667. def_system_macro('CPU64');
  2668. def_system_macro('CPUX64');
  2669. { not supported for now, afaik (FK)
  2670. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2671. { win64 doesn't support the legacy fpu }
  2672. if target_info.system=system_x86_64_win64 then
  2673. begin
  2674. def_system_macro('FPC_CURRENCY_IS_INT64');
  2675. def_system_macro('FPC_COMP_IS_INT64');
  2676. end;
  2677. {$endif}
  2678. {$ifdef sparc}
  2679. def_system_macro('CPUSPARC');
  2680. def_system_macro('CPUSPARC32');
  2681. def_system_macro('CPU32');
  2682. def_system_macro('FPC_CURRENCY_IS_INT64');
  2683. def_system_macro('FPC_COMP_IS_INT64');
  2684. {$endif}
  2685. {$ifdef vis}
  2686. def_system_macro('CPUVIS');
  2687. def_system_macro('CPU32');
  2688. {$endif}
  2689. {$ifdef arm}
  2690. def_system_macro('CPUARM');
  2691. def_system_macro('CPU32');
  2692. def_system_macro('FPC_CURRENCY_IS_INT64');
  2693. def_system_macro('FPC_COMP_IS_INT64');
  2694. {$endif arm}
  2695. {$ifdef avr}
  2696. def_system_macro('CPUAVR');
  2697. def_system_macro('CPU16');
  2698. def_system_macro('FPC_CURRENCY_IS_INT64');
  2699. def_system_macro('FPC_COMP_IS_INT64');
  2700. {$endif avr}
  2701. {$ifdef mips}
  2702. // HIGHLY TENTATIVE, from David Zhang's options.pas. MarkMLl.
  2703. def_system_macro('CPUMIPS');
  2704. def_system_macro('CPUMIPS32');
  2705. def_system_macro('CPU32');
  2706. // def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2707. // def_system_macro('FPC_HAS_TYPE_SINGLE');
  2708. // def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2709. def_system_macro('FPC_CURRENCY_IS_INT64');
  2710. def_system_macro('FPC_COMP_IS_INT64');
  2711. // def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2712. {$endif}
  2713. { read configuration file }
  2714. if (not disable_configfile) and
  2715. (ppccfg<>'') then
  2716. read_configfile:=check_configfile(ppccfg,ppccfg)
  2717. else
  2718. read_configfile := false;
  2719. { Read commandline and configfile }
  2720. param_file:='';
  2721. { read configfile }
  2722. if read_configfile then
  2723. option.interpret_file(ppccfg);
  2724. { read parameters again to override config file }
  2725. if cmd<>'' then
  2726. option.parsecmd(cmd)
  2727. else
  2728. begin
  2729. { Write help pages if no parameters are passed }
  2730. if (paramcount=0) then
  2731. Option.WriteHelpPages;
  2732. option.read_parameters;
  2733. { Write only quickinfo }
  2734. if option.quickinfo<>'' then
  2735. option.writequickinfo;
  2736. end;
  2737. { check the compatibility of different options and adjust them if necessary
  2738. (and print possible errors)
  2739. }
  2740. option.checkoptionscompatibility;
  2741. { Stop if errors in options }
  2742. if ErrorCount>0 then
  2743. StopOptions(1);
  2744. { endian define }
  2745. case target_info.endian of
  2746. endian_little :
  2747. begin
  2748. def_system_macro('ENDIAN_LITTLE');
  2749. def_system_macro('FPC_LITTLE_ENDIAN');
  2750. end;
  2751. endian_big :
  2752. begin
  2753. def_system_macro('ENDIAN_BIG');
  2754. def_system_macro('FPC_BIG_ENDIAN');
  2755. end;
  2756. end;
  2757. { define abi }
  2758. for abi:=low(tabi) to high(tabi) do
  2759. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2760. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2761. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  2762. systems since most code needs to behave the same on both}
  2763. if target_info.abi = abi_eabihf then
  2764. def_system_macro('FPC_ABI_EABI');
  2765. { Write logo }
  2766. if option.ParaLogo then
  2767. option.writelogo;
  2768. { Check file to compile }
  2769. if param_file='' then
  2770. begin
  2771. Message(option_no_source_found);
  2772. StopOptions(1);
  2773. end;
  2774. {$ifndef Unix}
  2775. param_file:=FixFileName(param_file);
  2776. {$endif not unix}
  2777. inputfilepath:=ExtractFilePath(param_file);
  2778. inputfilename:=ExtractFileName(param_file);
  2779. if ExtractFileExt(inputfilename)='' then
  2780. begin
  2781. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2782. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2783. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2784. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2785. else if ((m_mac in current_settings.modeswitches) or
  2786. (tf_p_ext_support in target_info.flags))
  2787. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2788. inputfilename:=ChangeFileExt(inputfilename,pext);
  2789. end;
  2790. { Check output dir }
  2791. if (OutputExeDir<>'') and
  2792. not PathExists(OutputExeDir,false) then
  2793. begin
  2794. Message1(general_e_path_does_not_exist,OutputExeDir);
  2795. StopOptions(1);
  2796. end;
  2797. { Add paths specified with parameters to the searchpaths }
  2798. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2799. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2800. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2801. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2802. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2803. { add unit environment and exepath to the unit search path }
  2804. if inputfilepath<>'' then
  2805. Unitsearchpath.AddPath(inputfilepath,true);
  2806. if not disable_configfile then
  2807. begin
  2808. env:=GetEnvironmentVariable(target_info.unit_env);
  2809. if env<>'' then
  2810. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2811. end;
  2812. {$ifdef Unix}
  2813. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2814. if fpcdir='' then
  2815. begin
  2816. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2817. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2818. else
  2819. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2820. end;
  2821. {$else unix}
  2822. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2823. if fpcdir='' then
  2824. begin
  2825. fpcdir:=ExePath+'../';
  2826. if not(PathExists(fpcdir+'units',true)) and
  2827. not(PathExists(fpcdir+'rtl',true)) then
  2828. fpcdir:=fpcdir+'../';
  2829. end;
  2830. {$endif unix}
  2831. { first try development RTL, else use the default installation path }
  2832. if not disable_configfile then
  2833. begin
  2834. if PathExists(FpcDir+'rtl',true) then
  2835. if tf_use_8_3 in Source_Info.Flags then
  2836. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2837. else
  2838. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2839. else
  2840. if tf_use_8_3 in Source_Info.Flags then
  2841. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2842. else
  2843. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2844. end;
  2845. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2846. Do not add it when linking on the target because then we can maybe already find
  2847. .o files that are not for the target }
  2848. if (ExePath<>GetCurrentDir) and
  2849. not(cs_link_on_target in init_settings.globalswitches) then
  2850. UnitSearchPath.AddPath(ExePath,false);
  2851. { Add unit dir to the object and library path }
  2852. objectsearchpath.AddList(unitsearchpath,false);
  2853. librarysearchpath.AddList(unitsearchpath,false);
  2854. { maybe override assembler }
  2855. if (paratargetasm<>as_none) then
  2856. begin
  2857. if not set_target_asm(paratargetasm) then
  2858. begin
  2859. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2860. set_target_asm(target_info.assemextern);
  2861. Message1(option_asm_forced,target_asm.idtxt);
  2862. end;
  2863. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2864. (paratargetdbg<>dbg_none) then
  2865. begin
  2866. Message1(option_confict_asm_debug,
  2867. asminfos[paratargetasm]^.idtxt);
  2868. paratargetdbg:=dbg_none;
  2869. exclude(init_settings.moduleswitches,cs_debuginfo);
  2870. end;
  2871. end;
  2872. {TOptionheck a second time as we might have changed assembler just above }
  2873. option.checkoptionscompatibility;
  2874. { maybe override debug info format }
  2875. if (paratargetdbg<>dbg_none) then
  2876. set_target_dbg(paratargetdbg);
  2877. { switch assembler if it's binary and we got -a on the cmdline }
  2878. if (cs_asm_leave in init_settings.globalswitches) and
  2879. (af_outputbinary in target_asm.flags) then
  2880. begin
  2881. Message(option_switch_bin_to_src_assembler);
  2882. set_target_asm(target_info.assemextern);
  2883. end;
  2884. { Force use of external linker if there is no
  2885. internal linker or the linking is skipped }
  2886. if not(cs_link_extern in init_settings.globalswitches) and
  2887. (not assigned(target_info.link) or
  2888. (cs_link_nolink in init_settings.globalswitches)) then
  2889. include(init_settings.globalswitches,cs_link_extern);
  2890. { turn off stripping if compiling with debuginfo or profile }
  2891. if (
  2892. (cs_debuginfo in init_settings.moduleswitches) or
  2893. (cs_profile in init_settings.moduleswitches)
  2894. ) and
  2895. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2896. exclude(init_settings.globalswitches,cs_link_strip);
  2897. { set Mac OS X version default macros if not specified explicitly }
  2898. option.MaybeSetDefaultMacVersionMacro;
  2899. { force fpu emulation on arm/wince, arm/gba, arm/embedded, arm/nds and
  2900. arm/darwin if fpu type not explicitly set }
  2901. if not(option.FPUSetExplicitly) and
  2902. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2903. system_m68k_linux,system_arm_nds,system_arm_embedded,system_arm_darwin])
  2904. {$ifdef arm}
  2905. or (target_info.abi=abi_eabi)
  2906. {$endif arm}
  2907. )
  2908. {$ifdef arm}
  2909. or (init_settings.fputype=fpu_soft)
  2910. {$endif arm}
  2911. then
  2912. begin
  2913. {$ifdef cpufpemu}
  2914. include(init_settings.moduleswitches,cs_fp_emulation);
  2915. { cs_fp_emulation and fpu_soft are equal on arm }
  2916. init_settings.fputype:=fpu_soft;
  2917. {$endif cpufpemu}
  2918. end;
  2919. {$ifdef arm}
  2920. if target_info.abi = abi_eabihf then
  2921. begin
  2922. if not(option.FPUSetExplicitly) then
  2923. begin
  2924. init_settings.fputype:=fpu_vfpv3_d16
  2925. end
  2926. else
  2927. begin
  2928. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16]) then
  2929. begin
  2930. Message(option_illegal_fpu_eabihf);
  2931. StopOptions(1);
  2932. end;
  2933. end;
  2934. end;
  2935. {$endif arm}
  2936. {$ifdef arm}
  2937. { set default cpu type to ARMv6 for Darwin unless specified otherwise }
  2938. if (target_info.system=system_arm_darwin) then
  2939. begin
  2940. if not option.CPUSetExplicitly then
  2941. init_settings.cputype:=cpu_armv6;
  2942. if not option.OptCPUSetExplicitly then
  2943. init_settings.optimizecputype:=cpu_armv6;
  2944. end;
  2945. { set default cpu type to ARMv7 for ARMHF unless specified otherwise }
  2946. if (target_info.abi = abi_eabihf) then
  2947. begin
  2948. if not option.CPUSetExplicitly then
  2949. init_settings.cputype:=cpu_armv7;
  2950. if not option.OptCPUSetExplicitly then
  2951. init_settings.optimizecputype:=cpu_armv7;
  2952. end;
  2953. {$endif arm}
  2954. { now we can define cpu and fpu type }
  2955. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2956. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2957. if init_settings.fputype<>fpu_none then
  2958. begin
  2959. {$if defined(i386)}
  2960. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2961. {$endif}
  2962. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2963. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2964. {$if not defined(i386) and not defined(x86_64)}
  2965. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2966. {$endif}
  2967. {$ifdef x86_64}
  2968. { win64 doesn't support the legacy fpu }
  2969. if target_info.system=system_x86_64_win64 then
  2970. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2971. else
  2972. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2973. {$endif}
  2974. end;
  2975. { Enable now for testing }
  2976. {$ifndef DISABLE_TLS_DIRECTORY}
  2977. if target_info.system in systems_windows then
  2978. def_system_macro('FPC_USE_TLS_DIRECTORY');
  2979. {$endif not DISABLE_TLS_DIRECTORY}
  2980. {$ifdef TEST_WIN64_SEH}
  2981. if target_info.system=system_x86_64_win64 then
  2982. def_system_macro('FPC_USE_WIN64_SEH');
  2983. {$endif TEST_WIN64_SEH}
  2984. {$ifdef ARM}
  2985. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2986. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2987. not(cs_fp_emulation in init_settings.moduleswitches) then
  2988. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2989. {$endif ARM}
  2990. { Section smartlinking conflicts with import sections on Windows }
  2991. if GenerateImportSection and
  2992. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2993. exclude(target_info.flags,tf_smartlink_sections);
  2994. if not LinkTypeSetExplicitly then
  2995. set_default_link_type;
  2996. { Default alignment settings,
  2997. 1. load the defaults for the target
  2998. 2. override with generic optimizer setting (little size)
  2999. 3. override with the user specified -Oa }
  3000. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3001. if (cs_opt_size in current_settings.optimizerswitches) then
  3002. begin
  3003. init_settings.alignment.procalign:=1;
  3004. init_settings.alignment.jumpalign:=1;
  3005. init_settings.alignment.loopalign:=1;
  3006. end;
  3007. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3008. set_system_macro('FPC_VERSION',version_nr);
  3009. set_system_macro('FPC_RELEASE',release_nr);
  3010. set_system_macro('FPC_PATCH',patch_nr);
  3011. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3012. if not(target_info.system in systems_windows) then
  3013. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3014. for i:=low(tfeature) to high(tfeature) do
  3015. if i in features then
  3016. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3017. option.free;
  3018. Option:=nil;
  3019. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  3020. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl];
  3021. if (tf_safecall_clearstack in target_info.flags) then
  3022. begin
  3023. include (cdecl_pocalls, pocall_safecall);
  3024. include (clearstack_pocalls, pocall_safecall)
  3025. end;
  3026. end;
  3027. initialization
  3028. coption:=toption;
  3029. finalization
  3030. if assigned(option) then
  3031. option.free;
  3032. end.