options.pas 118 KB

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