options.pas 122 KB

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