options.pas 117 KB

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