options.pas 118 KB

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