2
0

options.pas 121 KB

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