options.pas 118 KB

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