options.pas 115 KB

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