options.pas 118 KB

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