options.pas 116 KB

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