options.pas 123 KB

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