options.pas 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499
  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. break;
  847. end;
  848. {$endif arm}
  849. 'n' :
  850. If UnsetBool(More, j, opt, false) then
  851. exclude(init_settings.globalswitches,cs_link_nolink)
  852. Else
  853. include(init_settings.globalswitches,cs_link_nolink);
  854. 'N' :
  855. If UnsetBool(More, j, opt, false) then
  856. exclude(init_settings.localswitches,cs_check_low_addr_load)
  857. Else
  858. include(init_settings.localswitches,cs_check_low_addr_load);
  859. 'o' :
  860. If UnsetBool(More, j, opt, false) then
  861. exclude(init_settings.localswitches,cs_check_overflow)
  862. Else
  863. include(init_settings.localswitches,cs_check_overflow);
  864. 'O' :
  865. If UnsetBool(More, j, opt, false) then
  866. exclude(init_settings.localswitches,cs_check_ordinal_size)
  867. Else
  868. include(init_settings.localswitches,cs_check_ordinal_size);
  869. 'p' :
  870. begin
  871. s:=upper(copy(more,j+1,length(more)-j));
  872. if not(Setcputype(s,init_settings)) then
  873. IllegalPara(opt);
  874. CPUSetExplicitly:=true;
  875. break;
  876. end;
  877. 'P':
  878. begin
  879. delete(more,1,1);
  880. if upper(copy(more,1,pos('=',more)-1))='PACKSET' then
  881. begin
  882. delete(more,1,pos('=',more));
  883. if (more='0') or (more='DEFAULT') or (more='NORMAL') then
  884. init_settings.setalloc:=0
  885. else if more='1' then
  886. init_settings.setalloc:=1
  887. else if more='2' then
  888. init_settings.setalloc:=2
  889. else if more='4' then
  890. init_settings.setalloc:=4
  891. else if more='8' then
  892. init_settings.setalloc:=8
  893. else
  894. IllegalPara(opt);
  895. end
  896. else
  897. IllegalPara(opt);
  898. end;
  899. 'r' :
  900. If UnsetBool(More, j, opt, false) then
  901. exclude(init_settings.localswitches,cs_check_range)
  902. Else
  903. include(init_settings.localswitches,cs_check_range);
  904. 'R' :
  905. If UnsetBool(More, j, opt, false) then
  906. begin
  907. exclude(init_settings.localswitches,cs_check_range);
  908. exclude(init_settings.localswitches,cs_check_object);
  909. end
  910. Else
  911. begin
  912. include(init_settings.localswitches,cs_check_range);
  913. include(init_settings.localswitches,cs_check_object);
  914. end;
  915. 's' :
  916. begin
  917. val(copy(more,j+1,length(more)-j),stacksize,code);
  918. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  919. IllegalPara(opt);
  920. break;
  921. end;
  922. 't' :
  923. If UnsetBool(More, j, opt, false) then
  924. exclude(init_settings.localswitches,cs_check_stack)
  925. Else
  926. include(init_settings.localswitches,cs_check_stack);
  927. 'D' :
  928. If UnsetBool(More, j, opt, false) then
  929. exclude(init_settings.moduleswitches,cs_create_dynamic)
  930. Else
  931. include(init_settings.moduleswitches,cs_create_dynamic);
  932. 'X' :
  933. If UnsetBool(More, j, opt, false) then
  934. exclude(init_settings.moduleswitches,cs_create_smart)
  935. Else
  936. include(init_settings.moduleswitches,cs_create_smart);
  937. 'T' :
  938. begin
  939. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  940. IllegalPara(opt);
  941. break;
  942. end;
  943. 'v' :
  944. If target_info.system in systems_jvm then
  945. If UnsetBool(More, j, opt, false) then
  946. exclude(init_settings.localswitches,cs_check_var_copyout)
  947. Else
  948. include(init_settings.localswitches,cs_check_var_copyout)
  949. else
  950. IllegalPara(opt)
  951. else
  952. IllegalPara(opt);
  953. end;
  954. inc(j);
  955. end;
  956. end;
  957. 'd' :
  958. if more <> '' then
  959. begin
  960. l:=Pos(':=',more);
  961. if l>0 then
  962. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  963. else
  964. def_system_macro(more);
  965. end;
  966. 'D' :
  967. begin
  968. include(init_settings.globalswitches,cs_link_deffile);
  969. j:=1;
  970. while j<=length(more) do
  971. begin
  972. case more[j] of
  973. 'd' :
  974. begin
  975. description:=Copy(more,j+1,255);
  976. break;
  977. end;
  978. 'v' :
  979. begin
  980. dllversion:=Copy(more,j+1,255);
  981. l:=pos('.',dllversion);
  982. dllminor:=0;
  983. error:=0;
  984. if l>0 then
  985. begin
  986. val(copy(dllversion,l+1,255),minor,error);
  987. if (error=0) and
  988. (minor>=0) and (minor<=$ffff) then
  989. dllminor:=minor
  990. else
  991. if error=0 then
  992. error:=1;
  993. end;
  994. if l=0 then
  995. l:=256;
  996. dllmajor:=1;
  997. if error=0 then
  998. val(copy(dllversion,1,l-1),major,error);
  999. if (error=0) and (major>=0) and (major<=$ffff) then
  1000. dllmajor:=major
  1001. else
  1002. if error=0 then
  1003. error:=1;
  1004. if error<>0 then
  1005. Message1(scan_w_wrong_version_ignored,dllversion);
  1006. break;
  1007. end;
  1008. 'w' :
  1009. usewindowapi:=true;
  1010. '-' :
  1011. begin
  1012. exclude(init_settings.globalswitches,cs_link_deffile);
  1013. usewindowapi:=false;
  1014. end;
  1015. else
  1016. IllegalPara(opt);
  1017. end;
  1018. inc(j);
  1019. end;
  1020. end;
  1021. 'e' :
  1022. exepath:=FixPath(More,true);
  1023. 'E' :
  1024. begin
  1025. if UnsetBool(More, 0, opt, true) then
  1026. exclude(init_settings.globalswitches,cs_link_nolink)
  1027. else
  1028. include(init_settings.globalswitches,cs_link_nolink);
  1029. end;
  1030. 'f' :
  1031. begin
  1032. if more='PIC' then
  1033. begin
  1034. if tf_no_pic_supported in target_info.flags then
  1035. message(scan_w_pic_ignored)
  1036. else
  1037. include(init_settings.moduleswitches,cs_create_pic)
  1038. end
  1039. else
  1040. IllegalPara(opt);
  1041. end;
  1042. 'F' :
  1043. begin
  1044. if more='' then
  1045. IllegalPara(opt);
  1046. c:=more[1];
  1047. Delete(more,1,1);
  1048. DefaultReplacements(More);
  1049. case c of
  1050. 'a' :
  1051. autoloadunits:=more;
  1052. 'c' :
  1053. begin
  1054. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1055. init_settings.sourcecodepage:=CP_UTF8
  1056. else if not(cpavailable(more)) then
  1057. Message1(option_code_page_not_available,more)
  1058. else
  1059. init_settings.sourcecodepage:=codepagebyname(more);
  1060. include(init_settings.moduleswitches,cs_explicit_codepage);
  1061. end;
  1062. 'C' :
  1063. RCCompiler := More;
  1064. 'd' :
  1065. if UnsetBool(more, 0, opt, true) then
  1066. init_settings.disabledircache:=false
  1067. else
  1068. init_settings.disabledircache:=true;
  1069. 'D' :
  1070. utilsdirectory:=FixPath(More,true);
  1071. 'e' :
  1072. SetRedirectFile(More);
  1073. 'E' :
  1074. OutputExeDir:=FixPath(More,true);
  1075. 'f' :
  1076. if (target_info.system in systems_darwin) then
  1077. if ispara then
  1078. ParaFrameworkPath.AddPath(More,false)
  1079. else
  1080. frameworksearchpath.AddPath(More,true)
  1081. else
  1082. IllegalPara(opt);
  1083. 'i' :
  1084. begin
  1085. if ispara then
  1086. ParaIncludePath.AddPath(More,false)
  1087. else
  1088. includesearchpath.AddPath(More,true);
  1089. end;
  1090. 'm' :
  1091. begin
  1092. s:=ExtractFileDir(more);
  1093. if TryStrToInt(ExtractFileName(more),j) then
  1094. begin
  1095. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1096. if assigned(unicodemapping) then
  1097. registermapping(unicodemapping)
  1098. else
  1099. IllegalPara(opt);
  1100. end
  1101. else
  1102. IllegalPara(opt);
  1103. end;
  1104. 'g' :
  1105. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1106. 'l' :
  1107. begin
  1108. if ispara then
  1109. ParaLibraryPath.AddPath(sysrootpath,More,false)
  1110. else
  1111. LibrarySearchPath.AddPath(sysrootpath,More,true);
  1112. end;
  1113. 'L' :
  1114. begin
  1115. if More<>'' then
  1116. ParaDynamicLinker:=More
  1117. else
  1118. IllegalPara(opt);
  1119. end;
  1120. 'o' :
  1121. begin
  1122. if ispara then
  1123. ParaObjectPath.AddPath(More,false)
  1124. else
  1125. ObjectSearchPath.AddPath(More,true);
  1126. end;
  1127. 'r' :
  1128. Msgfilename:=More;
  1129. 'R' :
  1130. ResCompiler := More;
  1131. 'u' :
  1132. begin
  1133. if ispara then
  1134. ParaUnitPath.AddPath(More,false)
  1135. else
  1136. unitsearchpath.AddPath(More,true);
  1137. end;
  1138. 'U' :
  1139. OutputUnitDir:=FixPath(More,true);
  1140. 'W',
  1141. 'w':
  1142. begin
  1143. if More<>'' then
  1144. begin
  1145. DefaultReplacements(More);
  1146. D:=ExtractFilePath(More);
  1147. if (D<>'') then
  1148. D:=FixPath(D,True);
  1149. D:=D+ExtractFileName(More);
  1150. if (c='W') then
  1151. WpoFeedbackOutput:=D
  1152. else
  1153. WpoFeedbackInput:=D;
  1154. end
  1155. else
  1156. IllegalPara(opt);
  1157. end;
  1158. else
  1159. IllegalPara(opt);
  1160. end;
  1161. end;
  1162. 'g' :
  1163. begin
  1164. if UnsetBool(More, 0, opt, false) then
  1165. begin
  1166. exclude(init_settings.moduleswitches,cs_debuginfo);
  1167. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1168. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1169. exclude(init_settings.localswitches,cs_checkpointer);
  1170. localvartrashing := -1;
  1171. end
  1172. else
  1173. begin
  1174. include(init_settings.moduleswitches,cs_debuginfo);
  1175. if paratargetdbg=dbg_none then
  1176. paratargetdbg:=target_info.dbg;
  1177. end;
  1178. if not RelocSectionSetExplicitly then
  1179. RelocSection:=false;
  1180. j:=1;
  1181. while j<=length(more) do
  1182. begin
  1183. case more[j] of
  1184. 'c' :
  1185. begin
  1186. if UnsetBool(More, j, opt, false) then
  1187. exclude(init_settings.localswitches,cs_checkpointer)
  1188. else if (target_info.system in supported_targets_gc) then
  1189. include(init_settings.localswitches,cs_checkpointer)
  1190. else
  1191. UnsupportedPara('-gc');
  1192. end;
  1193. 'h' :
  1194. begin
  1195. if UnsetBool(More, j, opt, false) then
  1196. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1197. else
  1198. include(init_settings.globalswitches,cs_use_heaptrc);
  1199. end;
  1200. 'l' :
  1201. begin
  1202. if UnsetBool(More, j, opt, false) then
  1203. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1204. else
  1205. include(init_settings.globalswitches,cs_use_lineinfo);
  1206. end;
  1207. 'o' :
  1208. begin
  1209. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1210. IllegalPara(opt);
  1211. break;
  1212. end;
  1213. 'p' :
  1214. begin
  1215. if UnsetBool(More, j, opt, false) then
  1216. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1217. else
  1218. include(init_settings.globalswitches,cs_stabs_preservecase);
  1219. end;
  1220. 's' :
  1221. begin
  1222. paratargetdbg:=dbg_stabs;
  1223. end;
  1224. 't' :
  1225. begin
  1226. if UnsetBool(More, j, opt, false) then
  1227. localvartrashing := -1
  1228. else
  1229. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1230. end;
  1231. 'v' :
  1232. begin
  1233. if UnsetBool(More, j, opt, false) then
  1234. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1235. else
  1236. include(init_settings.globalswitches,cs_gdb_valgrind);
  1237. end;
  1238. 'w' :
  1239. begin
  1240. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1241. begin
  1242. case more[j+1] of
  1243. '2': paratargetdbg:=dbg_dwarf2;
  1244. '3': paratargetdbg:=dbg_dwarf3;
  1245. '4': paratargetdbg:=dbg_dwarf4;
  1246. end;
  1247. inc(j);
  1248. end
  1249. else
  1250. paratargetdbg:=dbg_dwarf2;
  1251. end;
  1252. else
  1253. IllegalPara(opt);
  1254. end;
  1255. inc(j);
  1256. end;
  1257. end;
  1258. 'h' :
  1259. begin
  1260. NoPressEnter:=true;
  1261. if (More <> '') and (More [1] = 'F') then
  1262. begin
  1263. FPCHelpLines := true;
  1264. Delete (More, 1, 1);
  1265. FPCBinaryPath := More;
  1266. end;
  1267. WriteHelpPages;
  1268. end;
  1269. 'i' :
  1270. begin
  1271. if More='' then
  1272. WriteInfo
  1273. else
  1274. QuickInfo:=QuickInfo+More;
  1275. end;
  1276. 'I' :
  1277. begin
  1278. if ispara then
  1279. ParaIncludePath.AddPath(More,false)
  1280. else
  1281. includesearchpath.AddPath(More,false);
  1282. end;
  1283. 'k' :
  1284. begin
  1285. if more<>'' then
  1286. ParaLinkOptions:=ParaLinkOptions+' '+More
  1287. else
  1288. IllegalPara(opt);
  1289. end;
  1290. 'l' :
  1291. ParaLogo:=not UnSetBool(more,0,opt,true);
  1292. 'm' :
  1293. parapreprocess:=not UnSetBool(more,0,opt,true);
  1294. 'M' :
  1295. begin
  1296. more:=Upper(more);
  1297. if not SetCompileMode(more, true) then
  1298. if not SetCompileModeSwitch(more, true) then
  1299. IllegalPara(opt);
  1300. end;
  1301. 'n' :
  1302. begin
  1303. if More='' then
  1304. disable_configfile:=true
  1305. else
  1306. IllegalPara(opt);
  1307. end;
  1308. 'o' :
  1309. begin
  1310. if More<>'' then
  1311. begin
  1312. DefaultReplacements(More);
  1313. D:=ExtractFilePath(More);
  1314. if (D<>'') then
  1315. OutputExeDir:=FixPath(D,True);
  1316. OutputFileName:=ExtractFileName(More);
  1317. end
  1318. else
  1319. IllegalPara(opt);
  1320. end;
  1321. 'O' :
  1322. begin
  1323. j:=1;
  1324. while j<=length(more) do
  1325. begin
  1326. case more[j] of
  1327. '1' :
  1328. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1329. '2' :
  1330. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1331. '3' :
  1332. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1333. '4' :
  1334. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1335. 'a' :
  1336. begin
  1337. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1338. IllegalPara(opt);
  1339. break;
  1340. end;
  1341. 's' :
  1342. include(init_settings.optimizerswitches,cs_opt_size);
  1343. 'p' :
  1344. begin
  1345. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1346. begin
  1347. OptCPUSetExplicitly:=true;
  1348. { Give warning for old i386 switches }
  1349. if (Length(More)-j=1) and
  1350. (More[j+1]>='1') and (More[j+1]<='5')then
  1351. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1352. else
  1353. IllegalPara(opt);
  1354. end;
  1355. break;
  1356. end;
  1357. 'o' :
  1358. begin
  1359. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1360. IllegalPara(opt);
  1361. break;
  1362. end;
  1363. '-' :
  1364. begin
  1365. init_settings.optimizerswitches:=[];
  1366. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1367. end;
  1368. { Obsolete switches }
  1369. 'g' :
  1370. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1371. 'G' :
  1372. Message1(option_obsolete_switch,'-OG');
  1373. 'r' :
  1374. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1375. 'u' :
  1376. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1377. 'w' :
  1378. begin
  1379. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1380. IllegalPara(opt);
  1381. break;
  1382. end;
  1383. 'W' :
  1384. begin
  1385. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1386. IllegalPara(opt);
  1387. break;
  1388. end;
  1389. else
  1390. IllegalPara(opt);
  1391. end;
  1392. inc(j);
  1393. end;
  1394. end;
  1395. 'p' :
  1396. begin
  1397. if UnsetBool(More, 0, opt, false) then
  1398. begin
  1399. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1400. undef_system_macro('FPC_PROFILE');
  1401. end
  1402. else
  1403. if Length(More)=0 then
  1404. IllegalPara(opt)
  1405. else
  1406. case more[1] of
  1407. 'g' : if UnsetBool(more, 1, opt, false) then
  1408. begin
  1409. exclude(init_settings.moduleswitches,cs_profile);
  1410. undef_system_macro('FPC_PROFILE');
  1411. end
  1412. else if (target_info.system in supported_targets_pg) then
  1413. begin
  1414. include(init_settings.moduleswitches,cs_profile);
  1415. def_system_macro('FPC_PROFILE');
  1416. end
  1417. else
  1418. UnsupportedPara('-pg');
  1419. else
  1420. IllegalPara(opt);
  1421. end;
  1422. end;
  1423. 'P' : ; { Ignore used by fpc.pp }
  1424. 'R' :
  1425. begin
  1426. if not SetAsmReadMode(More,init_settings.asmmode) then
  1427. IllegalPara(opt);
  1428. end;
  1429. 's' :
  1430. begin
  1431. if UnsetBool(More, 0, opt, false) then
  1432. begin
  1433. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1434. if more<>'' then
  1435. IllegalPara(opt);
  1436. end
  1437. else
  1438. begin
  1439. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1440. if more='h' then
  1441. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1442. else if more='t' then
  1443. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1444. else if more='r' then
  1445. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1446. else if more<>'' then
  1447. IllegalPara(opt);
  1448. end;
  1449. end;
  1450. 'S' :
  1451. begin
  1452. if more='' then
  1453. IllegalPara(opt);
  1454. if more[1]='I' then
  1455. begin
  1456. {$ifdef jvm}
  1457. UnsupportedPara('-SI');
  1458. {$endif}
  1459. if upper(more)='ICOM' then
  1460. init_settings.interfacetype:=it_interfacecom
  1461. else if upper(more)='ICORBA' then
  1462. init_settings.interfacetype:=it_interfacecorba
  1463. else
  1464. IllegalPara(opt);
  1465. end
  1466. else
  1467. begin
  1468. j:=1;
  1469. while j<=length(more) do
  1470. begin
  1471. case more[j] of
  1472. '2' : //an alternative to -Mobjfpc
  1473. SetCompileMode('OBJFPC',true);
  1474. 'a' :
  1475. If UnsetBool(More, j, opt, false) then
  1476. exclude(init_settings.localswitches,cs_do_assertion)
  1477. else
  1478. include(init_settings.localswitches,cs_do_assertion);
  1479. 'c' :
  1480. If UnsetBool(More, j, opt, false) then
  1481. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1482. else
  1483. include(init_settings.moduleswitches,cs_support_c_operators);
  1484. 'd' : //an alternative to -Mdelphi
  1485. SetCompileMode('DELPHI',true);
  1486. 'e' :
  1487. begin
  1488. SetErrorFlags(copy(more,j+1,length(more)));
  1489. break;
  1490. end;
  1491. 'f' :
  1492. begin
  1493. inc(j);
  1494. if more[j]='-' then
  1495. begin
  1496. features:=[];
  1497. if length(more)>j then
  1498. IllegalPara(opt);
  1499. end
  1500. else
  1501. begin
  1502. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1503. j:=length(more)
  1504. else
  1505. IllegalPara(opt);
  1506. end;
  1507. end;
  1508. 'g' :
  1509. If UnsetBool(More, j, opt, false) then
  1510. exclude(init_settings.moduleswitches,cs_support_goto)
  1511. else
  1512. include(init_settings.moduleswitches,cs_support_goto);
  1513. 'h' :
  1514. If UnsetBool(More, j, opt, false) then
  1515. exclude(init_settings.localswitches,cs_refcountedstrings)
  1516. else
  1517. include(init_settings.localswitches,cs_refcountedstrings);
  1518. 'i' :
  1519. If UnsetBool(More, j, opt, false) then
  1520. exclude(init_settings.localswitches,cs_do_inline)
  1521. else
  1522. include(init_settings.localswitches,cs_do_inline);
  1523. 'k' :
  1524. If UnsetBool(More, j, opt, false) then
  1525. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1526. else
  1527. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1528. 'm' :
  1529. If UnsetBool(More, j, opt, false) then
  1530. exclude(init_settings.moduleswitches,cs_support_macro)
  1531. else
  1532. include(init_settings.moduleswitches,cs_support_macro);
  1533. 'o' : //an alternative to -Mtp
  1534. SetCompileMode('TP',true);
  1535. {$ifdef gpc_mode}
  1536. 'p' : //an alternative to -Mgpc
  1537. SetCompileMode('GPC',true);
  1538. {$endif}
  1539. 's' :
  1540. If UnsetBool(More, j, opt, false) then
  1541. exclude(init_settings.globalswitches,cs_constructor_name)
  1542. else
  1543. include(init_settings.globalswitches,cs_constructor_name);
  1544. 't' :
  1545. Message1(option_obsolete_switch,'-St');
  1546. 'v' :
  1547. If UnsetBool(More, j, opt, false) then
  1548. exclude(init_settings.globalswitches,cs_support_vectors)
  1549. else
  1550. include(init_settings.globalswitches,cs_support_vectors);
  1551. 'x' :
  1552. If UnsetBool(More, j, opt, false) then
  1553. exclude(init_settings.globalswitches,cs_support_exceptions)
  1554. else
  1555. include(init_settings.globalswitches,cs_support_exceptions);
  1556. 'y' :
  1557. If UnsetBool(More, j, opt, false) then
  1558. exclude(init_settings.localswitches,cs_typed_addresses)
  1559. else
  1560. include(init_settings.localswitches,cs_typed_addresses);
  1561. '-' :
  1562. begin
  1563. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1564. cs_support_vectors,cs_load_fpcylix_unit];
  1565. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  1566. cs_typed_addresses];
  1567. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1568. cs_support_macro];
  1569. end;
  1570. else
  1571. IllegalPara(opt);
  1572. end;
  1573. inc(j);
  1574. end;
  1575. end;
  1576. end;
  1577. 'T' :
  1578. begin
  1579. more:=Upper(More);
  1580. if paratarget=system_none then
  1581. begin
  1582. { remove old target define }
  1583. TargetOptions(false);
  1584. { load new target }
  1585. paratarget:=find_system_by_string(More);
  1586. if paratarget<>system_none then
  1587. set_target(paratarget)
  1588. else
  1589. IllegalPara(opt);
  1590. { set new define }
  1591. TargetOptions(true);
  1592. end
  1593. else
  1594. if More<>upper(target_info.shortname) then
  1595. Message1(option_target_is_already_set,target_info.shortname);
  1596. end;
  1597. 'u' :
  1598. if more <> '' then
  1599. undef_system_macro(more);
  1600. 'U' :
  1601. begin
  1602. j:=1;
  1603. while j<=length(more) do
  1604. begin
  1605. case more[j] of
  1606. {$ifdef UNITALIASES}
  1607. 'a' :
  1608. begin
  1609. AddUnitAlias(Copy(More,j+1,255));
  1610. break;
  1611. end;
  1612. {$endif UNITALIASES}
  1613. 'n' :
  1614. exclude(init_settings.globalswitches,cs_check_unit_name);
  1615. 'p' :
  1616. begin
  1617. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1618. break;
  1619. end;
  1620. 'r' :
  1621. do_release:=true;
  1622. 's' :
  1623. include(init_settings.moduleswitches,cs_compilesystem);
  1624. '-' :
  1625. begin
  1626. exclude(init_settings.moduleswitches,cs_compilesystem);
  1627. exclude(init_settings.globalswitches,cs_check_unit_name);
  1628. end;
  1629. else
  1630. IllegalPara(opt);
  1631. end;
  1632. inc(j);
  1633. end;
  1634. end;
  1635. 'v' :
  1636. begin
  1637. if not setverbosity(More) then
  1638. IllegalPara(opt);
  1639. end;
  1640. 'V' : ; { Ignore used by fpc }
  1641. 'W' :
  1642. begin
  1643. j:=1;
  1644. while j<=length(More) do
  1645. begin
  1646. case More[j] of
  1647. 'A':
  1648. begin
  1649. if target_info.system in systems_all_windows then
  1650. begin
  1651. if UnsetBool(More, j, opt, false) then
  1652. SetApptype(app_cui)
  1653. else
  1654. SetApptype(app_native);
  1655. end
  1656. else
  1657. IllegalPara(opt);
  1658. end;
  1659. 'b':
  1660. begin
  1661. if target_info.system in systems_darwin then
  1662. begin
  1663. if UnsetBool(More, j, opt, false) then
  1664. SetApptype(app_cui)
  1665. else
  1666. SetApptype(app_bundle)
  1667. end
  1668. else
  1669. IllegalPara(opt);
  1670. end;
  1671. 'B':
  1672. begin
  1673. if target_info.system in systems_all_windows+systems_symbian then
  1674. begin
  1675. { -WB200000 means set trefered base address
  1676. to $200000, but does not change relocsection boolean
  1677. this way we can create both relocatble and
  1678. non relocatable DLL at a specific base address PM }
  1679. if (length(More)>j) then
  1680. begin
  1681. val('$'+Copy(More,j+1,255),imagebase,code);
  1682. if code<>0 then
  1683. IllegalPara(opt);
  1684. ImageBaseSetExplicity:=true;
  1685. end
  1686. else
  1687. begin
  1688. RelocSection:=true;
  1689. RelocSectionSetExplicitly:=true;
  1690. end;
  1691. break;
  1692. end
  1693. else
  1694. IllegalPara(opt);
  1695. end;
  1696. 'C':
  1697. begin
  1698. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1699. begin
  1700. if UnsetBool(More, j, opt, false) then
  1701. SetApptype(app_gui)
  1702. else
  1703. SetApptype(app_cui);
  1704. end
  1705. else
  1706. IllegalPara(opt);
  1707. end;
  1708. 'D':
  1709. begin
  1710. if target_info.system in systems_all_windows then
  1711. begin
  1712. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  1713. UseDeffileForExportsSetExplicitly:=true;
  1714. end
  1715. else
  1716. IllegalPara(opt);
  1717. end;
  1718. 'e':
  1719. begin
  1720. if (target_info.system in systems_darwin) then
  1721. begin
  1722. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1723. set_target_res(res_ext);
  1724. target_info.resobjext:='.fpcres';
  1725. end
  1726. else
  1727. IllegalPara(opt);
  1728. end;
  1729. 'F':
  1730. begin
  1731. if target_info.system in systems_os2 then
  1732. begin
  1733. if UnsetBool(More, j, opt, false) then
  1734. SetApptype(app_cui)
  1735. else
  1736. SetApptype(app_fs);
  1737. end
  1738. else
  1739. IllegalPara(opt);
  1740. end;
  1741. 'G':
  1742. begin
  1743. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  1744. begin
  1745. if UnsetBool(More, j, opt, false) then
  1746. SetApptype(app_cui)
  1747. else
  1748. SetApptype(app_gui);
  1749. end
  1750. else
  1751. IllegalPara(opt);
  1752. end;
  1753. 'I':
  1754. begin
  1755. if target_info.system in systems_all_windows then
  1756. begin
  1757. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  1758. GenerateImportSectionSetExplicitly:=true;
  1759. end
  1760. else
  1761. IllegalPara(opt);
  1762. end;
  1763. 'i':
  1764. begin
  1765. if (target_info.system in systems_darwin) then
  1766. begin
  1767. set_target_res(res_macho);
  1768. target_info.resobjext:=
  1769. targetinfos[target_info.system]^.resobjext;
  1770. end
  1771. else
  1772. IllegalPara(opt);
  1773. end;
  1774. 'm':
  1775. begin
  1776. {$if defined(i8086)}
  1777. if (target_info.system in [system_i8086_msdos]) then
  1778. begin
  1779. case Upper(Copy(More,j+1,255)) of
  1780. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  1781. 'SMALL': init_settings.x86memorymodel:=mm_small;
  1782. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  1783. 'COMPACT',
  1784. 'LARGE',
  1785. 'HUGE': IllegalPara(opt); { these are not implemented yet }
  1786. else
  1787. IllegalPara(opt);
  1788. end;
  1789. break;
  1790. end
  1791. else
  1792. {$endif defined(i8086)}
  1793. IllegalPara(opt);
  1794. end;
  1795. 'M':
  1796. begin
  1797. if (target_info.system in (systems_darwin-[system_i386_iphonesim])) and
  1798. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  1799. begin
  1800. break;
  1801. end
  1802. else
  1803. IllegalPara(opt);
  1804. end;
  1805. 'N':
  1806. begin
  1807. if target_info.system in systems_all_windows then
  1808. begin
  1809. RelocSection:=UnsetBool(More,j,opt,false);
  1810. RelocSectionSetExplicitly:=true;
  1811. end
  1812. else
  1813. IllegalPara(opt);
  1814. end;
  1815. 'p':
  1816. begin
  1817. {$if defined(arm) or defined(avr)}
  1818. if (target_info.system in systems_embedded) then
  1819. begin
  1820. s:=upper(copy(more,j+1,length(more)-j));
  1821. if not(SetControllerType(s,init_settings.controllertype)) then
  1822. IllegalPara(opt);
  1823. break;
  1824. end
  1825. else
  1826. {$endif defined(arm) or defined(avr)}
  1827. IllegalPara(opt);
  1828. end;
  1829. 'P':
  1830. begin
  1831. if (target_info.system in [system_i386_iphonesim,system_arm_darwin]) and
  1832. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  1833. begin
  1834. break;
  1835. end
  1836. else
  1837. IllegalPara(opt);
  1838. end;
  1839. 'R':
  1840. begin
  1841. if target_info.system in systems_all_windows then
  1842. begin
  1843. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1844. RelocSection:=not UnsetBool(More,j,opt,false);
  1845. RelocSectionSetExplicitly:=true;
  1846. end
  1847. else
  1848. IllegalPara(opt);
  1849. end;
  1850. 'T':
  1851. begin
  1852. if target_info.system in systems_macos then
  1853. begin
  1854. if UnsetBool(More, j, opt, false) then
  1855. SetApptype(app_cui)
  1856. else
  1857. SetApptype(app_tool);
  1858. end
  1859. else
  1860. IllegalPara(opt);
  1861. end;
  1862. 'X':
  1863. begin
  1864. if (target_info.system in systems_linux) then
  1865. begin
  1866. if UnsetBool(More, j, opt, false) then
  1867. exclude(init_settings.moduleswitches,cs_executable_stack)
  1868. else
  1869. include(init_settings.moduleswitches,cs_executable_stack)
  1870. end
  1871. else
  1872. IllegalPara(opt);
  1873. end;
  1874. else
  1875. IllegalPara(opt);
  1876. end;
  1877. inc(j);
  1878. end;
  1879. end;
  1880. 'X' :
  1881. begin
  1882. j:=1;
  1883. while j<=length(more) do
  1884. begin
  1885. case More[j] of
  1886. 'c' : Cshared:=TRUE;
  1887. 'd' : Dontlinkstdlibpath:=TRUE;
  1888. 'e' :
  1889. begin
  1890. If UnsetBool(More, j, opt, false) then
  1891. exclude(init_settings.globalswitches,cs_link_extern)
  1892. else
  1893. include(init_settings.globalswitches,cs_link_extern);
  1894. end;
  1895. 'f' :
  1896. include(init_settings.globalswitches,cs_link_pthread);
  1897. 'g' :
  1898. begin
  1899. If UnsetBool(More, j, opt, false) then
  1900. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1901. else
  1902. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1903. end;
  1904. 'i' :
  1905. begin
  1906. If UnsetBool(More, j, opt, false) then
  1907. include(init_settings.globalswitches,cs_link_extern)
  1908. else
  1909. exclude(init_settings.globalswitches,cs_link_extern);
  1910. end;
  1911. 'n' :
  1912. begin
  1913. If UnsetBool(More, j, opt, false) then
  1914. exclude(init_settings.globalswitches,cs_link_native)
  1915. else
  1916. include(init_settings.globalswitches,cs_link_native);
  1917. end;
  1918. 'm' :
  1919. begin
  1920. If UnsetBool(More, j, opt, false) then
  1921. exclude(init_settings.globalswitches,cs_link_map)
  1922. else
  1923. include(init_settings.globalswitches,cs_link_map);
  1924. end;
  1925. 'p' : ; { Ignore used by fpc.pp }
  1926. 'r' :
  1927. begin
  1928. if (target_info.system in suppported_targets_x_smallr) then
  1929. begin
  1930. rlinkpath:=Copy(more,2,length(More)-1);
  1931. DefaultReplacements(rlinkpath);
  1932. end
  1933. else
  1934. IgnoredPara('-Xr');
  1935. more:='';
  1936. end;
  1937. 'R' :
  1938. begin
  1939. sysrootpath:=copy(more,2,length(more)-1);
  1940. defaultreplacements(sysrootpath);
  1941. more:='';
  1942. end;
  1943. 's' :
  1944. begin
  1945. If UnsetBool(More, j, opt, false) then
  1946. exclude(init_settings.globalswitches,cs_link_strip)
  1947. else
  1948. include(init_settings.globalswitches,cs_link_strip);
  1949. end;
  1950. 't' :
  1951. include(init_settings.globalswitches,cs_link_staticflag);
  1952. 'v' :
  1953. begin
  1954. If UnsetBool(More, j, opt, false) then
  1955. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1956. else
  1957. include(init_settings.globalswitches,cs_link_opt_vtable);
  1958. end;
  1959. 'D' :
  1960. begin
  1961. def_system_macro('FPC_LINK_DYNAMIC');
  1962. undef_system_macro('FPC_LINK_SMART');
  1963. undef_system_macro('FPC_LINK_STATIC');
  1964. exclude(init_settings.globalswitches,cs_link_static);
  1965. exclude(init_settings.globalswitches,cs_link_smart);
  1966. include(init_settings.globalswitches,cs_link_shared);
  1967. LinkTypeSetExplicitly:=true;
  1968. end;
  1969. 'M' :
  1970. begin
  1971. mainaliasname:=Copy(more,2,length(More)-1);
  1972. More:='';
  1973. end;
  1974. 'P' :
  1975. begin
  1976. utilsprefix:=Copy(more,2,length(More)-1);
  1977. DefaultReplacements(utilsprefix);
  1978. More:='';
  1979. end;
  1980. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1981. // these are not aggregable.
  1982. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1983. IllegalPara(opt)
  1984. else
  1985. begin
  1986. case more[j+1] of
  1987. 'A' : begin
  1988. s:=Copy(more,3,length(More)-2);
  1989. if not LinkLibraryAliases.AddDep(s) Then
  1990. IllegalPara(opt);
  1991. end;
  1992. 'O' : begin
  1993. s:=Copy(more,3,length(More)-2);
  1994. if not LinkLibraryOrder.AddWeight(s) Then
  1995. IllegalPara(opt);
  1996. end;
  1997. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1998. else
  1999. IllegalPara(opt);
  2000. end; {case}
  2001. j:=length(more);
  2002. end; {else begin}
  2003. end;
  2004. 'S' :
  2005. begin
  2006. ForceStaticLinking;
  2007. end;
  2008. 'X' :
  2009. begin
  2010. def_system_macro('FPC_LINK_SMART');
  2011. undef_system_macro('FPC_LINK_STATIC');
  2012. undef_system_macro('FPC_LINK_DYNAMIC');
  2013. exclude(init_settings.globalswitches,cs_link_static);
  2014. include(init_settings.globalswitches,cs_link_smart);
  2015. exclude(init_settings.globalswitches,cs_link_shared);
  2016. LinkTypeSetExplicitly:=true;
  2017. end;
  2018. '-' :
  2019. begin
  2020. exclude(init_settings.globalswitches,cs_link_staticflag);
  2021. exclude(init_settings.globalswitches,cs_link_strip);
  2022. exclude(init_settings.globalswitches,cs_link_map);
  2023. set_default_link_type;
  2024. end;
  2025. else
  2026. IllegalPara(opt);
  2027. end;
  2028. inc(j);
  2029. end;
  2030. end;
  2031. else
  2032. IllegalPara(opt);
  2033. end;
  2034. end;
  2035. '@' :
  2036. begin
  2037. Message(option_no_nested_response_file);
  2038. StopOptions(1);
  2039. end;
  2040. else
  2041. begin
  2042. if (length(param_file)<>0) then
  2043. Message2(option_only_one_source_support,param_file,opt);
  2044. param_file:=opt;
  2045. Message1(option_found_file,opt);
  2046. end;
  2047. end;
  2048. end;
  2049. procedure Toption.Interpret_file(const filename : TPathStr);
  2050. procedure RemoveSep(var fn:TPathStr);
  2051. var
  2052. i : longint;
  2053. begin
  2054. i:=0;
  2055. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2056. inc(i);
  2057. Delete(fn,1,i);
  2058. i:=length(fn);
  2059. while (i>0) and (fn[i] in [',',' ',#9]) do
  2060. dec(i);
  2061. fn:=copy(fn,1,i);
  2062. end;
  2063. function GetName(var fn:TPathStr):TPathStr;
  2064. var
  2065. i : longint;
  2066. begin
  2067. i:=0;
  2068. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2069. inc(i);
  2070. GetName:=Copy(fn,1,i);
  2071. Delete(fn,1,i);
  2072. end;
  2073. const
  2074. maxlevel = 15;
  2075. var
  2076. f : text;
  2077. s, tmp,
  2078. opts : TCmdStr;
  2079. skip : array[0..maxlevel] of boolean;
  2080. line,
  2081. level : longint;
  2082. option_read : boolean;
  2083. oldfilemode : byte;
  2084. ConfigFile: TPathStr;
  2085. begin
  2086. { avoid infinite loop }
  2087. Inc(FileLevel);
  2088. Option_read:=false;
  2089. If FileLevel>MaxLevel then
  2090. Message(option_too_many_cfg_files);
  2091. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2092. ConfigFile := ExpandFileName(filename);
  2093. { Maybe It's Directory ?} //Jaro Change:
  2094. if PathExists(ConfigFile,false) then
  2095. begin
  2096. Message1(option_config_is_dir,filename);
  2097. exit;
  2098. end;
  2099. { open file }
  2100. Message1(option_using_file,filename);
  2101. oldfilemode:=filemode;
  2102. filemode:=0;
  2103. assign(f,ConfigFile);
  2104. {$push}{$I-}
  2105. reset(f);
  2106. {$pop}
  2107. filemode:=oldfilemode;
  2108. if ioresult<>0 then
  2109. begin
  2110. Message1(option_unable_open_file,filename);
  2111. exit;
  2112. end;
  2113. Message1(option_start_reading_configfile,filename);
  2114. fillchar(skip,sizeof(skip),0);
  2115. level:=0;
  2116. line:=0;
  2117. while not eof(f) do
  2118. begin
  2119. readln(f,opts);
  2120. inc(line);
  2121. RemoveSep(opts);
  2122. if (opts<>'') and (opts[1]<>';') then
  2123. begin
  2124. if opts[1]='#' then
  2125. begin
  2126. Message1(option_interpreting_file_option,opts);
  2127. Delete(opts,1,1);
  2128. s:=upper(GetName(opts));
  2129. if (s='SECTION') then
  2130. begin
  2131. RemoveSep(opts);
  2132. s:=upper(GetName(opts));
  2133. if level=0 then
  2134. skip[level]:=not defined_macro(s) or (s='COMMON');
  2135. end
  2136. else
  2137. if (s='IFDEF') then
  2138. begin
  2139. RemoveSep(opts);
  2140. if Level>=maxlevel then
  2141. begin
  2142. Message2(option_too_many_ifdef,filename,tostr(line));
  2143. stopOptions(1);
  2144. end;
  2145. inc(Level);
  2146. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2147. end
  2148. else
  2149. if (s='IFNDEF') then
  2150. begin
  2151. RemoveSep(opts);
  2152. if Level>=maxlevel then
  2153. begin
  2154. Message2(option_too_many_ifdef,filename,tostr(line));
  2155. stopOptions(1);
  2156. end;
  2157. inc(Level);
  2158. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2159. end
  2160. else
  2161. if (s='ELSE') then
  2162. begin
  2163. if Level=0 then
  2164. begin
  2165. Message2(option_else_without_if,filename,tostr(line));
  2166. stopOptions(1);
  2167. end
  2168. else
  2169. skip[level]:=skip[level-1] or (not skip[level])
  2170. end
  2171. else
  2172. if (s='ENDIF') then
  2173. begin
  2174. skip[level]:=false;
  2175. if Level=0 then
  2176. begin
  2177. Message2(option_too_many_endif,filename,tostr(line));
  2178. stopOptions(1);
  2179. end;
  2180. dec(level);
  2181. end
  2182. else
  2183. if (not skip[level]) then
  2184. begin
  2185. if (s='DEFINE') then
  2186. begin
  2187. RemoveSep(opts);
  2188. tmp:= GetName(opts);
  2189. if tmp <> '' then
  2190. def_system_macro(tmp);
  2191. Option_read:=true;
  2192. end
  2193. else
  2194. if (s='UNDEF') then
  2195. begin
  2196. RemoveSep(opts);
  2197. tmp:= GetName(opts);
  2198. if tmp <> '' then
  2199. undef_system_macro(tmp);
  2200. Option_read:=true;
  2201. end
  2202. else
  2203. if (s='WRITE') then
  2204. begin
  2205. Delete(opts,1,1);
  2206. WriteLn(opts);
  2207. Option_read:=true;
  2208. end
  2209. else
  2210. if (s='INCLUDE') then
  2211. begin
  2212. Delete(opts,1,1);
  2213. Interpret_file(opts);
  2214. Option_read:=true;
  2215. end
  2216. else
  2217. if (s='CFGDIR') then
  2218. begin
  2219. Delete(opts,1,1);
  2220. DefaultReplacements(opts);
  2221. ParaIncludeCfgPath.AddPath(opts,false);
  2222. Option_read:=true;
  2223. end;
  2224. end;
  2225. end
  2226. else
  2227. begin
  2228. if (opts[1]='-') or (opts[1]='@') then
  2229. begin
  2230. if (not skip[level]) then
  2231. interpret_option(opts,false);
  2232. Option_read:=true;
  2233. end
  2234. else
  2235. Message1(option_illegal_para,opts);
  2236. end;
  2237. end;
  2238. end;
  2239. if Level>0 then
  2240. Message(option_too_less_endif);
  2241. if Not Option_read then
  2242. Message1(option_no_option_found,filename)
  2243. else
  2244. Message1(option_end_reading_configfile,filename);
  2245. Close(f);
  2246. Dec(FileLevel);
  2247. end;
  2248. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2249. var
  2250. argstart,
  2251. env,
  2252. pc : pchar;
  2253. arglen : longint;
  2254. quote : set of char;
  2255. hs : TCmdStr;
  2256. begin
  2257. Message1(option_using_env,envname);
  2258. env:=GetEnvPChar(envname);
  2259. pc:=env;
  2260. if assigned(pc) then
  2261. begin
  2262. repeat
  2263. { skip leading spaces }
  2264. while pc^ in [' ',#9,#13] do
  2265. inc(pc);
  2266. case pc^ of
  2267. #0 :
  2268. break;
  2269. '"' :
  2270. begin
  2271. quote:=['"'];
  2272. inc(pc);
  2273. end;
  2274. '''' :
  2275. begin
  2276. quote:=[''''];
  2277. inc(pc);
  2278. end;
  2279. else
  2280. quote:=[' ',#9,#13];
  2281. end;
  2282. { scan until the end of the argument }
  2283. argstart:=pc;
  2284. while (pc^<>#0) and not(pc^ in quote) do
  2285. inc(pc);
  2286. { create argument }
  2287. arglen:=pc-argstart;
  2288. { TODO: FIXME: silent truncation of environment parameters }
  2289. if (arglen > 255) then
  2290. arglen := 255;
  2291. setlength(hs,arglen);
  2292. move(argstart^,hs[1],arglen);
  2293. interpret_option(hs,true);
  2294. { skip quote }
  2295. if pc^ in quote then
  2296. inc(pc);
  2297. until false;
  2298. end
  2299. else
  2300. Message1(option_no_option_found,'(env) '+envname);
  2301. FreeEnvPChar(env);
  2302. end;
  2303. procedure toption.read_parameters;
  2304. var
  2305. opts : TCmdStr;
  2306. paramindex : longint;
  2307. begin
  2308. paramindex:=0;
  2309. while paramindex<paramcount do
  2310. begin
  2311. inc(paramindex);
  2312. opts:=objpas.paramstr(paramindex);
  2313. if length(opts)>0 then
  2314. case opts[1] of
  2315. '@' :
  2316. if not firstpass then
  2317. begin
  2318. Delete(opts,1,1);
  2319. Message1(option_reading_further_from,opts);
  2320. interpret_file(opts);
  2321. end;
  2322. '!' :
  2323. if not firstpass then
  2324. begin
  2325. Delete(opts,1,1);
  2326. Message1(option_reading_further_from,'(env) '+opts);
  2327. interpret_envvar(opts);
  2328. end;
  2329. else
  2330. interpret_option(opts,true);
  2331. end;
  2332. end;
  2333. end;
  2334. procedure toption.parsecmd(cmd:TCmdStr);
  2335. var
  2336. i,ps : longint;
  2337. opts : TCmdStr;
  2338. begin
  2339. while (cmd<>'') do
  2340. begin
  2341. while cmd[1]=' ' do
  2342. delete(cmd,1,1);
  2343. i:=pos(' ',cmd);
  2344. if i=0 then
  2345. i:=2147483647;
  2346. opts:=Copy(cmd,1,i-1);
  2347. Delete(cmd,1,i);
  2348. case opts[1] of
  2349. '@' :
  2350. if not firstpass then
  2351. begin
  2352. Delete(opts,1,1);
  2353. Message1(option_reading_further_from,opts);
  2354. interpret_file(opts);
  2355. end;
  2356. '!' :
  2357. if not firstpass then
  2358. begin
  2359. Delete(opts,1,1);
  2360. Message1(option_reading_further_from,'(env) '+opts);
  2361. interpret_envvar(opts);
  2362. end;
  2363. '"' :
  2364. begin
  2365. Delete(opts,1,1);
  2366. ps:=pos('"',cmd);
  2367. if (i<>256) and (ps>0) then
  2368. begin
  2369. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2370. cmd:=copy(cmd,ps+1,255);
  2371. end;
  2372. interpret_option(opts,true);
  2373. end;
  2374. else
  2375. interpret_option(opts,true);
  2376. end;
  2377. end;
  2378. end;
  2379. procedure toption.writequickinfo;
  2380. var
  2381. s : string;
  2382. i : longint;
  2383. procedure addinfo(const hs:string);
  2384. begin
  2385. if s<>'' then
  2386. s:=s+' '+hs
  2387. else
  2388. s:=hs;
  2389. end;
  2390. begin
  2391. s:='';
  2392. i:=0;
  2393. while (i<length(quickinfo)) do
  2394. begin
  2395. inc(i);
  2396. case quickinfo[i] of
  2397. 'S' :
  2398. begin
  2399. inc(i);
  2400. case quickinfo[i] of
  2401. 'O' :
  2402. addinfo(lower(source_info.shortname));
  2403. 'P' :
  2404. addinfo(source_cpu_string);
  2405. else
  2406. IllegalPara('-i'+QuickInfo);
  2407. end;
  2408. end;
  2409. 'T' :
  2410. begin
  2411. inc(i);
  2412. case quickinfo[i] of
  2413. 'O' :
  2414. addinfo(lower(target_info.shortname));
  2415. 'P' :
  2416. AddInfo(target_cpu_string);
  2417. else
  2418. IllegalPara('-i'+QuickInfo);
  2419. end;
  2420. end;
  2421. 'V' :
  2422. AddInfo(version_string);
  2423. 'W' :
  2424. AddInfo(full_version_string);
  2425. 'D' :
  2426. AddInfo(date_string);
  2427. '_' :
  2428. ;
  2429. else
  2430. IllegalPara('-i'+QuickInfo);
  2431. end;
  2432. end;
  2433. if s<>'' then
  2434. begin
  2435. writeln(s);
  2436. stopoptions(0);
  2437. end;
  2438. end;
  2439. procedure TOption.TargetOptions(def:boolean);
  2440. var
  2441. s : string;
  2442. i : integer;
  2443. target_unsup_features : tfeatures;
  2444. begin
  2445. if def then
  2446. def_system_macro(target_info.shortname)
  2447. else
  2448. undef_system_macro(target_info.shortname);
  2449. s:=target_info.extradefines;
  2450. while (s<>'') do
  2451. begin
  2452. i:=pos(';',s);
  2453. if i=0 then
  2454. i:=length(s)+1;
  2455. if def then
  2456. def_system_macro(Copy(s,1,i-1))
  2457. else
  2458. undef_system_macro(Copy(s,1,i-1));
  2459. delete(s,1,i);
  2460. end;
  2461. if (tf_winlikewidestring in target_info.flags) then
  2462. if def then
  2463. def_system_macro('FPC_WINLIKEWIDESTRING')
  2464. else
  2465. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2466. if (tf_requires_proper_alignment in target_info.flags) then
  2467. if def then
  2468. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2469. else
  2470. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2471. if source_info.system<>target_info.system then
  2472. if def then
  2473. def_system_macro('FPC_CROSSCOMPILING')
  2474. else
  2475. undef_system_macro('FPC_CROSSCOMPILING');
  2476. if source_info.cpu<>target_info.cpu then
  2477. if def then
  2478. def_system_macro('FPC_CPUCROSSCOMPILING')
  2479. else
  2480. def_system_macro('FPC_CPUCROSSCOMPILING');
  2481. if (tf_no_generic_stackcheck in target_info.flags) then
  2482. if def then
  2483. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2484. else
  2485. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2486. if (tf_section_threadvars in target_info.flags) then
  2487. if def then
  2488. def_system_macro('FPC_SECTION_THREADVARS')
  2489. else
  2490. undef_system_macro('FPC_SECTION_THREADVARS');
  2491. { Code generation flags }
  2492. if def and
  2493. (tf_pic_default in target_info.flags) then
  2494. include(init_settings.moduleswitches,cs_create_pic)
  2495. else
  2496. exclude(init_settings.moduleswitches,cs_create_pic);
  2497. { Resources support }
  2498. if (tf_has_winlike_resources in target_info.flags) then
  2499. if def then
  2500. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2501. else
  2502. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2503. { Features }
  2504. case target_info.system of
  2505. system_arm_gba:
  2506. target_unsup_features:=[f_dynlibs];
  2507. system_arm_nds:
  2508. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2509. system_i386_nativent:
  2510. // until these features are implemented, they are disabled in the compiler
  2511. target_unsup_features:=[f_stackcheck];
  2512. system_jvm_java32,
  2513. system_jvm_android32:
  2514. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2515. f_variants,f_objects,f_commandargs,
  2516. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2517. else
  2518. target_unsup_features:=[];
  2519. end;
  2520. if def then
  2521. features:=features-target_unsup_features
  2522. else
  2523. features:=features+target_unsup_features;
  2524. end;
  2525. procedure TOption.checkoptionscompatibility;
  2526. begin
  2527. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2528. not(target_info.system in systems_darwin) then
  2529. begin
  2530. { smartlink creation does not yet work with DWARF
  2531. debug info on most targets, but it works in internal assembler }
  2532. if (cs_create_smart in init_settings.moduleswitches) and
  2533. not (af_outputbinary in target_asm.flags) then
  2534. begin
  2535. Message(option_dwarf_smartlink_creation);
  2536. exclude(init_settings.moduleswitches,cs_create_smart);
  2537. end;
  2538. { smart linking does not yet work with DWARF debug info on most targets }
  2539. if (cs_link_smart in init_settings.globalswitches) then
  2540. begin
  2541. Message(option_dwarf_smart_linking);
  2542. ForceStaticLinking;
  2543. end;
  2544. end;
  2545. { external debug info is only supported for DWARF on darwin }
  2546. if (target_info.system in systems_darwin) and
  2547. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2548. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2549. begin
  2550. Message(option_debug_external_unsupported);
  2551. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2552. end;
  2553. end;
  2554. constructor TOption.create;
  2555. begin
  2556. LogoWritten:=false;
  2557. NoPressEnter:=false;
  2558. FirstPass:=false;
  2559. FPUSetExplicitly:=false;
  2560. CPUSetExplicitly:=false;
  2561. OptCPUSetExplicitly:=false;
  2562. FileLevel:=0;
  2563. Quickinfo:='';
  2564. ParaIncludeCfgPath:=TSearchPathList.Create;
  2565. ParaIncludePath:=TSearchPathList.Create;
  2566. ParaObjectPath:=TSearchPathList.Create;
  2567. ParaUnitPath:=TSearchPathList.Create;
  2568. ParaLibraryPath:=TSearchPathList.Create;
  2569. ParaFrameworkPath:=TSearchPathList.Create;
  2570. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2571. MacVersionSet:=false;
  2572. end;
  2573. destructor TOption.destroy;
  2574. begin
  2575. ParaIncludeCfgPath.Free;
  2576. ParaIncludePath.Free;
  2577. ParaObjectPath.Free;
  2578. ParaUnitPath.Free;
  2579. ParaLibraryPath.Free;
  2580. ParaFrameworkPath.Free;
  2581. end;
  2582. {****************************************************************************
  2583. Callable Routines
  2584. ****************************************************************************}
  2585. function check_configfile(const fn:string;var foundfn:string):boolean;
  2586. function CfgFileExists(const fn:string):boolean;
  2587. begin
  2588. Comment(V_Tried,'Configfile search: '+fn);
  2589. CfgFileExists:=FileExists(fn);
  2590. end;
  2591. var
  2592. {$ifdef Unix}
  2593. hs,
  2594. {$endif Unix}
  2595. configpath : string;
  2596. begin
  2597. foundfn:=fn;
  2598. check_configfile:=true;
  2599. { retrieve configpath }
  2600. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2601. {$ifdef Unix}
  2602. if configpath='' then
  2603. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2604. {$endif}
  2605. {
  2606. Order to read configuration file :
  2607. try reading fpc.cfg in :
  2608. 1 - current dir
  2609. 2 - configpath
  2610. 3 - compiler path
  2611. }
  2612. if not FileExists(fn) then
  2613. begin
  2614. {$ifdef Unix}
  2615. hs:=GetEnvironmentVariable('HOME');
  2616. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2617. foundfn:=FixPath(hs,false)+'.'+fn
  2618. else
  2619. {$endif}
  2620. if CfgFileExists(configpath+fn) then
  2621. foundfn:=configpath+fn
  2622. else
  2623. {$ifdef WINDOWS}
  2624. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  2625. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  2626. else
  2627. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  2628. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  2629. else
  2630. {$endif WINDOWS}
  2631. {$ifndef Unix}
  2632. if CfgFileExists(exepath+fn) then
  2633. foundfn:=exepath+fn
  2634. else
  2635. {$else}
  2636. if CfgFileExists('/etc/'+fn) then
  2637. foundfn:='/etc/'+fn
  2638. else
  2639. {$endif}
  2640. check_configfile:=false;
  2641. end;
  2642. end;
  2643. procedure read_arguments(cmd:TCmdStr);
  2644. var
  2645. env: ansistring;
  2646. i : tfeature;
  2647. abi : tabi;
  2648. {$if defined(arm) or defined(avr)}
  2649. cpuflag : tcpuflags;
  2650. hs : string;
  2651. {$endif defined(arm) or defined(avr)}
  2652. begin
  2653. option:=coption.create;
  2654. disable_configfile:=false;
  2655. { Non-core target defines }
  2656. Option.TargetOptions(true);
  2657. { get default messagefile }
  2658. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2659. { default configfile can be specified on the commandline,
  2660. remove it first }
  2661. if (cmd<>'') and (cmd[1]='[') then
  2662. begin
  2663. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2664. Delete(cmd,1,pos(']',cmd));
  2665. end
  2666. else
  2667. ppccfg:='fpc.cfg';
  2668. { first pass reading of parameters, only -i -v -T etc.}
  2669. option.firstpass:=true;
  2670. if cmd<>'' then
  2671. option.parsecmd(cmd)
  2672. else
  2673. begin
  2674. option.read_parameters;
  2675. { Write only quickinfo }
  2676. if option.quickinfo<>'' then
  2677. option.writequickinfo;
  2678. end;
  2679. option.firstpass:=false;
  2680. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  2681. Option.TargetOptions(true);
  2682. { target is set here, for wince the default app type is gui }
  2683. if target_info.system in systems_wince then
  2684. SetApptype(app_gui)
  2685. else
  2686. SetApptype(apptype);
  2687. { default defines }
  2688. def_system_macro(target_info.shortname);
  2689. def_system_macro('FPC');
  2690. def_system_macro('VER'+version_nr);
  2691. def_system_macro('VER'+version_nr+'_'+release_nr);
  2692. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2693. { Temporary defines, until things settle down }
  2694. def_system_macro('RESSTRSECTIONS');
  2695. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2696. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2697. def_system_macro('FPC_HAS_VARSETS');
  2698. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2699. def_system_macro('FPC_HAS_STR_CURRENCY');
  2700. def_system_macro('FPC_REAL2REAL_FIXED');
  2701. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2702. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2703. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2704. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2705. def_system_macro('FPC_HAS_CONSTREF');
  2706. def_system_macro('FPC_STATICRIPFIXED');
  2707. def_system_macro('FPC_VARIANTCOPY_FIXED');
  2708. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  2709. {$if defined(x86) or defined(powerpc) or defined(powerpc64) or defined(cpuarm)}
  2710. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2711. {$endif}
  2712. def_system_macro('FPC_HAS_UNICODESTRING');
  2713. def_system_macro('FPC_RTTI_PACKSET1');
  2714. def_system_macro('FPC_HAS_CPSTRING');
  2715. {$ifdef x86_64}
  2716. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2717. {$endif x86_64}
  2718. def_system_macro('FPC_HAS_CEXTENDED');
  2719. def_system_macro('FPC_HAS_RESSTRINITS');
  2720. { these cpus have an inline rol/ror implementaion }
  2721. {$ifdef cpurox}
  2722. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2723. {$endif}
  2724. { these cpus have an inline sar implementaion }
  2725. { currently, all supported CPUs have an internal sar implementation }
  2726. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc) or defined(mips)}
  2727. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2728. { $endif}
  2729. {$ifdef powerpc64}
  2730. def_system_macro('FPC_HAS_LWSYNC');
  2731. {$endif}
  2732. def_system_macro('FPC_HAS_MEMBAR');
  2733. def_system_macro('FPC_SETBASE_USED');
  2734. {$ifdef SUPPORT_GET_FRAME}
  2735. def_system_macro('INTERNAL_BACKTRACE');
  2736. {$endif SUPPORT_GET_FRAME}
  2737. def_system_macro('STR_CONCAT_PROCS');
  2738. {$warnings off}
  2739. if pocall_default = pocall_register then
  2740. def_system_macro('REGCALL');
  2741. {$warnings on}
  2742. { don't remove this, it's also for fpdoc necessary (FK) }
  2743. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2744. { using a case is pretty useless here (FK) }
  2745. { some stuff for TP compatibility }
  2746. {$ifdef i386}
  2747. def_system_macro('CPU86');
  2748. def_system_macro('CPU87');
  2749. def_system_macro('CPU386');
  2750. {$endif}
  2751. { new processor stuff }
  2752. {$ifdef i386}
  2753. def_system_macro('CPUI386');
  2754. def_system_macro('CPU32');
  2755. def_system_macro('CPUX86');
  2756. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2757. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2758. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2759. {$endif}
  2760. {$ifdef m68k}
  2761. def_system_macro('CPU68');
  2762. def_system_macro('CPU68K');
  2763. def_system_macro('CPUM68K');
  2764. def_system_macro('CPU32');
  2765. def_system_macro('FPC_CURRENCY_IS_INT64');
  2766. def_system_macro('FPC_COMP_IS_INT64');
  2767. {$endif}
  2768. {$ifdef ALPHA}
  2769. def_system_macro('CPUALPHA');
  2770. def_system_macro('CPU64');
  2771. {$endif}
  2772. {$ifdef powerpc}
  2773. def_system_macro('CPUPOWERPC');
  2774. def_system_macro('CPUPOWERPC32');
  2775. def_system_macro('CPU32');
  2776. def_system_macro('FPC_CURRENCY_IS_INT64');
  2777. def_system_macro('FPC_COMP_IS_INT64');
  2778. {$endif}
  2779. {$ifdef POWERPC64}
  2780. def_system_macro('CPUPOWERPC');
  2781. def_system_macro('CPUPOWERPC64');
  2782. def_system_macro('CPU64');
  2783. def_system_macro('FPC_CURRENCY_IS_INT64');
  2784. def_system_macro('FPC_COMP_IS_INT64');
  2785. {$endif}
  2786. {$ifdef iA64}
  2787. def_system_macro('CPUIA64');
  2788. def_system_macro('CPU64');
  2789. {$endif}
  2790. {$ifdef x86_64}
  2791. def_system_macro('CPUX86_64');
  2792. def_system_macro('CPUAMD64');
  2793. def_system_macro('CPU64');
  2794. def_system_macro('CPUX64');
  2795. { not supported for now, afaik (FK)
  2796. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2797. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  2798. { normally, win64 doesn't support the legacy fpu }
  2799. if target_info.system=system_x86_64_win64 then
  2800. begin
  2801. def_system_macro('FPC_CURRENCY_IS_INT64');
  2802. def_system_macro('FPC_COMP_IS_INT64');
  2803. end;
  2804. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  2805. {$endif}
  2806. {$ifdef sparc}
  2807. def_system_macro('CPUSPARC');
  2808. def_system_macro('CPUSPARC32');
  2809. def_system_macro('CPU32');
  2810. def_system_macro('FPC_CURRENCY_IS_INT64');
  2811. def_system_macro('FPC_COMP_IS_INT64');
  2812. {$endif}
  2813. {$ifdef vis}
  2814. def_system_macro('CPUVIS');
  2815. def_system_macro('CPU32');
  2816. {$endif}
  2817. {$ifdef arm}
  2818. def_system_macro('CPUARM');
  2819. def_system_macro('CPU32');
  2820. def_system_macro('FPC_CURRENCY_IS_INT64');
  2821. def_system_macro('FPC_COMP_IS_INT64');
  2822. {$endif arm}
  2823. {$ifdef avr}
  2824. def_system_macro('CPUAVR');
  2825. def_system_macro('CPU16');
  2826. def_system_macro('FPC_CURRENCY_IS_INT64');
  2827. def_system_macro('FPC_COMP_IS_INT64');
  2828. {$endif avr}
  2829. {$ifdef jvm}
  2830. def_system_macro('CPUJVM');
  2831. def_system_macro('CPU32');
  2832. def_system_macro('FPC_CURRENCY_IS_INT64');
  2833. def_system_macro('FPC_COMP_IS_INT64');
  2834. {$endif jvm}
  2835. {$ifdef mipsel}
  2836. def_system_macro('CPUMIPS');
  2837. def_system_macro('CPUMIPS32');
  2838. def_system_macro('CPUMIPSEL');
  2839. def_system_macro('CPUMIPSEL32');
  2840. def_system_macro('CPU32');
  2841. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2842. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2843. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2844. def_system_macro('FPC_CURRENCY_IS_INT64');
  2845. def_system_macro('FPC_COMP_IS_INT64');
  2846. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2847. { On most systems, locals are accessed relative to base pointer,
  2848. but for MIPS cpu, they are accessed relative to stack pointer.
  2849. This needs adaptation for so low level routines,
  2850. like MethodPointerLocal and related objects unit functions. }
  2851. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  2852. {$endif mipsel}
  2853. {$ifdef mipseb}
  2854. def_system_macro('CPUMIPS');
  2855. def_system_macro('CPUMIPS32');
  2856. def_system_macro('CPUMIPSEB');
  2857. def_system_macro('CPUMIPSEB32');
  2858. def_system_macro('CPU32');
  2859. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2860. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2861. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2862. def_system_macro('FPC_CURRENCY_IS_INT64');
  2863. def_system_macro('FPC_COMP_IS_INT64');
  2864. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2865. { See comment above for mipsel }
  2866. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  2867. {$endif}
  2868. {$ifdef i8086}
  2869. def_system_macro('CPU86'); { Borland compatibility }
  2870. def_system_macro('CPU87'); { Borland compatibility }
  2871. def_system_macro('CPU8086');
  2872. def_system_macro('CPUI8086');
  2873. def_system_macro('CPU16');
  2874. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2875. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2876. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2877. {$endif i8086}
  2878. { Set up a default prefix for binutils when cross-compiling }
  2879. if source_info.system<>target_info.system then
  2880. case target_info.system of
  2881. { Use standard Android NDK prefixes }
  2882. system_arm_android:
  2883. utilsprefix:='arm-linux-androideabi-';
  2884. system_i386_android:
  2885. utilsprefix:='i686-linux-android-';
  2886. end;
  2887. { Set up default value for the heap }
  2888. if target_info.system in systems_embedded then
  2889. begin
  2890. case target_info.system of
  2891. system_avr_embedded:
  2892. heapsize:=128;
  2893. system_arm_embedded:
  2894. heapsize:=256;
  2895. else
  2896. heapsize:=256;
  2897. end;
  2898. end;
  2899. { read configuration file }
  2900. if (not disable_configfile) and
  2901. (ppccfg<>'') then
  2902. read_configfile:=check_configfile(ppccfg,ppccfg)
  2903. else
  2904. read_configfile := false;
  2905. { Read commandline and configfile }
  2906. param_file:='';
  2907. { read configfile }
  2908. if read_configfile then
  2909. option.interpret_file(ppccfg);
  2910. { read parameters again to override config file }
  2911. if cmd<>'' then
  2912. option.parsecmd(cmd)
  2913. else
  2914. begin
  2915. { Write help pages if no parameters are passed }
  2916. if (paramcount=0) then
  2917. Option.WriteHelpPages;
  2918. option.read_parameters;
  2919. { Write only quickinfo }
  2920. if option.quickinfo<>'' then
  2921. option.writequickinfo;
  2922. end;
  2923. { check the compatibility of different options and adjust them if necessary
  2924. (and print possible errors)
  2925. }
  2926. option.checkoptionscompatibility;
  2927. { Stop if errors in options }
  2928. if ErrorCount>0 then
  2929. StopOptions(1);
  2930. { endian define }
  2931. case target_info.endian of
  2932. endian_little :
  2933. begin
  2934. def_system_macro('ENDIAN_LITTLE');
  2935. def_system_macro('FPC_LITTLE_ENDIAN');
  2936. end;
  2937. endian_big :
  2938. begin
  2939. def_system_macro('ENDIAN_BIG');
  2940. def_system_macro('FPC_BIG_ENDIAN');
  2941. end;
  2942. end;
  2943. { define abi }
  2944. for abi:=low(tabi) to high(tabi) do
  2945. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  2946. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  2947. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  2948. systems since most code needs to behave the same on both}
  2949. if target_info.abi = abi_eabihf then
  2950. def_system_macro('FPC_ABI_EABI');
  2951. { Write logo }
  2952. if option.ParaLogo then
  2953. option.writelogo;
  2954. { Check file to compile }
  2955. if param_file='' then
  2956. begin
  2957. Message(option_no_source_found);
  2958. StopOptions(1);
  2959. end;
  2960. {$ifndef Unix}
  2961. param_file:=FixFileName(param_file);
  2962. {$endif not unix}
  2963. inputfilepath:=ExtractFilePath(param_file);
  2964. inputfilename:=ExtractFileName(param_file);
  2965. if ExtractFileExt(inputfilename)='' then
  2966. begin
  2967. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2968. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2969. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2970. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2971. else if ((m_mac in current_settings.modeswitches) or
  2972. (tf_p_ext_support in target_info.flags))
  2973. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2974. inputfilename:=ChangeFileExt(inputfilename,pext);
  2975. end;
  2976. { Check output dir }
  2977. if (OutputExeDir<>'') and
  2978. not PathExists(OutputExeDir,false) then
  2979. begin
  2980. Message1(general_e_path_does_not_exist,OutputExeDir);
  2981. StopOptions(1);
  2982. end;
  2983. { Add paths specified with parameters to the searchpaths }
  2984. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2985. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2986. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2987. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2988. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2989. { add unit environment and exepath to the unit search path }
  2990. if inputfilepath<>'' then
  2991. Unitsearchpath.AddPath(inputfilepath,true);
  2992. if not disable_configfile then
  2993. begin
  2994. env:=GetEnvironmentVariable(target_info.unit_env);
  2995. if env<>'' then
  2996. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2997. end;
  2998. {$ifdef Unix}
  2999. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3000. if fpcdir='' then
  3001. begin
  3002. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3003. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3004. else
  3005. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3006. end;
  3007. {$else unix}
  3008. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3009. if fpcdir='' then
  3010. begin
  3011. fpcdir:=ExePath+'../';
  3012. if not(PathExists(fpcdir+'units',true)) and
  3013. not(PathExists(fpcdir+'rtl',true)) then
  3014. fpcdir:=fpcdir+'../';
  3015. end;
  3016. {$endif unix}
  3017. { first try development RTL, else use the default installation path }
  3018. if not disable_configfile then
  3019. begin
  3020. if PathExists(FpcDir+'rtl',true) then
  3021. if tf_use_8_3 in Source_Info.Flags then
  3022. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3023. else
  3024. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3025. else
  3026. if tf_use_8_3 in Source_Info.Flags then
  3027. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3028. else
  3029. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3030. end;
  3031. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3032. Do not add it when linking on the target because then we can maybe already find
  3033. .o files that are not for the target }
  3034. if (ExePath<>cfileutl.GetCurrentDir) and
  3035. not(cs_link_on_target in init_settings.globalswitches) then
  3036. UnitSearchPath.AddPath(ExePath,false);
  3037. { Add unit dir to the object and library path }
  3038. objectsearchpath.AddList(unitsearchpath,false);
  3039. librarysearchpath.AddList(unitsearchpath,false);
  3040. { maybe override assembler }
  3041. if (paratargetasm<>as_none) then
  3042. begin
  3043. if not set_target_asm(paratargetasm) then
  3044. begin
  3045. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  3046. set_target_asm(target_info.assemextern);
  3047. Message1(option_asm_forced,target_asm.idtxt);
  3048. end;
  3049. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  3050. (paratargetdbg<>dbg_none) then
  3051. begin
  3052. Message1(option_confict_asm_debug,
  3053. asminfos[paratargetasm]^.idtxt);
  3054. paratargetdbg:=dbg_none;
  3055. exclude(init_settings.moduleswitches,cs_debuginfo);
  3056. end;
  3057. end;
  3058. {TOptionheck a second time as we might have changed assembler just above }
  3059. option.checkoptionscompatibility;
  3060. { maybe override debug info format }
  3061. if (paratargetdbg<>dbg_none) then
  3062. if not set_target_dbg(paratargetdbg) then
  3063. Message(option_w_unsupported_debug_format);
  3064. { switch assembler if it's binary and we got -a on the cmdline }
  3065. if (cs_asm_leave in init_settings.globalswitches) and
  3066. (af_outputbinary in target_asm.flags) then
  3067. begin
  3068. Message(option_switch_bin_to_src_assembler);
  3069. set_target_asm(target_info.assemextern);
  3070. end;
  3071. { Force use of external linker if there is no
  3072. internal linker or the linking is skipped }
  3073. if not(cs_link_extern in init_settings.globalswitches) and
  3074. ((target_info.link=ld_none) or
  3075. (cs_link_nolink in init_settings.globalswitches)) then
  3076. include(init_settings.globalswitches,cs_link_extern);
  3077. { turn off stripping if compiling with debuginfo or profile }
  3078. if (
  3079. (cs_debuginfo in init_settings.moduleswitches) or
  3080. (cs_profile in init_settings.moduleswitches)
  3081. ) and
  3082. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3083. exclude(init_settings.globalswitches,cs_link_strip);
  3084. { set Mac OS X version default macros if not specified explicitly }
  3085. option.MaybeSetDefaultMacVersionMacro;
  3086. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3087. if fpu type not explicitly set }
  3088. if not(option.FPUSetExplicitly) and
  3089. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  3090. system_m68k_linux,system_arm_nds,system_arm_embedded])
  3091. {$ifdef arm}
  3092. or (target_info.abi=abi_eabi)
  3093. {$endif arm}
  3094. )
  3095. {$if defined(arm) or defined (m68k)}
  3096. or (init_settings.fputype=fpu_soft)
  3097. {$endif arm or m68k}
  3098. then
  3099. begin
  3100. {$ifdef cpufpemu}
  3101. include(init_settings.moduleswitches,cs_fp_emulation);
  3102. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3103. init_settings.fputype:=fpu_soft;
  3104. {$endif cpufpemu}
  3105. end;
  3106. {$ifdef arm}
  3107. if target_info.abi = abi_eabihf then
  3108. begin
  3109. if not(option.FPUSetExplicitly) then
  3110. begin
  3111. init_settings.fputype:=fpu_vfpv3_d16
  3112. end
  3113. else
  3114. begin
  3115. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16]) then
  3116. begin
  3117. Message(option_illegal_fpu_eabihf);
  3118. StopOptions(1);
  3119. end;
  3120. end;
  3121. end;
  3122. {$endif arm}
  3123. {$ifdef arm}
  3124. case target_info.system of
  3125. system_arm_darwin:
  3126. begin
  3127. { set default cpu type to ARMv6 for Darwin unless specified otherwise, and fpu
  3128. to VFPv2 }
  3129. if not option.CPUSetExplicitly then
  3130. init_settings.cputype:=cpu_armv6;
  3131. if not option.OptCPUSetExplicitly then
  3132. init_settings.optimizecputype:=cpu_armv6;
  3133. if not option.FPUSetExplicitly then
  3134. init_settings.fputype:=fpu_vfpv2;
  3135. end;
  3136. system_arm_android:
  3137. begin
  3138. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3139. if not option.CPUSetExplicitly then
  3140. init_settings.cputype:=cpu_armv5t;
  3141. if not option.OptCPUSetExplicitly then
  3142. init_settings.optimizecputype:=cpu_armv5t;
  3143. end;
  3144. end;
  3145. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3146. if (target_info.abi = abi_eabihf) then
  3147. begin
  3148. {$ifdef CPUARMV6}
  3149. { if the compiler is built for armv6, then
  3150. inherit this setting, e.g. Raspian is armhf but
  3151. only armv6, this makes rebuilds of the compiler
  3152. easier }
  3153. if not option.CPUSetExplicitly then
  3154. init_settings.cputype:=cpu_armv6;
  3155. if not option.OptCPUSetExplicitly then
  3156. init_settings.optimizecputype:=cpu_armv6;
  3157. {$else CPUARMV6}
  3158. if not option.CPUSetExplicitly then
  3159. init_settings.cputype:=cpu_armv7a;
  3160. if not option.OptCPUSetExplicitly then
  3161. init_settings.optimizecputype:=cpu_armv7a;
  3162. {$endif CPUARMV6}
  3163. end;
  3164. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3165. begin
  3166. def_system_macro('CPUTHUMB');
  3167. if not option.FPUSetExplicitly then
  3168. init_settings.fputype:=fpu_soft;
  3169. end;
  3170. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3171. def_system_macro('CPUTHUMB2');
  3172. {$endif arm}
  3173. {$ifdef jvm}
  3174. { set default CPU type to Dalvik when targeting Android }
  3175. if target_info.system=system_jvm_android32 then
  3176. begin
  3177. if not option.CPUSetExplicitly then
  3178. init_settings.cputype:=cpu_dalvik;
  3179. end;
  3180. {$endif jvm}
  3181. { now we can define cpu and fpu type }
  3182. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3183. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3184. {$if defined(arm) or defined(avr)}
  3185. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3186. begin
  3187. str(cpuflag,hs);
  3188. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3189. def_system_macro(hs)
  3190. else
  3191. undef_system_macro(hs);
  3192. end;
  3193. {$endif defined(arm) or defined(avr)}
  3194. if init_settings.fputype<>fpu_none then
  3195. begin
  3196. {$if defined(i386) or defined(i8086)}
  3197. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3198. {$endif}
  3199. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3200. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3201. {$if not defined(i386) and not defined(x86_64) and not defined(i8086)}
  3202. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3203. {$endif}
  3204. {$if defined(m68k)}
  3205. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3206. {$endif}
  3207. {$ifdef x86_64}
  3208. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3209. { normally, win64 doesn't support the legacy fpu }
  3210. if target_info.system=system_x86_64_win64 then
  3211. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3212. else
  3213. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3214. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3215. {$endif}
  3216. end;
  3217. { Enable now for testing }
  3218. {$ifndef DISABLE_TLS_DIRECTORY}
  3219. if target_info.system in systems_windows then
  3220. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3221. {$endif not DISABLE_TLS_DIRECTORY}
  3222. {$ifndef DISABLE_WIN64_SEH}
  3223. if target_info.system=system_x86_64_win64 then
  3224. def_system_macro('FPC_USE_WIN64_SEH');
  3225. {$endif DISABLE_WIN64_SEH}
  3226. {$ifdef ARM}
  3227. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3228. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3229. not(cs_fp_emulation in init_settings.moduleswitches) then
  3230. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3231. {$endif ARM}
  3232. { inline bsf/bsr implementation }
  3233. {$if defined(x86) or defined(x86_64)}
  3234. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3235. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3236. {$endif}
  3237. {$if defined(arm)}
  3238. { it is determined during system unit compilation if clz is used for bsf or not,
  3239. this is not perfect but the current implementation bsf/bsr does not allow another
  3240. solution }
  3241. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3242. ((init_settings.instructionset=is_arm) or
  3243. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3244. begin
  3245. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3246. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3247. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3248. end;
  3249. {$endif}
  3250. {$if defined(i8086)}
  3251. case init_settings.x86memorymodel of
  3252. mm_tiny: def_system_macro('FPC_MM_TINY');
  3253. mm_small: def_system_macro('FPC_MM_SMALL');
  3254. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3255. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3256. mm_large: def_system_macro('FPC_MM_LARGE');
  3257. mm_huge: def_system_macro('FPC_MM_HUGE');
  3258. end;
  3259. {$endif}
  3260. { Section smartlinking conflicts with import sections on Windows }
  3261. if GenerateImportSection and
  3262. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3263. exclude(target_info.flags,tf_smartlink_sections);
  3264. if not LinkTypeSetExplicitly then
  3265. set_default_link_type;
  3266. { Default alignment settings,
  3267. 1. load the defaults for the target
  3268. 2. override with generic optimizer setting (little size)
  3269. 3. override with the user specified -Oa }
  3270. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3271. if (cs_opt_size in current_settings.optimizerswitches) then
  3272. begin
  3273. init_settings.alignment.procalign:=1;
  3274. init_settings.alignment.jumpalign:=1;
  3275. init_settings.alignment.loopalign:=1;
  3276. end;
  3277. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3278. set_system_macro('FPC_VERSION',version_nr);
  3279. set_system_macro('FPC_RELEASE',release_nr);
  3280. set_system_macro('FPC_PATCH',patch_nr);
  3281. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3282. if not(target_info.system in systems_windows) then
  3283. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3284. for i:=low(tfeature) to high(tfeature) do
  3285. if i in features then
  3286. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3287. option.free;
  3288. Option:=nil;
  3289. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  3290. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal];
  3291. if (tf_safecall_clearstack in target_info.flags) then
  3292. begin
  3293. include (cdecl_pocalls, pocall_safecall);
  3294. include (clearstack_pocalls, pocall_safecall)
  3295. end;
  3296. end;
  3297. initialization
  3298. coption:=toption;
  3299. finalization
  3300. if assigned(option) then
  3301. option.free;
  3302. end.