options.pas 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514
  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 target_info.system in systems_macos then
  1868. begin
  1869. if UnsetBool(More, j, opt, false) then
  1870. SetApptype(app_cui)
  1871. else
  1872. SetApptype(app_tool);
  1873. end
  1874. else
  1875. IllegalPara(opt);
  1876. end;
  1877. 'X':
  1878. begin
  1879. if (target_info.system in systems_linux) then
  1880. begin
  1881. if UnsetBool(More, j, opt, false) then
  1882. exclude(init_settings.moduleswitches,cs_executable_stack)
  1883. else
  1884. include(init_settings.moduleswitches,cs_executable_stack)
  1885. end
  1886. else
  1887. IllegalPara(opt);
  1888. end;
  1889. else
  1890. IllegalPara(opt);
  1891. end;
  1892. inc(j);
  1893. end;
  1894. end;
  1895. 'X' :
  1896. begin
  1897. j:=1;
  1898. while j<=length(more) do
  1899. begin
  1900. case More[j] of
  1901. 'c' : Cshared:=TRUE;
  1902. 'd' : Dontlinkstdlibpath:=TRUE;
  1903. 'e' :
  1904. begin
  1905. If UnsetBool(More, j, opt, false) then
  1906. exclude(init_settings.globalswitches,cs_link_extern)
  1907. else
  1908. include(init_settings.globalswitches,cs_link_extern);
  1909. end;
  1910. 'f' :
  1911. include(init_settings.globalswitches,cs_link_pthread);
  1912. 'g' :
  1913. begin
  1914. If UnsetBool(More, j, opt, false) then
  1915. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1916. else
  1917. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1918. end;
  1919. 'i' :
  1920. begin
  1921. If UnsetBool(More, j, opt, false) then
  1922. include(init_settings.globalswitches,cs_link_extern)
  1923. else
  1924. exclude(init_settings.globalswitches,cs_link_extern);
  1925. end;
  1926. 'n' :
  1927. begin
  1928. If UnsetBool(More, j, opt, false) then
  1929. exclude(init_settings.globalswitches,cs_link_native)
  1930. else
  1931. include(init_settings.globalswitches,cs_link_native);
  1932. end;
  1933. 'm' :
  1934. begin
  1935. If UnsetBool(More, j, opt, false) then
  1936. exclude(init_settings.globalswitches,cs_link_map)
  1937. else
  1938. include(init_settings.globalswitches,cs_link_map);
  1939. end;
  1940. 'p' : ; { Ignore used by fpc.pp }
  1941. 'r' :
  1942. begin
  1943. if (target_info.system in suppported_targets_x_smallr) then
  1944. begin
  1945. rlinkpath:=Copy(more,2,length(More)-1);
  1946. DefaultReplacements(rlinkpath);
  1947. end
  1948. else
  1949. IgnoredPara('-Xr');
  1950. more:='';
  1951. end;
  1952. 'R' :
  1953. begin
  1954. sysrootpath:=copy(more,2,length(more)-1);
  1955. defaultreplacements(sysrootpath);
  1956. more:='';
  1957. end;
  1958. 's' :
  1959. begin
  1960. If UnsetBool(More, j, opt, false) then
  1961. exclude(init_settings.globalswitches,cs_link_strip)
  1962. else
  1963. include(init_settings.globalswitches,cs_link_strip);
  1964. end;
  1965. 't' :
  1966. include(init_settings.globalswitches,cs_link_staticflag);
  1967. 'v' :
  1968. begin
  1969. If UnsetBool(More, j, opt, false) then
  1970. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1971. else
  1972. include(init_settings.globalswitches,cs_link_opt_vtable);
  1973. end;
  1974. 'D' :
  1975. begin
  1976. def_system_macro('FPC_LINK_DYNAMIC');
  1977. undef_system_macro('FPC_LINK_SMART');
  1978. undef_system_macro('FPC_LINK_STATIC');
  1979. exclude(init_settings.globalswitches,cs_link_static);
  1980. exclude(init_settings.globalswitches,cs_link_smart);
  1981. include(init_settings.globalswitches,cs_link_shared);
  1982. LinkTypeSetExplicitly:=true;
  1983. end;
  1984. 'M' :
  1985. begin
  1986. mainaliasname:=Copy(more,2,length(More)-1);
  1987. More:='';
  1988. end;
  1989. 'P' :
  1990. begin
  1991. utilsprefix:=Copy(more,2,length(More)-1);
  1992. DefaultReplacements(utilsprefix);
  1993. More:='';
  1994. end;
  1995. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1996. // these are not aggregable.
  1997. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1998. IllegalPara(opt)
  1999. else
  2000. begin
  2001. case more[j+1] of
  2002. 'A' : begin
  2003. s:=Copy(more,3,length(More)-2);
  2004. if not LinkLibraryAliases.AddDep(s) Then
  2005. IllegalPara(opt);
  2006. end;
  2007. 'O' : begin
  2008. s:=Copy(more,3,length(More)-2);
  2009. if not LinkLibraryOrder.AddWeight(s) Then
  2010. IllegalPara(opt);
  2011. end;
  2012. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2013. else
  2014. IllegalPara(opt);
  2015. end; {case}
  2016. j:=length(more);
  2017. end; {else begin}
  2018. end;
  2019. 'S' :
  2020. begin
  2021. ForceStaticLinking;
  2022. end;
  2023. 'X' :
  2024. begin
  2025. def_system_macro('FPC_LINK_SMART');
  2026. undef_system_macro('FPC_LINK_STATIC');
  2027. undef_system_macro('FPC_LINK_DYNAMIC');
  2028. exclude(init_settings.globalswitches,cs_link_static);
  2029. include(init_settings.globalswitches,cs_link_smart);
  2030. exclude(init_settings.globalswitches,cs_link_shared);
  2031. LinkTypeSetExplicitly:=true;
  2032. end;
  2033. '-' :
  2034. begin
  2035. exclude(init_settings.globalswitches,cs_link_staticflag);
  2036. exclude(init_settings.globalswitches,cs_link_strip);
  2037. exclude(init_settings.globalswitches,cs_link_map);
  2038. set_default_link_type;
  2039. end;
  2040. else
  2041. IllegalPara(opt);
  2042. end;
  2043. inc(j);
  2044. end;
  2045. end;
  2046. else
  2047. IllegalPara(opt);
  2048. end;
  2049. end;
  2050. '@' :
  2051. begin
  2052. Message(option_no_nested_response_file);
  2053. StopOptions(1);
  2054. end;
  2055. else
  2056. begin
  2057. if (length(param_file)<>0) then
  2058. Message2(option_only_one_source_support,param_file,opt);
  2059. param_file:=opt;
  2060. Message1(option_found_file,opt);
  2061. end;
  2062. end;
  2063. end;
  2064. procedure Toption.Interpret_file(const filename : TPathStr);
  2065. procedure RemoveSep(var fn:TPathStr);
  2066. var
  2067. i : longint;
  2068. begin
  2069. i:=0;
  2070. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2071. inc(i);
  2072. Delete(fn,1,i);
  2073. i:=length(fn);
  2074. while (i>0) and (fn[i] in [',',' ',#9]) do
  2075. dec(i);
  2076. fn:=copy(fn,1,i);
  2077. end;
  2078. function GetName(var fn:TPathStr):TPathStr;
  2079. var
  2080. i : longint;
  2081. begin
  2082. i:=0;
  2083. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2084. inc(i);
  2085. GetName:=Copy(fn,1,i);
  2086. Delete(fn,1,i);
  2087. end;
  2088. const
  2089. maxlevel = 15;
  2090. var
  2091. f : text;
  2092. s, tmp,
  2093. opts : TCmdStr;
  2094. skip : array[0..maxlevel] of boolean;
  2095. line,
  2096. level : longint;
  2097. option_read : boolean;
  2098. oldfilemode : byte;
  2099. ConfigFile: TPathStr;
  2100. begin
  2101. { avoid infinite loop }
  2102. Inc(FileLevel);
  2103. Option_read:=false;
  2104. If FileLevel>MaxLevel then
  2105. Message(option_too_many_cfg_files);
  2106. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2107. ConfigFile := ExpandFileName(filename);
  2108. { Maybe It's Directory ?} //Jaro Change:
  2109. if PathExists(ConfigFile,false) then
  2110. begin
  2111. Message1(option_config_is_dir,filename);
  2112. exit;
  2113. end;
  2114. { open file }
  2115. Message1(option_using_file,filename);
  2116. oldfilemode:=filemode;
  2117. filemode:=0;
  2118. assign(f,ConfigFile);
  2119. {$push}{$I-}
  2120. reset(f);
  2121. {$pop}
  2122. filemode:=oldfilemode;
  2123. if ioresult<>0 then
  2124. begin
  2125. Message1(option_unable_open_file,filename);
  2126. exit;
  2127. end;
  2128. Message1(option_start_reading_configfile,filename);
  2129. fillchar(skip,sizeof(skip),0);
  2130. level:=0;
  2131. line:=0;
  2132. while not eof(f) do
  2133. begin
  2134. readln(f,opts);
  2135. inc(line);
  2136. RemoveSep(opts);
  2137. if (opts<>'') and (opts[1]<>';') then
  2138. begin
  2139. if opts[1]='#' then
  2140. begin
  2141. Message1(option_interpreting_file_option,opts);
  2142. Delete(opts,1,1);
  2143. s:=upper(GetName(opts));
  2144. if (s='SECTION') then
  2145. begin
  2146. RemoveSep(opts);
  2147. s:=upper(GetName(opts));
  2148. if level=0 then
  2149. skip[level]:=not defined_macro(s) or (s='COMMON');
  2150. end
  2151. else
  2152. if (s='IFDEF') then
  2153. begin
  2154. RemoveSep(opts);
  2155. if Level>=maxlevel then
  2156. begin
  2157. Message2(option_too_many_ifdef,filename,tostr(line));
  2158. stopOptions(1);
  2159. end;
  2160. inc(Level);
  2161. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2162. end
  2163. else
  2164. if (s='IFNDEF') then
  2165. begin
  2166. RemoveSep(opts);
  2167. if Level>=maxlevel then
  2168. begin
  2169. Message2(option_too_many_ifdef,filename,tostr(line));
  2170. stopOptions(1);
  2171. end;
  2172. inc(Level);
  2173. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2174. end
  2175. else
  2176. if (s='ELSE') then
  2177. begin
  2178. if Level=0 then
  2179. begin
  2180. Message2(option_else_without_if,filename,tostr(line));
  2181. stopOptions(1);
  2182. end
  2183. else
  2184. skip[level]:=skip[level-1] or (not skip[level])
  2185. end
  2186. else
  2187. if (s='ENDIF') then
  2188. begin
  2189. skip[level]:=false;
  2190. if Level=0 then
  2191. begin
  2192. Message2(option_too_many_endif,filename,tostr(line));
  2193. stopOptions(1);
  2194. end;
  2195. dec(level);
  2196. end
  2197. else
  2198. if (not skip[level]) then
  2199. begin
  2200. if (s='DEFINE') then
  2201. begin
  2202. RemoveSep(opts);
  2203. tmp:= GetName(opts);
  2204. if tmp <> '' then
  2205. def_system_macro(tmp);
  2206. Option_read:=true;
  2207. end
  2208. else
  2209. if (s='UNDEF') then
  2210. begin
  2211. RemoveSep(opts);
  2212. tmp:= GetName(opts);
  2213. if tmp <> '' then
  2214. undef_system_macro(tmp);
  2215. Option_read:=true;
  2216. end
  2217. else
  2218. if (s='WRITE') then
  2219. begin
  2220. Delete(opts,1,1);
  2221. WriteLn(opts);
  2222. Option_read:=true;
  2223. end
  2224. else
  2225. if (s='INCLUDE') then
  2226. begin
  2227. Delete(opts,1,1);
  2228. Interpret_file(opts);
  2229. Option_read:=true;
  2230. end
  2231. else
  2232. if (s='CFGDIR') then
  2233. begin
  2234. Delete(opts,1,1);
  2235. DefaultReplacements(opts);
  2236. ParaIncludeCfgPath.AddPath(opts,false);
  2237. Option_read:=true;
  2238. end;
  2239. end;
  2240. end
  2241. else
  2242. begin
  2243. if (opts[1]='-') or (opts[1]='@') then
  2244. begin
  2245. if (not skip[level]) then
  2246. interpret_option(opts,false);
  2247. Option_read:=true;
  2248. end
  2249. else
  2250. Message1(option_illegal_para,opts);
  2251. end;
  2252. end;
  2253. end;
  2254. if Level>0 then
  2255. Message(option_too_less_endif);
  2256. if Not Option_read then
  2257. Message1(option_no_option_found,filename)
  2258. else
  2259. Message1(option_end_reading_configfile,filename);
  2260. Close(f);
  2261. Dec(FileLevel);
  2262. end;
  2263. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2264. var
  2265. argstart,
  2266. env,
  2267. pc : pchar;
  2268. arglen : longint;
  2269. quote : set of char;
  2270. hs : TCmdStr;
  2271. begin
  2272. Message1(option_using_env,envname);
  2273. env:=GetEnvPChar(envname);
  2274. pc:=env;
  2275. if assigned(pc) then
  2276. begin
  2277. repeat
  2278. { skip leading spaces }
  2279. while pc^ in [' ',#9,#13] do
  2280. inc(pc);
  2281. case pc^ of
  2282. #0 :
  2283. break;
  2284. '"' :
  2285. begin
  2286. quote:=['"'];
  2287. inc(pc);
  2288. end;
  2289. '''' :
  2290. begin
  2291. quote:=[''''];
  2292. inc(pc);
  2293. end;
  2294. else
  2295. quote:=[' ',#9,#13];
  2296. end;
  2297. { scan until the end of the argument }
  2298. argstart:=pc;
  2299. while (pc^<>#0) and not(pc^ in quote) do
  2300. inc(pc);
  2301. { create argument }
  2302. arglen:=pc-argstart;
  2303. { TODO: FIXME: silent truncation of environment parameters }
  2304. if (arglen > 255) then
  2305. arglen := 255;
  2306. setlength(hs,arglen);
  2307. move(argstart^,hs[1],arglen);
  2308. interpret_option(hs,true);
  2309. { skip quote }
  2310. if pc^ in quote then
  2311. inc(pc);
  2312. until false;
  2313. end
  2314. else
  2315. Message1(option_no_option_found,'(env) '+envname);
  2316. FreeEnvPChar(env);
  2317. end;
  2318. procedure toption.read_parameters;
  2319. var
  2320. opts : TCmdStr;
  2321. paramindex : longint;
  2322. begin
  2323. paramindex:=0;
  2324. while paramindex<paramcount do
  2325. begin
  2326. inc(paramindex);
  2327. opts:=objpas.paramstr(paramindex);
  2328. if length(opts)>0 then
  2329. case opts[1] of
  2330. '@' :
  2331. if not firstpass then
  2332. begin
  2333. Delete(opts,1,1);
  2334. Message1(option_reading_further_from,opts);
  2335. interpret_file(opts);
  2336. end;
  2337. '!' :
  2338. if not firstpass then
  2339. begin
  2340. Delete(opts,1,1);
  2341. Message1(option_reading_further_from,'(env) '+opts);
  2342. interpret_envvar(opts);
  2343. end;
  2344. else
  2345. interpret_option(opts,true);
  2346. end;
  2347. end;
  2348. end;
  2349. procedure toption.parsecmd(cmd:TCmdStr);
  2350. var
  2351. i,ps : longint;
  2352. opts : TCmdStr;
  2353. begin
  2354. while (cmd<>'') do
  2355. begin
  2356. while cmd[1]=' ' do
  2357. delete(cmd,1,1);
  2358. i:=pos(' ',cmd);
  2359. if i=0 then
  2360. i:=2147483647;
  2361. opts:=Copy(cmd,1,i-1);
  2362. Delete(cmd,1,i);
  2363. case opts[1] of
  2364. '@' :
  2365. if not firstpass then
  2366. begin
  2367. Delete(opts,1,1);
  2368. Message1(option_reading_further_from,opts);
  2369. interpret_file(opts);
  2370. end;
  2371. '!' :
  2372. if not firstpass then
  2373. begin
  2374. Delete(opts,1,1);
  2375. Message1(option_reading_further_from,'(env) '+opts);
  2376. interpret_envvar(opts);
  2377. end;
  2378. '"' :
  2379. begin
  2380. Delete(opts,1,1);
  2381. ps:=pos('"',cmd);
  2382. if (i<>256) and (ps>0) then
  2383. begin
  2384. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2385. cmd:=copy(cmd,ps+1,255);
  2386. end;
  2387. interpret_option(opts,true);
  2388. end;
  2389. else
  2390. interpret_option(opts,true);
  2391. end;
  2392. end;
  2393. end;
  2394. procedure toption.writequickinfo;
  2395. var
  2396. s : string;
  2397. i : longint;
  2398. procedure addinfo(const hs:string);
  2399. begin
  2400. if s<>'' then
  2401. s:=s+' '+hs
  2402. else
  2403. s:=hs;
  2404. end;
  2405. begin
  2406. s:='';
  2407. i:=0;
  2408. while (i<length(quickinfo)) do
  2409. begin
  2410. inc(i);
  2411. case quickinfo[i] of
  2412. 'S' :
  2413. begin
  2414. inc(i);
  2415. case quickinfo[i] of
  2416. 'O' :
  2417. addinfo(lower(source_info.shortname));
  2418. 'P' :
  2419. addinfo(source_cpu_string);
  2420. else
  2421. IllegalPara('-i'+QuickInfo);
  2422. end;
  2423. end;
  2424. 'T' :
  2425. begin
  2426. inc(i);
  2427. case quickinfo[i] of
  2428. 'O' :
  2429. addinfo(lower(target_info.shortname));
  2430. 'P' :
  2431. AddInfo(target_cpu_string);
  2432. else
  2433. IllegalPara('-i'+QuickInfo);
  2434. end;
  2435. end;
  2436. 'V' :
  2437. AddInfo(version_string);
  2438. 'W' :
  2439. AddInfo(full_version_string);
  2440. 'D' :
  2441. AddInfo(date_string);
  2442. '_' :
  2443. ;
  2444. else
  2445. IllegalPara('-i'+QuickInfo);
  2446. end;
  2447. end;
  2448. if s<>'' then
  2449. begin
  2450. writeln(s);
  2451. stopoptions(0);
  2452. end;
  2453. end;
  2454. procedure TOption.TargetOptions(def:boolean);
  2455. var
  2456. s : string;
  2457. i : integer;
  2458. target_unsup_features : tfeatures;
  2459. begin
  2460. if def then
  2461. def_system_macro(target_info.shortname)
  2462. else
  2463. undef_system_macro(target_info.shortname);
  2464. s:=target_info.extradefines;
  2465. while (s<>'') do
  2466. begin
  2467. i:=pos(';',s);
  2468. if i=0 then
  2469. i:=length(s)+1;
  2470. if def then
  2471. def_system_macro(Copy(s,1,i-1))
  2472. else
  2473. undef_system_macro(Copy(s,1,i-1));
  2474. delete(s,1,i);
  2475. end;
  2476. if (tf_winlikewidestring in target_info.flags) then
  2477. if def then
  2478. def_system_macro('FPC_WINLIKEWIDESTRING')
  2479. else
  2480. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2481. if (tf_requires_proper_alignment in target_info.flags) then
  2482. if def then
  2483. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2484. else
  2485. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2486. if source_info.system<>target_info.system then
  2487. if def then
  2488. def_system_macro('FPC_CROSSCOMPILING')
  2489. else
  2490. undef_system_macro('FPC_CROSSCOMPILING');
  2491. if source_info.cpu<>target_info.cpu then
  2492. if def then
  2493. def_system_macro('FPC_CPUCROSSCOMPILING')
  2494. else
  2495. def_system_macro('FPC_CPUCROSSCOMPILING');
  2496. if (tf_no_generic_stackcheck in target_info.flags) then
  2497. if def then
  2498. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2499. else
  2500. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2501. if (tf_section_threadvars in target_info.flags) then
  2502. if def then
  2503. def_system_macro('FPC_SECTION_THREADVARS')
  2504. else
  2505. undef_system_macro('FPC_SECTION_THREADVARS');
  2506. { Code generation flags }
  2507. if def and
  2508. (tf_pic_default in target_info.flags) then
  2509. include(init_settings.moduleswitches,cs_create_pic)
  2510. else
  2511. exclude(init_settings.moduleswitches,cs_create_pic);
  2512. { Resources support }
  2513. if (tf_has_winlike_resources in target_info.flags) then
  2514. if def then
  2515. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2516. else
  2517. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2518. { Features }
  2519. case target_info.system of
  2520. system_arm_gba:
  2521. target_unsup_features:=[f_dynlibs];
  2522. system_arm_nds:
  2523. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2524. system_i386_nativent:
  2525. // until these features are implemented, they are disabled in the compiler
  2526. target_unsup_features:=[f_stackcheck];
  2527. system_jvm_java32,
  2528. system_jvm_android32:
  2529. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2530. f_variants,f_objects,f_commandargs,
  2531. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2532. else
  2533. target_unsup_features:=[];
  2534. end;
  2535. if def then
  2536. features:=features-target_unsup_features
  2537. else
  2538. features:=features+target_unsup_features;
  2539. end;
  2540. procedure TOption.checkoptionscompatibility;
  2541. begin
  2542. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2543. not(target_info.system in systems_darwin) then
  2544. begin
  2545. { smartlink creation does not yet work with DWARF
  2546. debug info on most targets, but it works in internal assembler }
  2547. if (cs_create_smart in init_settings.moduleswitches) and
  2548. not (af_outputbinary in target_asm.flags) then
  2549. begin
  2550. Message(option_dwarf_smartlink_creation);
  2551. exclude(init_settings.moduleswitches,cs_create_smart);
  2552. end;
  2553. { smart linking does not yet work with DWARF debug info on most targets }
  2554. if (cs_link_smart in init_settings.globalswitches) then
  2555. begin
  2556. Message(option_dwarf_smart_linking);
  2557. ForceStaticLinking;
  2558. end;
  2559. end;
  2560. { external debug info is only supported for DWARF on darwin }
  2561. if (target_info.system in systems_darwin) and
  2562. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2563. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2564. begin
  2565. Message(option_debug_external_unsupported);
  2566. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2567. end;
  2568. end;
  2569. constructor TOption.create;
  2570. begin
  2571. LogoWritten:=false;
  2572. NoPressEnter:=false;
  2573. FirstPass:=false;
  2574. FPUSetExplicitly:=false;
  2575. CPUSetExplicitly:=false;
  2576. OptCPUSetExplicitly:=false;
  2577. FileLevel:=0;
  2578. Quickinfo:='';
  2579. ParaIncludeCfgPath:=TSearchPathList.Create;
  2580. ParaIncludePath:=TSearchPathList.Create;
  2581. ParaObjectPath:=TSearchPathList.Create;
  2582. ParaUnitPath:=TSearchPathList.Create;
  2583. ParaLibraryPath:=TSearchPathList.Create;
  2584. ParaFrameworkPath:=TSearchPathList.Create;
  2585. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2586. MacVersionSet:=false;
  2587. end;
  2588. destructor TOption.destroy;
  2589. begin
  2590. ParaIncludeCfgPath.Free;
  2591. ParaIncludePath.Free;
  2592. ParaObjectPath.Free;
  2593. ParaUnitPath.Free;
  2594. ParaLibraryPath.Free;
  2595. ParaFrameworkPath.Free;
  2596. end;
  2597. {****************************************************************************
  2598. Callable Routines
  2599. ****************************************************************************}
  2600. function check_configfile(const fn:string;var foundfn:string):boolean;
  2601. function CfgFileExists(const fn:string):boolean;
  2602. begin
  2603. Comment(V_Tried,'Configfile search: '+fn);
  2604. CfgFileExists:=FileExists(fn);
  2605. end;
  2606. var
  2607. {$ifdef Unix}
  2608. hs,
  2609. {$endif Unix}
  2610. configpath : string;
  2611. begin
  2612. foundfn:=fn;
  2613. check_configfile:=true;
  2614. { retrieve configpath }
  2615. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2616. {$ifdef Unix}
  2617. if configpath='' then
  2618. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2619. {$endif}
  2620. {
  2621. Order to read configuration file :
  2622. try reading fpc.cfg in :
  2623. 1 - current dir
  2624. 2 - configpath
  2625. 3 - compiler path
  2626. }
  2627. if not FileExists(fn) then
  2628. begin
  2629. {$ifdef Unix}
  2630. hs:=GetEnvironmentVariable('HOME');
  2631. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2632. foundfn:=FixPath(hs,false)+'.'+fn
  2633. else
  2634. {$endif}
  2635. if CfgFileExists(configpath+fn) then
  2636. foundfn:=configpath+fn
  2637. else
  2638. {$ifdef WINDOWS}
  2639. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  2640. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  2641. else
  2642. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  2643. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  2644. else
  2645. {$endif WINDOWS}
  2646. {$ifndef Unix}
  2647. if CfgFileExists(exepath+fn) then
  2648. foundfn:=exepath+fn
  2649. else
  2650. {$else}
  2651. if CfgFileExists('/etc/'+fn) then
  2652. foundfn:='/etc/'+fn
  2653. else
  2654. {$endif}
  2655. check_configfile:=false;
  2656. end;
  2657. end;
  2658. procedure read_arguments(cmd:TCmdStr);
  2659. var
  2660. env: ansistring;
  2661. i : tfeature;
  2662. abi : tabi;
  2663. {$if defined(cpucapabilities)}
  2664. cpuflag : tcpuflags;
  2665. hs : string;
  2666. {$endif defined(cpucapabilities)}
  2667. begin
  2668. option:=coption.create;
  2669. disable_configfile:=false;
  2670. { Non-core target defines }
  2671. Option.TargetOptions(true);
  2672. { get default messagefile }
  2673. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2674. { default configfile can be specified on the commandline,
  2675. remove it first }
  2676. if (cmd<>'') and (cmd[1]='[') then
  2677. begin
  2678. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2679. Delete(cmd,1,pos(']',cmd));
  2680. end
  2681. else
  2682. ppccfg:='fpc.cfg';
  2683. { first pass reading of parameters, only -i -v -T etc.}
  2684. option.firstpass:=true;
  2685. if cmd<>'' then
  2686. option.parsecmd(cmd)
  2687. else
  2688. begin
  2689. option.read_parameters;
  2690. { Write only quickinfo }
  2691. if option.quickinfo<>'' then
  2692. option.writequickinfo;
  2693. end;
  2694. option.firstpass:=false;
  2695. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  2696. Option.TargetOptions(true);
  2697. { target is set here, for wince the default app type is gui }
  2698. if target_info.system in systems_wince then
  2699. SetApptype(app_gui)
  2700. else
  2701. SetApptype(apptype);
  2702. { default defines }
  2703. def_system_macro(target_info.shortname);
  2704. def_system_macro('FPC');
  2705. def_system_macro('VER'+version_nr);
  2706. def_system_macro('VER'+version_nr+'_'+release_nr);
  2707. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2708. { Temporary defines, until things settle down }
  2709. def_system_macro('RESSTRSECTIONS');
  2710. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2711. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2712. def_system_macro('FPC_HAS_VARSETS');
  2713. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2714. def_system_macro('FPC_HAS_STR_CURRENCY');
  2715. def_system_macro('FPC_REAL2REAL_FIXED');
  2716. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2717. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2718. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2719. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2720. def_system_macro('FPC_HAS_CONSTREF');
  2721. def_system_macro('FPC_STATICRIPFIXED');
  2722. def_system_macro('FPC_VARIANTCOPY_FIXED');
  2723. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  2724. {$if defined(x86) or defined(powerpc) or defined(powerpc64) or defined(cpuarm)}
  2725. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2726. {$endif}
  2727. def_system_macro('FPC_HAS_UNICODESTRING');
  2728. def_system_macro('FPC_RTTI_PACKSET1');
  2729. def_system_macro('FPC_HAS_CPSTRING');
  2730. {$ifdef x86_64}
  2731. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2732. {$endif x86_64}
  2733. def_system_macro('FPC_HAS_CEXTENDED');
  2734. def_system_macro('FPC_HAS_RESSTRINITS');
  2735. { these cpus have an inline rol/ror implementaion }
  2736. {$ifdef cpurox}
  2737. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2738. {$endif}
  2739. { these cpus have an inline sar implementaion }
  2740. { currently, all supported CPUs have an internal sar implementation }
  2741. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc) or defined(mips)}
  2742. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2743. { $endif}
  2744. {$ifdef powerpc64}
  2745. def_system_macro('FPC_HAS_LWSYNC');
  2746. {$endif}
  2747. def_system_macro('FPC_HAS_MEMBAR');
  2748. def_system_macro('FPC_SETBASE_USED');
  2749. {$ifdef SUPPORT_GET_FRAME}
  2750. def_system_macro('INTERNAL_BACKTRACE');
  2751. {$endif SUPPORT_GET_FRAME}
  2752. def_system_macro('STR_CONCAT_PROCS');
  2753. {$warnings off}
  2754. if pocall_default = pocall_register then
  2755. def_system_macro('REGCALL');
  2756. {$warnings on}
  2757. { don't remove this, it's also for fpdoc necessary (FK) }
  2758. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2759. { using a case is pretty useless here (FK) }
  2760. { some stuff for TP compatibility }
  2761. {$ifdef i386}
  2762. def_system_macro('CPU86');
  2763. def_system_macro('CPU87');
  2764. def_system_macro('CPU386');
  2765. {$endif}
  2766. { new processor stuff }
  2767. {$ifdef i386}
  2768. def_system_macro('CPUI386');
  2769. def_system_macro('CPU32');
  2770. def_system_macro('CPUX86');
  2771. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2772. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2773. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2774. {$endif}
  2775. {$ifdef m68k}
  2776. def_system_macro('CPU68');
  2777. def_system_macro('CPU68K');
  2778. def_system_macro('CPUM68K');
  2779. def_system_macro('CPU32');
  2780. def_system_macro('FPC_CURRENCY_IS_INT64');
  2781. def_system_macro('FPC_COMP_IS_INT64');
  2782. {$endif}
  2783. {$ifdef ALPHA}
  2784. def_system_macro('CPUALPHA');
  2785. def_system_macro('CPU64');
  2786. {$endif}
  2787. {$ifdef powerpc}
  2788. def_system_macro('CPUPOWERPC');
  2789. def_system_macro('CPUPOWERPC32');
  2790. def_system_macro('CPU32');
  2791. def_system_macro('FPC_CURRENCY_IS_INT64');
  2792. def_system_macro('FPC_COMP_IS_INT64');
  2793. {$endif}
  2794. {$ifdef POWERPC64}
  2795. def_system_macro('CPUPOWERPC');
  2796. def_system_macro('CPUPOWERPC64');
  2797. def_system_macro('CPU64');
  2798. def_system_macro('FPC_CURRENCY_IS_INT64');
  2799. def_system_macro('FPC_COMP_IS_INT64');
  2800. {$endif}
  2801. {$ifdef iA64}
  2802. def_system_macro('CPUIA64');
  2803. def_system_macro('CPU64');
  2804. {$endif}
  2805. {$ifdef x86_64}
  2806. def_system_macro('CPUX86_64');
  2807. def_system_macro('CPUAMD64');
  2808. def_system_macro('CPU64');
  2809. def_system_macro('CPUX64');
  2810. { not supported for now, afaik (FK)
  2811. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2812. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  2813. { normally, win64 doesn't support the legacy fpu }
  2814. if target_info.system=system_x86_64_win64 then
  2815. begin
  2816. def_system_macro('FPC_CURRENCY_IS_INT64');
  2817. def_system_macro('FPC_COMP_IS_INT64');
  2818. end;
  2819. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  2820. {$endif}
  2821. {$ifdef sparc}
  2822. def_system_macro('CPUSPARC');
  2823. def_system_macro('CPUSPARC32');
  2824. def_system_macro('CPU32');
  2825. def_system_macro('FPC_CURRENCY_IS_INT64');
  2826. def_system_macro('FPC_COMP_IS_INT64');
  2827. {$endif}
  2828. {$ifdef vis}
  2829. def_system_macro('CPUVIS');
  2830. def_system_macro('CPU32');
  2831. {$endif}
  2832. {$ifdef arm}
  2833. def_system_macro('CPUARM');
  2834. def_system_macro('CPU32');
  2835. def_system_macro('FPC_CURRENCY_IS_INT64');
  2836. def_system_macro('FPC_COMP_IS_INT64');
  2837. {$endif arm}
  2838. {$ifdef avr}
  2839. def_system_macro('CPUAVR');
  2840. def_system_macro('CPU16');
  2841. def_system_macro('FPC_CURRENCY_IS_INT64');
  2842. def_system_macro('FPC_COMP_IS_INT64');
  2843. {$endif avr}
  2844. {$ifdef jvm}
  2845. def_system_macro('CPUJVM');
  2846. def_system_macro('CPU32');
  2847. def_system_macro('FPC_CURRENCY_IS_INT64');
  2848. def_system_macro('FPC_COMP_IS_INT64');
  2849. {$endif jvm}
  2850. {$ifdef mipsel}
  2851. def_system_macro('CPUMIPS');
  2852. def_system_macro('CPUMIPS32');
  2853. def_system_macro('CPUMIPSEL');
  2854. def_system_macro('CPUMIPSEL32');
  2855. def_system_macro('CPU32');
  2856. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2857. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2858. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2859. def_system_macro('FPC_CURRENCY_IS_INT64');
  2860. def_system_macro('FPC_COMP_IS_INT64');
  2861. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2862. { On most systems, locals are accessed relative to base pointer,
  2863. but for MIPS cpu, they are accessed relative to stack pointer.
  2864. This needs adaptation for so low level routines,
  2865. like MethodPointerLocal and related objects unit functions. }
  2866. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  2867. {$endif mipsel}
  2868. {$ifdef mipseb}
  2869. def_system_macro('CPUMIPS');
  2870. def_system_macro('CPUMIPS32');
  2871. def_system_macro('CPUMIPSEB');
  2872. def_system_macro('CPUMIPSEB32');
  2873. def_system_macro('CPU32');
  2874. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2875. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2876. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2877. def_system_macro('FPC_CURRENCY_IS_INT64');
  2878. def_system_macro('FPC_COMP_IS_INT64');
  2879. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2880. { See comment above for mipsel }
  2881. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  2882. {$endif}
  2883. {$ifdef i8086}
  2884. def_system_macro('CPU86'); { Borland compatibility }
  2885. def_system_macro('CPU87'); { Borland compatibility }
  2886. def_system_macro('CPU8086');
  2887. def_system_macro('CPUI8086');
  2888. def_system_macro('CPU16');
  2889. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2890. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2891. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2892. {$endif i8086}
  2893. { Set up a default prefix for binutils when cross-compiling }
  2894. if source_info.system<>target_info.system then
  2895. case target_info.system of
  2896. { Use standard Android NDK prefixes }
  2897. system_arm_android:
  2898. utilsprefix:='arm-linux-androideabi-';
  2899. system_i386_android:
  2900. utilsprefix:='i686-linux-android-';
  2901. end;
  2902. { Set up default value for the heap }
  2903. if target_info.system in systems_embedded then
  2904. begin
  2905. case target_info.system of
  2906. system_avr_embedded:
  2907. heapsize:=128;
  2908. system_arm_embedded:
  2909. heapsize:=256;
  2910. else
  2911. heapsize:=256;
  2912. end;
  2913. end;
  2914. { read configuration file }
  2915. if (not disable_configfile) and
  2916. (ppccfg<>'') then
  2917. read_configfile:=check_configfile(ppccfg,ppccfg)
  2918. else
  2919. read_configfile := false;
  2920. { Read commandline and configfile }
  2921. param_file:='';
  2922. { read configfile }
  2923. if read_configfile then
  2924. option.interpret_file(ppccfg);
  2925. { read parameters again to override config file }
  2926. if cmd<>'' then
  2927. option.parsecmd(cmd)
  2928. else
  2929. begin
  2930. { Write help pages if no parameters are passed }
  2931. if (paramcount=0) then
  2932. Option.WriteHelpPages;
  2933. option.read_parameters;
  2934. { Write only quickinfo }
  2935. if option.quickinfo<>'' then
  2936. option.writequickinfo;
  2937. end;
  2938. { check the compatibility of different options and adjust them if necessary
  2939. (and print possible errors)
  2940. }
  2941. option.checkoptionscompatibility;
  2942. { Stop if errors in options }
  2943. if ErrorCount>0 then
  2944. StopOptions(1);
  2945. { endian define }
  2946. case target_info.endian of
  2947. endian_little :
  2948. begin
  2949. def_system_macro('ENDIAN_LITTLE');
  2950. def_system_macro('FPC_LITTLE_ENDIAN');
  2951. end;
  2952. endian_big :
  2953. begin
  2954. def_system_macro('ENDIAN_BIG');
  2955. def_system_macro('FPC_BIG_ENDIAN');
  2956. end;
  2957. end;
  2958. { define abi }
  2959. for abi:=low(tabi) to high(tabi) do
  2960. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  2961. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  2962. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  2963. systems since most code needs to behave the same on both}
  2964. if target_info.abi = abi_eabihf then
  2965. def_system_macro('FPC_ABI_EABI');
  2966. { Write logo }
  2967. if option.ParaLogo then
  2968. option.writelogo;
  2969. { Check file to compile }
  2970. if param_file='' then
  2971. begin
  2972. Message(option_no_source_found);
  2973. StopOptions(1);
  2974. end;
  2975. {$ifndef Unix}
  2976. param_file:=FixFileName(param_file);
  2977. {$endif not unix}
  2978. inputfilepath:=ExtractFilePath(param_file);
  2979. inputfilename:=ExtractFileName(param_file);
  2980. if ExtractFileExt(inputfilename)='' then
  2981. begin
  2982. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2983. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2984. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2985. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2986. else if ((m_mac in current_settings.modeswitches) or
  2987. (tf_p_ext_support in target_info.flags))
  2988. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2989. inputfilename:=ChangeFileExt(inputfilename,pext);
  2990. end;
  2991. { Check output dir }
  2992. if (OutputExeDir<>'') and
  2993. not PathExists(OutputExeDir,false) then
  2994. begin
  2995. Message1(general_e_path_does_not_exist,OutputExeDir);
  2996. StopOptions(1);
  2997. end;
  2998. { Add paths specified with parameters to the searchpaths }
  2999. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3000. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3001. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3002. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3003. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3004. { add unit environment and exepath to the unit search path }
  3005. if inputfilepath<>'' then
  3006. Unitsearchpath.AddPath(inputfilepath,true);
  3007. if not disable_configfile then
  3008. begin
  3009. env:=GetEnvironmentVariable(target_info.unit_env);
  3010. if env<>'' then
  3011. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3012. end;
  3013. {$ifdef Unix}
  3014. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3015. if fpcdir='' then
  3016. begin
  3017. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3018. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3019. else
  3020. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3021. end;
  3022. {$else unix}
  3023. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3024. if fpcdir='' then
  3025. begin
  3026. fpcdir:=ExePath+'../';
  3027. if not(PathExists(fpcdir+'units',true)) and
  3028. not(PathExists(fpcdir+'rtl',true)) then
  3029. fpcdir:=fpcdir+'../';
  3030. end;
  3031. {$endif unix}
  3032. { first try development RTL, else use the default installation path }
  3033. if not disable_configfile then
  3034. begin
  3035. if PathExists(FpcDir+'rtl',true) then
  3036. if tf_use_8_3 in Source_Info.Flags then
  3037. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3038. else
  3039. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3040. else
  3041. if tf_use_8_3 in Source_Info.Flags then
  3042. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3043. else
  3044. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3045. end;
  3046. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3047. Do not add it when linking on the target because then we can maybe already find
  3048. .o files that are not for the target }
  3049. if (ExePath<>cfileutl.GetCurrentDir) and
  3050. not(cs_link_on_target in init_settings.globalswitches) then
  3051. UnitSearchPath.AddPath(ExePath,false);
  3052. { Add unit dir to the object and library path }
  3053. objectsearchpath.AddList(unitsearchpath,false);
  3054. librarysearchpath.AddList(unitsearchpath,false);
  3055. { maybe override assembler }
  3056. if (paratargetasm<>as_none) then
  3057. begin
  3058. if not set_target_asm(paratargetasm) then
  3059. begin
  3060. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  3061. set_target_asm(target_info.assemextern);
  3062. Message1(option_asm_forced,target_asm.idtxt);
  3063. end;
  3064. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  3065. (paratargetdbg<>dbg_none) then
  3066. begin
  3067. Message1(option_confict_asm_debug,
  3068. asminfos[paratargetasm]^.idtxt);
  3069. paratargetdbg:=dbg_none;
  3070. exclude(init_settings.moduleswitches,cs_debuginfo);
  3071. end;
  3072. end;
  3073. {TOptionheck a second time as we might have changed assembler just above }
  3074. option.checkoptionscompatibility;
  3075. { maybe override debug info format }
  3076. if (paratargetdbg<>dbg_none) then
  3077. if not set_target_dbg(paratargetdbg) then
  3078. Message(option_w_unsupported_debug_format);
  3079. { switch assembler if it's binary and we got -a on the cmdline }
  3080. if (cs_asm_leave in init_settings.globalswitches) and
  3081. (af_outputbinary in target_asm.flags) then
  3082. begin
  3083. Message(option_switch_bin_to_src_assembler);
  3084. set_target_asm(target_info.assemextern);
  3085. end;
  3086. { Force use of external linker if there is no
  3087. internal linker or the linking is skipped }
  3088. if not(cs_link_extern in init_settings.globalswitches) and
  3089. ((target_info.link=ld_none) or
  3090. (cs_link_nolink in init_settings.globalswitches)) then
  3091. include(init_settings.globalswitches,cs_link_extern);
  3092. { turn off stripping if compiling with debuginfo or profile }
  3093. if (
  3094. (cs_debuginfo in init_settings.moduleswitches) or
  3095. (cs_profile in init_settings.moduleswitches)
  3096. ) and
  3097. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3098. exclude(init_settings.globalswitches,cs_link_strip);
  3099. { set Mac OS X version default macros if not specified explicitly }
  3100. option.MaybeSetDefaultMacVersionMacro;
  3101. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3102. if fpu type not explicitly set }
  3103. if not(option.FPUSetExplicitly) and
  3104. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  3105. system_m68k_linux,system_arm_nds,system_arm_embedded])
  3106. {$ifdef arm}
  3107. or (target_info.abi=abi_eabi)
  3108. {$endif arm}
  3109. )
  3110. {$if defined(arm) or defined (m68k)}
  3111. or (init_settings.fputype=fpu_soft)
  3112. {$endif arm or m68k}
  3113. then
  3114. begin
  3115. {$ifdef cpufpemu}
  3116. include(init_settings.moduleswitches,cs_fp_emulation);
  3117. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3118. init_settings.fputype:=fpu_soft;
  3119. {$endif cpufpemu}
  3120. end;
  3121. {$ifdef arm}
  3122. if target_info.abi = abi_eabihf then
  3123. begin
  3124. if not(option.FPUSetExplicitly) then
  3125. begin
  3126. init_settings.fputype:=fpu_vfpv3_d16
  3127. end
  3128. else
  3129. begin
  3130. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16]) then
  3131. begin
  3132. Message(option_illegal_fpu_eabihf);
  3133. StopOptions(1);
  3134. end;
  3135. end;
  3136. end;
  3137. {$endif arm}
  3138. {$ifdef arm}
  3139. case target_info.system of
  3140. system_arm_darwin:
  3141. begin
  3142. { set default cpu type to ARMv6 for Darwin unless specified otherwise, and fpu
  3143. to VFPv2 }
  3144. if not option.CPUSetExplicitly then
  3145. init_settings.cputype:=cpu_armv6;
  3146. if not option.OptCPUSetExplicitly then
  3147. init_settings.optimizecputype:=cpu_armv6;
  3148. if not option.FPUSetExplicitly then
  3149. init_settings.fputype:=fpu_vfpv2;
  3150. end;
  3151. system_arm_android:
  3152. begin
  3153. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3154. if not option.CPUSetExplicitly then
  3155. init_settings.cputype:=cpu_armv5t;
  3156. if not option.OptCPUSetExplicitly then
  3157. init_settings.optimizecputype:=cpu_armv5t;
  3158. end;
  3159. end;
  3160. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3161. if (target_info.abi = abi_eabihf) then
  3162. begin
  3163. {$ifdef CPUARMV6}
  3164. { if the compiler is built for armv6, then
  3165. inherit this setting, e.g. Raspian is armhf but
  3166. only armv6, this makes rebuilds of the compiler
  3167. easier }
  3168. if not option.CPUSetExplicitly then
  3169. init_settings.cputype:=cpu_armv6;
  3170. if not option.OptCPUSetExplicitly then
  3171. init_settings.optimizecputype:=cpu_armv6;
  3172. {$else CPUARMV6}
  3173. if not option.CPUSetExplicitly then
  3174. init_settings.cputype:=cpu_armv7a;
  3175. if not option.OptCPUSetExplicitly then
  3176. init_settings.optimizecputype:=cpu_armv7a;
  3177. {$endif CPUARMV6}
  3178. end;
  3179. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3180. begin
  3181. def_system_macro('CPUTHUMB');
  3182. if not option.FPUSetExplicitly then
  3183. init_settings.fputype:=fpu_soft;
  3184. end;
  3185. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3186. def_system_macro('CPUTHUMB2');
  3187. {$endif arm}
  3188. {$ifdef jvm}
  3189. { set default CPU type to Dalvik when targeting Android }
  3190. if target_info.system=system_jvm_android32 then
  3191. begin
  3192. if not option.CPUSetExplicitly then
  3193. init_settings.cputype:=cpu_dalvik;
  3194. end;
  3195. {$endif jvm}
  3196. { now we can define cpu and fpu type }
  3197. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3198. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3199. {$if defined(cpucapabilities)}
  3200. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3201. begin
  3202. str(cpuflag,hs);
  3203. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3204. def_system_macro(hs)
  3205. else
  3206. undef_system_macro(hs);
  3207. end;
  3208. {$endif defined(cpucapabilities)}
  3209. if init_settings.fputype<>fpu_none then
  3210. begin
  3211. {$if defined(i386) or defined(i8086)}
  3212. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3213. {$endif}
  3214. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3215. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3216. {$if not defined(i386) and not defined(x86_64) and not defined(i8086)}
  3217. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3218. {$endif}
  3219. {$if defined(m68k)}
  3220. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3221. {$endif}
  3222. {$ifdef x86_64}
  3223. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3224. { normally, win64 doesn't support the legacy fpu }
  3225. if target_info.system=system_x86_64_win64 then
  3226. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3227. else
  3228. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3229. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3230. {$endif}
  3231. end;
  3232. { Enable now for testing }
  3233. {$ifndef DISABLE_TLS_DIRECTORY}
  3234. if target_info.system in systems_windows then
  3235. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3236. {$endif not DISABLE_TLS_DIRECTORY}
  3237. {$ifndef DISABLE_WIN64_SEH}
  3238. if target_info.system=system_x86_64_win64 then
  3239. def_system_macro('FPC_USE_WIN64_SEH');
  3240. {$endif DISABLE_WIN64_SEH}
  3241. {$ifdef ARM}
  3242. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3243. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3244. not(cs_fp_emulation in init_settings.moduleswitches) then
  3245. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3246. {$endif ARM}
  3247. { inline bsf/bsr implementation }
  3248. {$if defined(x86) or defined(x86_64)}
  3249. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3250. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3251. {$endif}
  3252. {$if defined(arm)}
  3253. { it is determined during system unit compilation if clz is used for bsf or not,
  3254. this is not perfect but the current implementation bsf/bsr does not allow another
  3255. solution }
  3256. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3257. ((init_settings.instructionset=is_arm) or
  3258. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3259. begin
  3260. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3261. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3262. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3263. end;
  3264. {$endif}
  3265. {$if defined(i8086)}
  3266. case init_settings.x86memorymodel of
  3267. mm_tiny: def_system_macro('FPC_MM_TINY');
  3268. mm_small: def_system_macro('FPC_MM_SMALL');
  3269. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3270. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3271. mm_large: def_system_macro('FPC_MM_LARGE');
  3272. mm_huge: def_system_macro('FPC_MM_HUGE');
  3273. end;
  3274. {$endif}
  3275. { Section smartlinking conflicts with import sections on Windows }
  3276. if GenerateImportSection and
  3277. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3278. exclude(target_info.flags,tf_smartlink_sections);
  3279. if not LinkTypeSetExplicitly then
  3280. set_default_link_type;
  3281. { Default alignment settings,
  3282. 1. load the defaults for the target
  3283. 2. override with generic optimizer setting (little size)
  3284. 3. override with the user specified -Oa }
  3285. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3286. if (cs_opt_size in current_settings.optimizerswitches) then
  3287. begin
  3288. init_settings.alignment.procalign:=1;
  3289. init_settings.alignment.jumpalign:=1;
  3290. init_settings.alignment.loopalign:=1;
  3291. end;
  3292. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3293. set_system_macro('FPC_VERSION',version_nr);
  3294. set_system_macro('FPC_RELEASE',release_nr);
  3295. set_system_macro('FPC_PATCH',patch_nr);
  3296. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3297. if not(target_info.system in systems_windows) then
  3298. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3299. for i:=low(tfeature) to high(tfeature) do
  3300. if i in features then
  3301. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3302. option.free;
  3303. Option:=nil;
  3304. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  3305. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal];
  3306. if (tf_safecall_clearstack in target_info.flags) then
  3307. begin
  3308. include (cdecl_pocalls, pocall_safecall);
  3309. include (clearstack_pocalls, pocall_safecall)
  3310. end;
  3311. end;
  3312. initialization
  3313. coption:=toption;
  3314. finalization
  3315. if assigned(option) then
  3316. option.free;
  3317. end.