options.pas 166 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891
  1. {
  2. Copyright (c) 1998-2008 by Florian Klaempfl and Peter Vreman
  3. Reads command line options and config files
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit options;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cfileutl,cclasses,
  22. globtype,globals,verbose,systems,cpuinfo,comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. FPCHelpLines,
  29. LogoWritten,
  30. ABISetExplicitly,
  31. FPUSetExplicitly,
  32. CPUSetExplicitly,
  33. OptCPUSetExplicitly: boolean;
  34. FileLevel : longint;
  35. QuickInfo : string;
  36. FPCBinaryPath: string;
  37. ParaIncludeCfgPath,
  38. ParaIncludePath,
  39. ParaUnitPath,
  40. ParaObjectPath,
  41. ParaLibraryPath,
  42. ParaFrameworkPath,
  43. parapackagepath : TSearchPathList;
  44. paranamespaces : TCmdStrList;
  45. ParaAlignment : TAlignmentInfo;
  46. parapackages : tfphashobjectlist;
  47. paratarget : tsystem;
  48. paratargetasm : tasm;
  49. paratargetdbg : tdbg;
  50. LinkTypeSetExplicitly : boolean;
  51. LinkerSetExplicitly : boolean;
  52. Constructor Create;
  53. Destructor Destroy;override;
  54. procedure WriteLogo;
  55. procedure WriteInfo (More: string);
  56. procedure WriteHelpPages;
  57. procedure WriteQuickInfo;
  58. procedure IllegalPara(const opt:TCmdStr);
  59. procedure UnsupportedPara(const opt:TCmdStr);
  60. procedure IgnoredPara(const opt:TCmdStr);
  61. function Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: Boolean):boolean;
  62. procedure interpret_option(const opt :TCmdStr;ispara:boolean);
  63. procedure Interpret_envvar(const envname : TCmdStr);
  64. procedure Interpret_file(const filename : TPathStr);
  65. procedure Read_Parameters;
  66. procedure parsecmd(cmd:TCmdStr);
  67. procedure TargetOptions(def:boolean);
  68. procedure CheckOptionsCompatibility;
  69. procedure ForceStaticLinking;
  70. protected
  71. MacVersionSet: boolean;
  72. processorstr: TCmdStr;
  73. function ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  74. procedure MaybeSetDefaultMacVersionMacro;
  75. procedure VerifyTargetProcessor;
  76. end;
  77. TOptionClass=class of toption;
  78. var
  79. coption : TOptionClass;
  80. procedure read_arguments(cmd:TCmdStr);
  81. implementation
  82. uses
  83. widestr,
  84. {$if FPC_FULLVERSION<20700}ccharset{$else}charset{$endif},
  85. SysUtils,
  86. version,
  87. cutils,cmsgs,
  88. comphook,
  89. symtable,scanner,rabase,
  90. symconst,
  91. {$ifdef llvm}
  92. { override supported optimizer transformations at the compiler level }
  93. llvminfo,
  94. {$endif llvm}
  95. dirparse,
  96. pkgutil;
  97. const
  98. page_size = 24;
  99. page_width = 80;
  100. var
  101. option : toption;
  102. read_configfile, { read config file, set when a cfgfile is found }
  103. disable_configfile : boolean;
  104. fpcdir,
  105. ppccfg,
  106. param_file : string; { file to compile specified on the commandline }
  107. {****************************************************************************
  108. Options not supported on all platforms
  109. ****************************************************************************}
  110. const
  111. { gprof (requires implementation of g_profilecode in the code generator) }
  112. supported_targets_pg = [system_i386_linux,system_x86_64_linux,system_mipseb_linux,system_mipsel_linux,system_arm_linux]
  113. + [system_i386_win32]
  114. + [system_powerpc_darwin,system_x86_64_darwin]
  115. + [system_i386_GO32V2]
  116. + [system_i386_freebsd]
  117. + [system_i386_netbsd]
  118. + [system_i386_wdosx]
  119. + [system_riscv32_linux,system_riscv64_linux]
  120. + [system_aarch64_linux];
  121. suppported_targets_x_smallr = systems_linux + systems_solaris + systems_android
  122. + [system_i386_haiku,system_x86_64_haiku]
  123. + [system_i386_beos]
  124. + [system_m68k_amiga];
  125. {****************************************************************************
  126. Defines
  127. ****************************************************************************}
  128. procedure set_default_link_type;
  129. begin
  130. undef_system_macro('FPC_LINK_SMART');
  131. def_system_macro('FPC_LINK_STATIC');
  132. undef_system_macro('FPC_LINK_DYNAMIC');
  133. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  134. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  135. {$ifdef AIX}
  136. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_native];
  137. {$endif}
  138. end;
  139. {****************************************************************************
  140. Toption
  141. ****************************************************************************}
  142. procedure StopOptions(err:longint);
  143. begin
  144. if assigned(Option) then
  145. begin
  146. Option.free;
  147. Option:=nil;
  148. end;
  149. raise ECompilerAbortSilent.Create;
  150. end;
  151. function is_identifier(const s: TCmdStr): boolean;
  152. var
  153. i: longint;
  154. begin
  155. result:=false;
  156. if (s='') or not (s[1] in ['A'..'Z','a'..'z','_']) then
  157. exit;
  158. for i:=2 to length(s) do
  159. if not (s[I] in ['A'..'Z','a'..'z','0'..'9','_']) then
  160. exit;
  161. result:=true;
  162. end;
  163. procedure Toption.WriteLogo;
  164. var
  165. msg : TMsgStr;
  166. p : pchar;
  167. begin
  168. if not LogoWritten then
  169. begin
  170. msg:=MessageStr(option_logo);
  171. p:=pchar(msg);
  172. while assigned(p) do
  173. Comment(V_Normal,GetMsgLine(p));
  174. LogoWritten:= true;
  175. end;
  176. end;
  177. procedure Toption.WriteInfo (More: string);
  178. var
  179. msg_str: TMsgStr;
  180. p : pchar;
  181. hs,hs1,hs3,s : TCmdStr;
  182. J: longint;
  183. xmloutput: Text;
  184. const
  185. NewLineStr = '$\n';
  186. OSTargetsPlaceholder = '$OSTARGETS';
  187. CPUListPlaceholder = '$INSTRUCTIONSETS';
  188. FPUListPlaceholder = '$FPUINSTRUCTIONSETS';
  189. ABIListPlaceholder = '$ABITARGETS';
  190. OptListPlaceholder = '$OPTIMIZATIONS';
  191. WPOListPlaceholder = '$WPOPTIMIZATIONS';
  192. AsmModeListPlaceholder = '$ASMMODES';
  193. ControllerListPlaceholder = '$CONTROLLERTYPES';
  194. FeatureListPlaceholder = '$FEATURELIST';
  195. ModeSwitchListPlaceholder = '$MODESWITCHES';
  196. CodeGenerationBackendPlaceholder = '$CODEGENERATIONBACKEND';
  197. procedure SplitLine (var OrigString: TCmdStr; const Placeholder: TCmdStr;
  198. out RemainderString: TCmdStr);
  199. var
  200. I: longint;
  201. HS2: TCmdStr;
  202. begin
  203. RemainderString := '';
  204. if OrigString = '' then
  205. Exit;
  206. repeat
  207. I := Pos (NewLineStr, OrigString);
  208. if I > 0 then
  209. begin
  210. HS2 := Copy (OrigString, 1, Pred (I));
  211. { Stop if this line contains the placeholder for list replacement }
  212. if Pos (Placeholder, HS2) > 0 then
  213. begin
  214. RemainderString := Copy (OrigString, I + Length (NewLineStr),
  215. Length (OrigString) - I - Length (NewLineStr));
  216. { Special case - NewLineStr at the end of the line }
  217. if RemainderString = '' then
  218. RemainderString := NewLineStr;
  219. OrigString := HS2;
  220. Exit;
  221. end;
  222. Comment (V_Normal, HS2);
  223. Delete (OrigString, 1, Pred (I) + Length (NewLineStr));
  224. end;
  225. until I = 0;
  226. if (OrigString <> '') and (Pos (Placeholder, OrigString) = 0) then
  227. Comment (V_Normal, OrigString);
  228. end;
  229. procedure ListOSTargets (OrigString: TCmdStr);
  230. var
  231. target : tsystem;
  232. begin
  233. SplitLine (OrigString, OSTargetsPlaceholder, HS3);
  234. for target:=low(tsystem) to high(tsystem) do
  235. if assigned(targetinfos[target]) then
  236. begin
  237. hs1:=targetinfos[target]^.shortname;
  238. if OrigString = '' then
  239. Comment (V_Normal, hs1)
  240. else
  241. begin
  242. hs := OrigString;
  243. hs1:=hs1 + ': ' + targetinfos[target]^.name;
  244. if tf_under_development in targetinfos[target]^.flags then
  245. hs1:=hs1+' {*}';
  246. Replace(hs,OSTargetsPlaceholder,hs1);
  247. Comment(V_Normal,hs);
  248. end;
  249. end;
  250. end;
  251. procedure ListCPUInstructionSets (OrigString: TCmdStr);
  252. var
  253. cpu : tcputype;
  254. begin
  255. SplitLine (OrigString, CPUListPlaceholder, HS3);
  256. hs1:='';
  257. for cpu:=low(tcputype) to high(tcputype) do
  258. begin
  259. if (OrigString = '') then
  260. begin
  261. if CPUTypeStr [CPU] <> '' then
  262. Comment (V_Normal, CPUTypeStr [CPU]);
  263. end
  264. else
  265. begin
  266. if length(hs1+cputypestr[cpu])>70 then
  267. begin
  268. hs:=OrigString;
  269. HS1 := HS1 + ',';
  270. Replace(hs,CPUListPlaceholder,hs1);
  271. Comment(V_Normal,hs);
  272. hs1:=''
  273. end
  274. else if hs1<>'' then
  275. hs1:=hs1+',';
  276. if cputypestr[cpu]<>'' then
  277. hs1:=hs1+cputypestr[cpu];
  278. end;
  279. end;
  280. if (OrigString <> '') and (hs1 <> '') then
  281. begin
  282. hs:=OrigString;
  283. Replace(hs,CPUListPlaceholder,hs1);
  284. Comment(V_Normal,hs);
  285. hs1:=''
  286. end;
  287. end;
  288. procedure ListFPUInstructionSets (OrigString: TCmdStr);
  289. var
  290. fpu : tfputype;
  291. begin
  292. SplitLine (OrigString, FPUListPlaceholder, HS3);
  293. hs1:='';
  294. for fpu:=low(tfputype) to high(tfputype) do
  295. begin
  296. if (OrigString = '') then
  297. begin
  298. if FPUTypeStr [FPU] <> '' then
  299. Comment (V_Normal, FPUTypeStr [FPU]);
  300. end
  301. else
  302. begin
  303. if length(hs1+fputypestr[fpu])>70 then
  304. begin
  305. hs:=OrigString;
  306. HS1 := HS1 + ',';
  307. Replace(hs,FPUListPlaceholder,hs1);
  308. Comment(V_Normal,hs);
  309. hs1:=''
  310. end
  311. else if hs1<>'' then
  312. hs1:=hs1+',';
  313. if fputypestr[fpu]<>'' then
  314. hs1:=hs1+fputypestr[fpu];
  315. end;
  316. end;
  317. if (OrigString <> '') and (hs1 <> '') then
  318. begin
  319. hs:=OrigString;
  320. Replace(hs,FPUListPlaceholder,hs1);
  321. Comment(V_Normal,hs);
  322. hs1:=''
  323. end;
  324. end;
  325. procedure ListABITargets (OrigString: TCmdStr);
  326. var
  327. abi : tabi;
  328. begin
  329. SplitLine (OrigString, ABIListPlaceholder, HS3);
  330. for abi:=low(abi) to high(abi) do
  331. begin
  332. if not abiinfo[abi].supported then
  333. continue;
  334. hs1:=abiinfo[abi].name;
  335. if hs1<>'' then
  336. begin
  337. if OrigString = '' then
  338. Comment (V_Normal, HS1)
  339. else
  340. begin
  341. hs:=OrigString;
  342. Replace(hs,ABIListPlaceholder,hs1);
  343. Comment(V_Normal,hs);
  344. end;
  345. end;
  346. end;
  347. end;
  348. procedure ListOptimizations (OrigString: TCmdStr);
  349. var
  350. opt : toptimizerswitch;
  351. begin
  352. SplitLine (OrigString, OptListPlaceholder, HS3);
  353. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  354. begin
  355. if opt in supported_optimizerswitches then
  356. begin
  357. hs1:=OptimizerSwitchStr[opt];
  358. if hs1<>'' then
  359. begin
  360. if OrigString = '' then
  361. Comment (V_Normal, hs1)
  362. else
  363. begin
  364. hs:=OrigString;
  365. Replace(hs,OptListPlaceholder,hs1);
  366. Comment(V_Normal,hs);
  367. end;
  368. end;
  369. end;
  370. end;
  371. end;
  372. procedure ListOptimizationsXML;
  373. var
  374. opt: toptimizerswitch;
  375. begin
  376. WriteLn(xmloutput,'<optimizations>');
  377. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  378. if OptimizerSwitchStr[opt]<>'' then
  379. WriteLn(xmloutput,'<optimization name="',OptimizerSwitchStr[opt],'"/>');
  380. WriteLn(xmloutput,'</optimizations>');
  381. end;
  382. procedure ListWPOptimizations (OrigString: TCmdStr);
  383. var
  384. wpopt: twpoptimizerswitch;
  385. begin
  386. SplitLine (OrigString, WPOListPlaceholder, HS3);
  387. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  388. begin
  389. { currently all whole program optimizations are platform-independent
  390. if opt in supported_wpoptimizerswitches then
  391. }
  392. begin
  393. hs1:=WPOptimizerSwitchStr[wpopt];
  394. if hs1<>'' then
  395. begin
  396. if OrigString = '' then
  397. Comment (V_Normal, hs1)
  398. else
  399. begin
  400. hs:=OrigString;
  401. Replace(hs,WPOListPlaceholder,hs1);
  402. Comment(V_Normal,hs);
  403. end;
  404. end;
  405. end;
  406. end;
  407. end;
  408. procedure ListAsmModes (OrigString: TCmdStr);
  409. var
  410. asmmode : tasmmode;
  411. begin
  412. SplitLine (OrigString, AsmModeListPlaceholder, HS3);
  413. for asmmode:=low(tasmmode) to high(tasmmode) do
  414. if assigned(asmmodeinfos[asmmode]) then
  415. begin
  416. hs1:=asmmodeinfos[asmmode]^.idtxt;
  417. if hs1<>'' then
  418. begin
  419. if OrigString = '' then
  420. Comment (V_Normal, hs1)
  421. else
  422. begin
  423. hs:=OrigString;
  424. Replace(hs,AsmModeListPlaceholder,hs1);
  425. Comment(V_Normal,hs);
  426. end;
  427. end;
  428. end;
  429. end;
  430. procedure ListControllerTypes (OrigString: TCmdStr);
  431. var
  432. controllertype : tcontrollertype;
  433. begin
  434. {$PUSH}
  435. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  436. if (ControllerSupport) then
  437. begin
  438. SplitLine (OrigString, ControllerListPlaceholder, HS3);
  439. hs1:='';
  440. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  441. begin
  442. if (OrigString = '') then
  443. begin
  444. if Embedded_Controllers [ControllerType].ControllerTypeStr <> '' then
  445. Comment (V_Normal, Embedded_Controllers [ControllerType].ControllerTypeStr);
  446. end
  447. else
  448. begin
  449. if length(hs1+embedded_controllers[controllertype].ControllerTypeStr)
  450. >70 then
  451. begin
  452. hs:=OrigString;
  453. HS1 := HS1 + ',';
  454. Replace(hs,ControllerListPlaceholder,hs1);
  455. Comment(V_Normal,hs);
  456. hs1:=''
  457. end
  458. else if hs1<>'' then
  459. hs1:=hs1+',';
  460. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  461. hs1:=hs1+embedded_controllers[controllertype].ControllerTypeStr;
  462. end;
  463. end;
  464. if (OrigString <> '') and (hs1<>'') then
  465. begin
  466. hs:=OrigString;
  467. Replace(hs,ControllerListPlaceholder,hs1);
  468. Comment(V_Normal,hs);
  469. hs1:=''
  470. end;
  471. end;
  472. {$POP}
  473. end;
  474. procedure ListControllerTypesXML;
  475. var
  476. controllertype : tcontrollertype;
  477. begin
  478. {$PUSH}
  479. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  480. if (ControllerSupport) then
  481. begin
  482. WriteLn(xmloutput,'<controllertypes>');
  483. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  484. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  485. WriteLn(xmloutput,'<controllertype name="',embedded_controllers[controllertype].ControllerTypeStr,'"/>');
  486. WriteLn(xmloutput,'</controllertypes>');
  487. end;
  488. {$POP}
  489. end;
  490. procedure ListFeatures (OrigString: TCmdStr);
  491. var
  492. Feature: TFeature;
  493. begin
  494. SplitLine (OrigString, FeatureListPlaceholder, HS3);
  495. HS1 := '';
  496. for Feature := Low (TFeature) to High (TFeature) do
  497. begin
  498. if (OrigString = '') then
  499. begin
  500. if FeatureStr [Feature] <> '' then
  501. Comment (V_Normal, FeatureStr [Feature]);
  502. end
  503. else
  504. begin
  505. if Length (HS1 + FeatureStr [Feature]) > 70 then
  506. begin
  507. HS := OrigString;
  508. HS1 := HS1 + ',';
  509. Replace (HS, FeatureListPlaceholder, HS1);
  510. Comment (V_Normal, HS);
  511. HS1 := ''
  512. end
  513. else if HS1 <> '' then
  514. HS1 := HS1 + ',';
  515. if FeatureStr [Feature] <> '' then
  516. HS1 := HS1 + FeatureStr [Feature];
  517. end;
  518. end;
  519. if (OrigString <> '') and (HS1 <> '') then
  520. begin
  521. HS := OrigString;
  522. Replace (HS, FeatureListPlaceholder, HS1);
  523. Comment (V_Normal, HS);
  524. HS1 := ''
  525. end;
  526. end;
  527. procedure ListModeswitches (OrigString: TCmdStr);
  528. var
  529. Modeswitch: TModeswitch;
  530. begin
  531. SplitLine (OrigString, ModeswitchListPlaceholder, HS3);
  532. HS1 := '';
  533. for Modeswitch := Low (TModeswitch) to High (TModeswitch) do
  534. begin
  535. if (OrigString = '') then
  536. begin
  537. if ModeswitchStr [Modeswitch] <> '' then
  538. Comment (V_Normal, ModeswitchStr [Modeswitch]);
  539. end
  540. else
  541. begin
  542. if Length (HS1 + ModeswitchStr [Modeswitch]) > 60 then
  543. begin
  544. HS := OrigString;
  545. HS1 := HS1 + ',';
  546. Replace (HS, ModeswitchListPlaceholder, HS1);
  547. Comment (V_Normal, HS);
  548. HS1 := ''
  549. end
  550. else if HS1 <> '' then
  551. HS1 := HS1 + ',';
  552. if ModeswitchStr [Modeswitch] <> '' then
  553. HS1 := HS1 + ModeswitchStr [Modeswitch];
  554. end;
  555. end;
  556. if (OrigString <> '') and (HS1 <> '') then
  557. begin
  558. HS := OrigString;
  559. Replace (HS, ModeswitchListPlaceholder, HS1);
  560. Comment (V_Normal, HS);
  561. HS1 := ''
  562. end;
  563. end;
  564. procedure ListCodeGenerationBackend (OrigString: TCmdStr);
  565. begin
  566. SplitLine (OrigString, CodeGenerationBackendPlaceholder, HS3);
  567. hs1:=cgbackend2str[cgbackend];
  568. if OrigString = '' then
  569. Comment (V_Normal, hs1)
  570. else
  571. begin
  572. hs:=OrigString;
  573. Replace(hs,CodeGenerationBackendPlaceholder,hs1);
  574. Comment(V_Normal,hs);
  575. end;
  576. end;
  577. begin
  578. if More = '' then
  579. begin
  580. msg_str:=MessageStr(option_info);
  581. p:=pchar(msg_str);
  582. while assigned(p) do
  583. begin
  584. s:=GetMsgLine(p);
  585. { list permitted values for certain options }
  586. if pos(OSTargetsPlaceholder,s)>0 then
  587. ListOSTargets (S)
  588. else if pos(CPUListPlaceholder,s)>0 then
  589. ListCPUInstructionSets (S)
  590. else if pos(FPUListPlaceholder,s)>0 then
  591. ListFPUInstructionSets (S)
  592. else if pos(ABIListPlaceholder,s)>0 then
  593. ListABITargets (S)
  594. else if pos(OptListPlaceholder,s)>0 then
  595. ListOptimizations (S)
  596. else if pos(WPOListPlaceholder,s)>0 then
  597. ListWPOptimizations (S)
  598. else if Pos (ModeswitchListPlaceholder, S) > 0 then
  599. ListModeswitches (S)
  600. else if pos(AsmModeListPlaceholder,s)>0 then
  601. ListAsmModes (S)
  602. else if pos(ControllerListPlaceholder,s)>0 then
  603. ListControllerTypes (S)
  604. else if pos(FeatureListPlaceholder,s)>0 then
  605. ListFeatures (S)
  606. else if pos(CodeGenerationBackendPlaceholder,s)>0 then
  607. ListCodeGenerationBackend (S)
  608. else
  609. Comment(V_Normal,s);
  610. end;
  611. end
  612. else if Copy(More,1,1) = 'x' then
  613. begin
  614. Assign(xmloutput,Copy(More,2,length(More)-1));
  615. Rewrite(xmloutput);
  616. WriteLn(xmloutput,'<?xml version="1.0" encoding="utf-8"?>');
  617. WriteLn(xmloutput,'<fpcoutput>');
  618. WriteLn(xmloutput,'<info>');
  619. ListOptimizationsXML;
  620. ListControllerTypesXML;
  621. WriteLn(xmloutput,'</info>');
  622. WriteLn(xmloutput,'</fpcoutput>');
  623. Close(xmloutput);
  624. end
  625. else
  626. begin
  627. J := 1;
  628. while J <= Length (More) do
  629. begin
  630. if J > 1 then
  631. Comment(V_Normal,''); (* Put empty line between multiple sections *)
  632. case More [J] of
  633. 'a': ListABITargets ('');
  634. 'b': Comment(V_Normal, cgbackend2str[cgbackend]);
  635. 'c': ListCPUInstructionSets ('');
  636. 'f': ListFPUInstructionSets ('');
  637. 'i': ListAsmModes ('');
  638. 'm': ListModeswitches ('');
  639. 'o': ListOptimizations ('');
  640. 'r': ListFeatures ('');
  641. 't': ListOSTargets ('');
  642. 'u': ListControllerTypes ('');
  643. 'w': ListWPOptimizations ('');
  644. else
  645. IllegalPara ('-i' + More);
  646. end;
  647. Inc (J);
  648. end;
  649. end;
  650. StopOptions(0);
  651. end;
  652. procedure Toption.WriteHelpPages;
  653. function PadEnd(s:string;i:longint):string;
  654. begin
  655. if length(s) >= i then
  656. S := S + ' '
  657. else
  658. while (length(s)<i) do
  659. s:=s+' ';
  660. PadEnd:=s;
  661. end;
  662. var
  663. lastident,
  664. j,outline,
  665. ident,
  666. HelpLineHeight,
  667. lines : longint;
  668. show : boolean;
  669. opt : string[32];
  670. input,
  671. HelpLine,
  672. s : string;
  673. p : pchar;
  674. msg_str: TMsgStr;
  675. begin
  676. WriteLogo;
  677. Lines:=4;
  678. if FPCHelpLines then
  679. Message1(option_usage,FixFileName(FPCBinaryPath))
  680. else
  681. Message1(option_usage,FixFileName(system.paramstr(0)));
  682. lastident:=0;
  683. msg_str:=MessageStr(option_help_pages);
  684. p:=pchar(msg_str);
  685. while assigned(p) do
  686. begin
  687. { get a line and reset }
  688. s:=GetMsgLine(p);
  689. ident:=0;
  690. show:=false;
  691. { parse options }
  692. case s[1] of
  693. 'F': if FPCHelpLines then
  694. Show := true;
  695. {$ifdef UNITALIASES}
  696. 'a',
  697. {$endif}
  698. {$ifdef EXTDEBUG}
  699. 'e',
  700. {$endif EXTDEBUG}
  701. {$ifdef i386}
  702. '3',
  703. {$endif}
  704. {$ifdef x86_64}
  705. '4',
  706. {$endif}
  707. {$ifdef m68k}
  708. '6',
  709. {$endif}
  710. {$ifdef i8086}
  711. '8',
  712. {$endif}
  713. {$ifdef aarch64}
  714. 'a',
  715. {$endif}
  716. {$ifdef arm}
  717. 'A',
  718. {$endif}
  719. {$ifdef mipsel}
  720. 'm',
  721. {$endif}
  722. {$ifdef mipseb}
  723. 'M',
  724. {$endif}
  725. {$ifdef powerpc}
  726. 'P',
  727. {$endif}
  728. {$ifdef powerpc64}
  729. 'p',
  730. {$endif}
  731. {$ifdef sparc}
  732. 'S',
  733. {$endif}
  734. {$ifdef sparc64}
  735. 's',
  736. {$endif}
  737. {$ifdef riscv32}
  738. 'R',
  739. {$endif}
  740. {$ifdef riscv64}
  741. 'r',
  742. {$endif}
  743. {$ifdef avr}
  744. 'V',
  745. {$endif}
  746. {$ifdef jvm}
  747. 'J',
  748. {$endif}
  749. {$ifdef llvm}
  750. 'L',
  751. {$endif}
  752. {$ifdef xtensa}
  753. 'x',
  754. {$endif}
  755. {$ifdef z80}
  756. 'Z',
  757. {$endif}
  758. '*' : show:=true;
  759. end;
  760. if show then
  761. begin
  762. case s[2] of
  763. 'g',
  764. {$ifdef Unix}
  765. 'L',
  766. {$endif}
  767. {$ifdef os2}
  768. 'O',
  769. {$endif}
  770. '*' : show:=true;
  771. else
  772. show:=false;
  773. end;
  774. end;
  775. { now we may show the message or not }
  776. if show then
  777. begin
  778. case s[3] of
  779. '0' : begin
  780. ident:=0;
  781. outline:=0;
  782. end;
  783. '1' : begin
  784. ident:=2;
  785. outline:=7;
  786. end;
  787. '2' : begin
  788. ident:=6;
  789. outline:=11;
  790. end;
  791. '3' : begin
  792. ident:=9;
  793. outline:=11;
  794. end;
  795. else
  796. internalerror(2013112906);
  797. end;
  798. j:=pos('_',s);
  799. opt:=Copy(s,4,j-4);
  800. if opt='*' then
  801. opt:=''
  802. else
  803. if (opt=' ') or (opt[1]='@') then
  804. opt:=PadEnd(opt,outline)
  805. else
  806. opt:=PadEnd('-'+opt,outline);
  807. if (ident=0) and (lastident<>0) then
  808. begin
  809. Comment(V_Normal,'');
  810. inc(Lines);
  811. end;
  812. HelpLine := PadEnd('',ident)+opt+Copy(s,j+1,255);
  813. if HelpLine = '' then
  814. HelpLineHeight := 1
  815. else
  816. HelpLineHeight := Succ (CharLength (HelpLine) div Page_Width);
  817. { page full ? }
  818. if (lines + HelpLineHeight >= page_size - 1) then
  819. begin
  820. if not NoPressEnter then
  821. begin
  822. Message(option_help_press_enter);
  823. readln(input);
  824. if upper(input)='Q' then
  825. StopOptions(0);
  826. end;
  827. lines:=0;
  828. end;
  829. Comment(V_Normal,HelpLine);
  830. LastIdent:=Ident;
  831. Inc (Lines, HelpLineHeight);
  832. end;
  833. end;
  834. StopOptions(0);
  835. end;
  836. procedure Toption.IllegalPara(const opt:TCmdStr);
  837. begin
  838. Message1(option_illegal_para,opt);
  839. Message(option_help_pages_para);
  840. StopOptions(1);
  841. end;
  842. procedure toption.UnsupportedPara(const opt: TCmdStr);
  843. begin
  844. Message1(option_unsupported_target,opt);
  845. StopOptions(1);
  846. end;
  847. procedure toption.IgnoredPara(const opt: TCmdStr);
  848. begin
  849. Message1(option_ignored_target,opt);
  850. end;
  851. procedure toption.ForceStaticLinking;
  852. begin
  853. def_system_macro('FPC_LINK_STATIC');
  854. undef_system_macro('FPC_LINK_SMART');
  855. undef_system_macro('FPC_LINK_DYNAMIC');
  856. include(init_settings.globalswitches,cs_link_static);
  857. exclude(init_settings.globalswitches,cs_link_smart);
  858. exclude(init_settings.globalswitches,cs_link_shared);
  859. LinkTypeSetExplicitly:=true;
  860. end;
  861. function toption.ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  862. function subval(start,maxlen: longint; out stop: longint): string;
  863. var
  864. i: longint;
  865. begin
  866. result:='';
  867. i:=start;
  868. while (i<=length(value)) and
  869. (value[i] in ['0'..'9']) do
  870. inc(i);
  871. { sufficient amount of digits? }
  872. if (i=start) or
  873. (i-start>maxlen) then
  874. exit;
  875. result:=copy(value,start,i-start);
  876. stop:=i;
  877. end;
  878. var
  879. temp,
  880. compvarvalue: string[15];
  881. i: longint;
  882. osx_minor_two_digits: boolean;
  883. begin
  884. minstr:=value;
  885. emptystr:='';
  886. MacVersionSet:=false;
  887. { check whether the value is a valid version number }
  888. if value='' then
  889. begin
  890. undef_system_macro(compvarname);
  891. exit(true);
  892. end;
  893. { major version number }
  894. compvarvalue:=subval(1,2,i);
  895. { not enough digits -> invalid }
  896. if compvarvalue='' then
  897. exit(false);
  898. { already end of string -> invalid }
  899. if (i>=length(value)) or
  900. (value[i]<>'.') then
  901. exit(false);
  902. { minor version number }
  903. temp:=subval(i+1,2,i);
  904. if temp='' then
  905. exit(false);
  906. { on Mac OS X, the minor version number was originally limited to 1 digit;
  907. with 10.10 the format changed and two digits were also supported; on iOS,
  908. the minor version number always takes up two digits }
  909. osx_minor_two_digits:=false;
  910. if not ios then
  911. begin
  912. { if the minor version number is two digits on OS X (the case since
  913. OS X 10.10), we also have to add two digits for the patch level}
  914. if length(temp)=2 then
  915. osx_minor_two_digits:=true;
  916. end
  917. { the minor version number always takes up two digits on iOS }
  918. else if length(temp)=1 then
  919. temp:='0'+temp;
  920. compvarvalue:=compvarvalue+temp;
  921. { optional patch level }
  922. if i<=length(value) then
  923. begin
  924. if value[i]<>'.' then
  925. exit(false);
  926. temp:=subval(i+1,2,i);
  927. if temp='' then
  928. exit(false);
  929. { there's only room for a single digit patch level in the version macro
  930. for Mac OS X. gcc sets it to zero if there are more digits, but that
  931. seems worse than clamping to 9 (don't declare as invalid like with
  932. minor version number, because there is a precedent like 10.4.11).
  933. As of OS X 10.10 there are two digits for the patch level
  934. }
  935. if not ios and
  936. not osx_minor_two_digits then
  937. begin
  938. if length(temp)<>1 then
  939. temp:='9';
  940. end
  941. else
  942. begin
  943. { on iOS, the patch level is always two digits }
  944. if length(temp)=1 then
  945. temp:='0'+temp;
  946. end;
  947. compvarvalue:=compvarvalue+temp;
  948. { must be the end }
  949. if i<=length(value) then
  950. exit(false);
  951. end
  952. else if not ios and
  953. not osx_minor_two_digits then
  954. begin
  955. compvarvalue:=compvarvalue+'0';
  956. minstr:=minstr+'.0'
  957. end
  958. else
  959. begin
  960. compvarvalue:=compvarvalue+'00';
  961. { command line versions still only use one 0 though }
  962. minstr:=minstr+'.0'
  963. end;
  964. set_system_compvar(compvarname,compvarvalue);
  965. MacVersionSet:=true;
  966. result:=true;
  967. end;
  968. procedure TOption.MaybeSetDefaultMacVersionMacro;
  969. var
  970. envstr: ansistring;
  971. begin
  972. if not(target_info.system in systems_darwin) then
  973. exit;
  974. if MacVersionSet then
  975. exit;
  976. { check for deployment target set via environment variable }
  977. if not(target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) then
  978. begin
  979. envstr:=GetEnvironmentVariable('MACOSX_DEPLOYMENT_TARGET');
  980. if envstr<>'' then
  981. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',envstr,false) then
  982. Message1(option_invalid_macosx_deployment_target,envstr)
  983. else
  984. begin
  985. {$ifdef llvm}
  986. { We only support libunwind as part of libsystem, which happened in Mac OS X 10.6 }
  987. if CompareVersionStrings(MacOSXVersionMin,'10.6')<=0 then
  988. Message1(option_invalid_macosx_deployment_target,envstr);
  989. {$endif}
  990. exit;
  991. end;
  992. end
  993. else
  994. begin
  995. envstr:=GetEnvironmentVariable('IPHONEOS_DEPLOYMENT_TARGET');
  996. if envstr<>'' then
  997. if not ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',envstr,true) then
  998. Message1(option_invalid_iphoneos_deployment_target,envstr)
  999. else
  1000. exit;
  1001. end;
  1002. { nothing specified -> defaults }
  1003. case target_info.system of
  1004. system_powerpc_darwin:
  1005. begin
  1006. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1030');
  1007. MacOSXVersionMin:='10.3.0';
  1008. end;
  1009. system_powerpc64_darwin:
  1010. begin
  1011. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1040');
  1012. MacOSXVersionMin:='10.4.0';
  1013. end;
  1014. system_i386_darwin,
  1015. system_x86_64_darwin:
  1016. begin
  1017. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1080');
  1018. MacOSXVersionMin:='10.8.0';
  1019. end;
  1020. system_arm_ios,
  1021. system_i386_iphonesim:
  1022. begin
  1023. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','90000');
  1024. iPhoneOSVersionMin:='9.0.0';
  1025. end;
  1026. system_aarch64_ios,
  1027. system_x86_64_iphonesim:
  1028. begin
  1029. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','90000');
  1030. iPhoneOSVersionMin:='9.0.0';
  1031. end;
  1032. system_aarch64_darwin:
  1033. begin
  1034. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','110000');
  1035. MacOSXVersionMin:='11.0.0';
  1036. end
  1037. else
  1038. internalerror(2012031001);
  1039. end;
  1040. end;
  1041. procedure TOption.VerifyTargetProcessor;
  1042. begin
  1043. { no custom target processor specified -> ok }
  1044. if processorstr='' then
  1045. exit;
  1046. { custom target processor specified -> verify it's the one we support }
  1047. if upcase(processorstr)<>upcase(target_cpu_string) then
  1048. Message1(option_invalid_target_architecture,processorstr);
  1049. end;
  1050. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: boolean):boolean;
  1051. { checks if the character after pos in Opts is a + or a - and returns resp.
  1052. false or true. If it is another character (or none), it also returns false }
  1053. begin
  1054. UnsetBool := false;
  1055. if Length(Opts)>Pos then
  1056. begin
  1057. inc(Pos);
  1058. UnsetBool := Opts[Pos] = '-';
  1059. if Opts[Pos] in ['-','+']then
  1060. delete(Opts,Pos,1)
  1061. else if RequireBoolPara then
  1062. IllegalPara(FullPara);
  1063. end;
  1064. end;
  1065. procedure TOption.interpret_option(const opt:TCmdStr;ispara:boolean);
  1066. var
  1067. code : integer;
  1068. c : char;
  1069. more : TCmdStr;
  1070. major,minor : longint;
  1071. error : integer;
  1072. j,l : longint;
  1073. d,s : TCmdStr;
  1074. hs : TCmdStr;
  1075. unicodemapping : punicodemap;
  1076. {$ifdef llvm}
  1077. disable: boolean;
  1078. {$endif}
  1079. begin
  1080. if opt='' then
  1081. exit;
  1082. { only parse define,undef,target,verbosity,link etc options the firsttime
  1083. -Us must now also be first-passed to avoid rejection of -Sf options
  1084. earlier in command line }
  1085. if firstpass and
  1086. not(
  1087. (opt[1]='-') and
  1088. (
  1089. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l','U'])) or
  1090. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e')) or
  1091. ((length(opt)>3) and (opt[2]='C') and (opt[3] in ['a','f','p'])) or
  1092. ((length(opt)>3) and (opt[2]='W') and (opt[3] in ['m','p']))
  1093. )
  1094. ) then
  1095. exit;
  1096. Message1(option_handling_option,opt);
  1097. case opt[1] of
  1098. '-' :
  1099. begin
  1100. more:=Copy(opt,3,2147483647);
  1101. if firstpass then
  1102. Message1(option_interpreting_firstpass_option,opt)
  1103. else
  1104. Message1(option_interpreting_option,opt);
  1105. case opt[2] of
  1106. '?' :
  1107. begin
  1108. if (More <> '') and (More [1] = 'F') then
  1109. begin
  1110. FPCHelpLines := true;
  1111. Delete (More, 1, 1);
  1112. FPCBinaryPath := More;
  1113. end;
  1114. WriteHelpPages;
  1115. end;
  1116. 'a' :
  1117. begin
  1118. include(init_settings.globalswitches,cs_asm_leave);
  1119. j:=1;
  1120. while j<=length(more) do
  1121. begin
  1122. case more[j] of
  1123. '5' :
  1124. if (target_info.system in systems_all_windows+systems_nativent-[system_i8086_win16])
  1125. or (target_info.cpu in [cpu_mipseb, cpu_mipsel]) then
  1126. begin
  1127. if UnsetBool(More, j, opt, false) then
  1128. exclude(init_settings.globalswitches,cs_asm_pre_binutils_2_25)
  1129. else
  1130. include(init_settings.globalswitches,cs_asm_pre_binutils_2_25);
  1131. end
  1132. else
  1133. IllegalPara(opt);
  1134. 'l' :
  1135. include(init_settings.globalswitches,cs_asm_source);
  1136. 'r' :
  1137. include(init_settings.globalswitches,cs_asm_regalloc);
  1138. 't' :
  1139. include(init_settings.globalswitches,cs_asm_tempalloc);
  1140. 'n' :
  1141. include(init_settings.globalswitches,cs_asm_nodes);
  1142. { -ao option must be the last, everything behind it is passed directly to
  1143. external assembler, it is ignored if internal assembler is used. }
  1144. 'o' :
  1145. begin
  1146. asmextraopt:=copy(more,j+1,length(more)-j);
  1147. break;
  1148. end;
  1149. 'p' :
  1150. begin
  1151. exclude(init_settings.globalswitches,cs_asm_leave);
  1152. if UnsetBool(More, 0, opt, false) then
  1153. exclude(init_settings.globalswitches,cs_asm_pipe)
  1154. else
  1155. include(init_settings.globalswitches,cs_asm_pipe);
  1156. end;
  1157. '-' :
  1158. init_settings.globalswitches:=init_settings.globalswitches -
  1159. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  1160. cs_asm_nodes, cs_asm_pipe];
  1161. else
  1162. IllegalPara(opt);
  1163. end;
  1164. inc(j);
  1165. end;
  1166. end;
  1167. 'A' :
  1168. begin
  1169. paratargetasm:=find_asm_by_string(More);
  1170. if paratargetasm=as_none then
  1171. IllegalPara(opt);
  1172. end;
  1173. 'b' :
  1174. begin
  1175. // Message1(option_obsolete_switch,'-b');
  1176. if UnsetBool(More,0,opt,false) then
  1177. begin
  1178. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  1179. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  1180. end
  1181. else
  1182. begin
  1183. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  1184. end;
  1185. if More<>'' then
  1186. if (More='l') or (More='l+') then
  1187. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  1188. else if More='l-' then
  1189. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  1190. else
  1191. IllegalPara(opt);
  1192. end;
  1193. 'B' :
  1194. do_build:=not UnSetBool(more,0,opt,true);
  1195. 'C' :
  1196. begin
  1197. j:=1;
  1198. while j<=length(more) do
  1199. begin
  1200. case more[j] of
  1201. '3' :
  1202. If UnsetBool(More, j, opt, false) then
  1203. exclude(init_settings.localswitches,cs_ieee_errors)
  1204. Else
  1205. include(init_settings.localswitches,cs_ieee_errors);
  1206. 'a' :
  1207. begin
  1208. s:=upper(copy(more,j+1,length(more)-j));
  1209. if not(SetAbiType(s,target_info.abi)) then
  1210. IllegalPara(opt);
  1211. ABISetExplicitly:=true;
  1212. break;
  1213. end;
  1214. 'b' :
  1215. begin
  1216. if UnsetBool(More, j, opt, false) then
  1217. target_info.endian:=endian_little
  1218. else
  1219. target_info.endian:=endian_big;
  1220. end;
  1221. 'c' :
  1222. begin
  1223. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  1224. IllegalPara(opt);
  1225. break;
  1226. end;
  1227. {$ifdef cpufpemu}
  1228. 'e' :
  1229. begin
  1230. If UnsetBool(More, j, opt, false) then
  1231. exclude(init_settings.moduleswitches,cs_fp_emulation)
  1232. Else
  1233. include(init_settings.moduleswitches,cs_fp_emulation);
  1234. end;
  1235. {$endif cpufpemu}
  1236. 'E' :
  1237. If UnsetBool(More, j, opt, false) then
  1238. exclude(init_settings.localswitches,cs_check_fpu_exceptions)
  1239. Else
  1240. include(init_settings.localswitches,cs_check_fpu_exceptions);
  1241. 'f' :
  1242. begin
  1243. s:=upper(copy(more,j+1,length(more)-j));
  1244. if not(SetFpuType(s,init_settings.fputype)) then
  1245. IllegalPara(opt);
  1246. FPUSetExplicitly:=True;
  1247. break;
  1248. end;
  1249. 'F' :
  1250. begin
  1251. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  1252. IllegalPara(opt);
  1253. break;
  1254. end;
  1255. 'g' :
  1256. begin
  1257. if tf_no_pic_supported in target_info.flags then
  1258. begin
  1259. { consume a possible '-' coming after it }
  1260. UnsetBool(More, j, opt, false);
  1261. message(scan_w_pic_ignored);
  1262. end
  1263. else if UnsetBool(More, j, opt, false) then
  1264. exclude(init_settings.moduleswitches,cs_create_pic)
  1265. else
  1266. include(init_settings.moduleswitches,cs_create_pic);
  1267. end;
  1268. 'h' :
  1269. begin
  1270. l:=pos(',',copy(more,j+1,length(more)-j));
  1271. if l=0 then
  1272. l:=length(more)-j+1;
  1273. val(copy(more,j+1,l-1),heapsize,code);
  1274. if (code<>0)
  1275. {$ifdef AVR}
  1276. or (heapsize<32)
  1277. {$else AVR}
  1278. or (heapsize<1024)
  1279. {$endif AVR}
  1280. then
  1281. IllegalPara(opt)
  1282. else if l<=length(more)-j then
  1283. begin
  1284. val(copy(more,j+l+1,length(more)),maxheapsize,code);
  1285. if code<>0 then
  1286. IllegalPara(opt)
  1287. else if (maxheapsize<heapsize) then
  1288. begin
  1289. message(scan_w_heapmax_lessthan_heapmin);
  1290. maxheapsize:=heapsize;
  1291. end;
  1292. end;
  1293. break;
  1294. end;
  1295. 'i' :
  1296. If UnsetBool(More, j, opt, false) then
  1297. exclude(init_settings.localswitches,cs_check_io)
  1298. else
  1299. include(init_settings.localswitches,cs_check_io);
  1300. {$ifdef arm}
  1301. 'I' :
  1302. begin
  1303. if (upper(copy(more,j+1,length(more)-j))='THUMB') and
  1304. { does selected CPU really understand thumb? }
  1305. (init_settings.cputype in cpu_has_thumb) then
  1306. init_settings.instructionset:=is_thumb
  1307. else if upper(copy(more,j+1,length(more)-j))='ARM' then
  1308. init_settings.instructionset:=is_arm
  1309. else
  1310. IllegalPara(opt);
  1311. break;
  1312. end;
  1313. {$endif arm}
  1314. {$ifdef llvm}
  1315. 'l':
  1316. begin
  1317. l:=j+1;
  1318. while l<=length(More) do
  1319. begin
  1320. case More[l] of
  1321. 'f':
  1322. begin
  1323. More:=copy(More,l+1,length(More));
  1324. disable:=Unsetbool(More,length(More)-1,opt,false);
  1325. case More of
  1326. 'lto':
  1327. begin
  1328. if not disable then
  1329. begin
  1330. include(init_settings.moduleswitches,cs_lto);
  1331. LTOExt:='.bc';
  1332. end
  1333. else
  1334. exclude(init_settings.moduleswitches,cs_lto);
  1335. end;
  1336. 'ltonosystem':
  1337. begin
  1338. if not disable then
  1339. begin
  1340. include(init_settings.globalswitches,cs_lto_nosystem);
  1341. end
  1342. else
  1343. exclude(init_settings.globalswitches,cs_lto_nosystem);
  1344. end;
  1345. else
  1346. begin
  1347. IllegalPara(opt);
  1348. end;
  1349. end;
  1350. l:=length(more)+1;
  1351. end;
  1352. 'v':
  1353. begin
  1354. init_settings.llvmversion:=llvmversion2enum(copy(More,l+1,length(More)));
  1355. if init_settings.llvmversion=llvmver_invalid then
  1356. begin
  1357. IllegalPara(opt);
  1358. end;
  1359. l:=length(More)+1;
  1360. end
  1361. else
  1362. begin
  1363. IllegalPara(opt);
  1364. end;
  1365. end;
  1366. end;
  1367. j:=l;
  1368. end;
  1369. {$endif llvm}
  1370. 'n' :
  1371. If UnsetBool(More, j, opt, false) then
  1372. exclude(init_settings.globalswitches,cs_link_nolink)
  1373. Else
  1374. include(init_settings.globalswitches,cs_link_nolink);
  1375. 'N' :
  1376. If UnsetBool(More, j, opt, false) then
  1377. exclude(init_settings.localswitches,cs_check_low_addr_load)
  1378. Else
  1379. include(init_settings.localswitches,cs_check_low_addr_load);
  1380. 'o' :
  1381. If UnsetBool(More, j, opt, false) then
  1382. exclude(init_settings.localswitches,cs_check_overflow)
  1383. Else
  1384. include(init_settings.localswitches,cs_check_overflow);
  1385. 'O' :
  1386. If UnsetBool(More, j, opt, false) then
  1387. exclude(init_settings.localswitches,cs_check_ordinal_size)
  1388. Else
  1389. include(init_settings.localswitches,cs_check_ordinal_size);
  1390. 'p' :
  1391. begin
  1392. s:=upper(copy(more,j+1,length(more)-j));
  1393. if not(Setcputype(s,init_settings)) then
  1394. IllegalPara(opt);
  1395. CPUSetExplicitly:=true;
  1396. break;
  1397. end;
  1398. 'P':
  1399. begin
  1400. delete(more,1,1);
  1401. case upper(copy(more,1,pos('=',more)-1)) of
  1402. 'PACKSET':
  1403. begin
  1404. delete(more,1,pos('=',more));
  1405. case more of
  1406. '0','DEFAULT','NORMAL':
  1407. init_settings.setalloc:=0;
  1408. '1','2','4','8':
  1409. init_settings.setalloc:=StrToInt(more);
  1410. else
  1411. IllegalPara(opt);
  1412. end
  1413. end;
  1414. 'PACKENUM':
  1415. begin
  1416. delete(more,1,pos('=',more));
  1417. case more of
  1418. '0','DEFAULT','NORMAL':
  1419. init_settings.packenum:=4;
  1420. '1','2','4':
  1421. init_settings.packenum:=StrToInt(more);
  1422. else
  1423. IllegalPara(opt);
  1424. end;
  1425. end;
  1426. 'PACKRECORD':
  1427. begin
  1428. delete(more,1,pos('=',more));
  1429. case more of
  1430. '0','DEFAULT','NORMAL':
  1431. init_settings.packrecords:=default_settings.packrecords;
  1432. '1','2','4','8','16','32':
  1433. init_settings.packrecords:=StrToInt(more);
  1434. else
  1435. IllegalPara(opt);
  1436. end;
  1437. end
  1438. else
  1439. IllegalPara(opt);
  1440. end;
  1441. end;
  1442. 'r' :
  1443. If UnsetBool(More, j, opt, false) then
  1444. exclude(init_settings.localswitches,cs_check_range)
  1445. Else
  1446. include(init_settings.localswitches,cs_check_range);
  1447. 'R' :
  1448. If UnsetBool(More, j, opt, false) then
  1449. begin
  1450. exclude(init_settings.localswitches,cs_check_range);
  1451. exclude(init_settings.localswitches,cs_check_object);
  1452. end
  1453. Else
  1454. begin
  1455. include(init_settings.localswitches,cs_check_range);
  1456. include(init_settings.localswitches,cs_check_object);
  1457. end;
  1458. 's' :
  1459. begin
  1460. val(copy(more,j+1,length(more)-j),stacksize,code);
  1461. if (code<>0)
  1462. {$ifdef cpu16bitaddr}
  1463. or (stacksize>=65521)
  1464. {$else cpu16bitaddr}
  1465. or (stacksize>=67107840)
  1466. {$endif cpu16bitaddr}
  1467. or (stacksize<1024) then
  1468. IllegalPara(opt);
  1469. break;
  1470. end;
  1471. 't' :
  1472. If UnsetBool(More, j, opt, false) then
  1473. exclude(init_settings.localswitches,cs_check_stack)
  1474. Else
  1475. include(init_settings.localswitches,cs_check_stack);
  1476. 'D' :
  1477. If UnsetBool(More, j, opt, false) then
  1478. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1479. Else
  1480. include(init_settings.moduleswitches,cs_create_dynamic);
  1481. 'X' :
  1482. If UnsetBool(More, j, opt, false) then
  1483. exclude(init_settings.moduleswitches,cs_create_smart)
  1484. Else
  1485. include(init_settings.moduleswitches,cs_create_smart);
  1486. 'T' :
  1487. begin
  1488. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1489. IllegalPara(opt);
  1490. break;
  1491. end;
  1492. 'v' :
  1493. If target_info.system in systems_jvm then
  1494. If UnsetBool(More, j, opt, false) then
  1495. exclude(init_settings.localswitches,cs_check_var_copyout)
  1496. Else
  1497. include(init_settings.localswitches,cs_check_var_copyout)
  1498. else
  1499. IllegalPara(opt);
  1500. 'V':
  1501. begin
  1502. s:=upper(copy(more,j+1,length(more)-j));
  1503. if s='GLOBAL-DYNAMIC' then
  1504. init_settings.tlsmodel:=tlsm_global_dynamic
  1505. else if s='LOCAL-EXEC' then
  1506. init_settings.tlsmodel:=tlsm_local_exec
  1507. else
  1508. IllegalPara(opt);
  1509. break;
  1510. end;
  1511. else
  1512. IllegalPara(opt);
  1513. end;
  1514. inc(j);
  1515. end;
  1516. end;
  1517. 'd' :
  1518. begin
  1519. l:=Pos(':=',more);
  1520. if l>0 then
  1521. hs:=copy(more,1,l-1)
  1522. else
  1523. hs:=more;
  1524. if (not is_identifier(hs)) then
  1525. begin
  1526. if hs='' then
  1527. Message1(option_missing_arg,'-d')
  1528. else
  1529. Message1(option_malformed_para,opt);
  1530. StopOptions(1);
  1531. end;
  1532. if l>0 then
  1533. begin
  1534. if cs_support_macro in init_settings.moduleswitches then
  1535. set_system_macro(hs,Copy(more,l+2,255))
  1536. else
  1537. set_system_compvar(hs,Copy(more,l+2,255));
  1538. end
  1539. else
  1540. def_system_macro(hs);
  1541. end;
  1542. 'D' :
  1543. begin
  1544. include(init_settings.globalswitches,cs_link_deffile);
  1545. j:=1;
  1546. while j<=length(more) do
  1547. begin
  1548. case more[j] of
  1549. 'd' :
  1550. begin
  1551. description:=Copy(more,j+1,255);
  1552. break;
  1553. end;
  1554. 'D' :
  1555. begin
  1556. datestr:=Copy(more,j+1,255);
  1557. break;
  1558. end;
  1559. 'T' :
  1560. begin
  1561. timestr:=Copy(more,j+1,255);
  1562. break;
  1563. end;
  1564. 'v' :
  1565. begin
  1566. dllversion:=Copy(more,j+1,255);
  1567. l:=pos('.',dllversion);
  1568. dllminor:=0;
  1569. error:=0;
  1570. if l>0 then
  1571. begin
  1572. val(copy(dllversion,l+1,255),minor,error);
  1573. if (error=0) and
  1574. (minor>=0) and (minor<=$ffff) then
  1575. dllminor:=minor
  1576. else
  1577. if error=0 then
  1578. error:=1;
  1579. end;
  1580. if l=0 then
  1581. l:=256;
  1582. dllmajor:=1;
  1583. major:=0;
  1584. if error=0 then
  1585. val(copy(dllversion,1,l-1),major,error);
  1586. if (error=0) and (major>=0) and (major<=$ffff) then
  1587. dllmajor:=major
  1588. else
  1589. if error=0 then
  1590. error:=1;
  1591. if error<>0 then
  1592. Message1(scan_w_wrong_version_ignored,dllversion);
  1593. break;
  1594. end;
  1595. 'w' :
  1596. usewindowapi:=true;
  1597. '-' :
  1598. begin
  1599. exclude(init_settings.globalswitches,cs_link_deffile);
  1600. usewindowapi:=false;
  1601. end;
  1602. else
  1603. IllegalPara(opt);
  1604. end;
  1605. inc(j);
  1606. end;
  1607. end;
  1608. 'e' :
  1609. exepath:=FixPath(More,true);
  1610. 'E' :
  1611. begin
  1612. if UnsetBool(More, 0, opt, true) then
  1613. exclude(init_settings.globalswitches,cs_link_nolink)
  1614. else
  1615. include(init_settings.globalswitches,cs_link_nolink);
  1616. end;
  1617. 'f' :
  1618. begin
  1619. if more='PIC' then
  1620. begin
  1621. if tf_no_pic_supported in target_info.flags then
  1622. message(scan_w_pic_ignored)
  1623. else
  1624. include(init_settings.moduleswitches,cs_create_pic)
  1625. end
  1626. else
  1627. IllegalPara(opt);
  1628. end;
  1629. 'F' :
  1630. begin
  1631. if more='' then
  1632. IllegalPara(opt);
  1633. c:=more[1];
  1634. Delete(more,1,1);
  1635. DefaultReplacements(More);
  1636. case c of
  1637. 'a' :
  1638. autoloadunits:=more;
  1639. 'c' :
  1640. begin
  1641. { if we first specify that the system code page should be
  1642. used and then explicitly specify a code page, unset the
  1643. flag that we're using the system code page again }
  1644. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1645. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1646. init_settings.sourcecodepage:=CP_UTF8
  1647. else if not(cpavailable(more)) then
  1648. Message1(option_code_page_not_available,more)
  1649. else
  1650. init_settings.sourcecodepage:=codepagebyname(more);
  1651. include(init_settings.moduleswitches,cs_explicit_codepage);
  1652. end;
  1653. 'C' :
  1654. RCCompiler:=More;
  1655. 'd' :
  1656. if UnsetBool(more, 0, opt, true) then
  1657. init_settings.disabledircache:=false
  1658. else
  1659. init_settings.disabledircache:=true;
  1660. 'D' :
  1661. utilsdirectory:=FixPath(More,true);
  1662. 'e' :
  1663. SetRedirectFile(More);
  1664. 'E' :
  1665. OutputExeDir:=FixPath(More,true);
  1666. 'f' :
  1667. if (target_info.system in systems_darwin) then
  1668. if ispara then
  1669. ParaFrameworkPath.AddPath(More,false)
  1670. else
  1671. frameworksearchpath.AddPath(More,true)
  1672. {$ifdef XTENSA}
  1673. else if (target_info.system=system_xtensa_freertos) then
  1674. idfpath:=FixPath(More,true)
  1675. {$endif XTENSA}
  1676. else
  1677. IllegalPara(opt);
  1678. 'F' :
  1679. RCForceFPCRes:=true;
  1680. 'i' :
  1681. begin
  1682. if ispara then
  1683. ParaIncludePath.AddPath(More,false)
  1684. else
  1685. includesearchpath.AddPath(More,true);
  1686. end;
  1687. 'm' :
  1688. begin
  1689. s:=ExtractFileDir(more);
  1690. if TryStrToInt(ExtractFileName(more),j) then
  1691. begin
  1692. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1693. if assigned(unicodemapping) then
  1694. registermapping(unicodemapping)
  1695. else
  1696. IllegalPara(opt);
  1697. end
  1698. else
  1699. IllegalPara(opt);
  1700. end;
  1701. 'M' :
  1702. unicodepath:=FixPath(More,true);
  1703. 'g' :
  1704. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1705. 'l' :
  1706. begin
  1707. if ispara then
  1708. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  1709. else
  1710. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  1711. end;
  1712. 'L' :
  1713. begin
  1714. if More<>'' then
  1715. ParaDynamicLinker:=More
  1716. else
  1717. IllegalPara(opt);
  1718. end;
  1719. 'N' :
  1720. begin
  1721. if more<>'' then
  1722. paranamespaces.insert(more)
  1723. else
  1724. illegalpara(opt);
  1725. end;
  1726. 'o' :
  1727. begin
  1728. if ispara then
  1729. ParaObjectPath.AddPath(More,false)
  1730. else
  1731. ObjectSearchPath.AddPath(More,true);
  1732. end;
  1733. 'P' :
  1734. begin
  1735. if ispara then
  1736. parapackages.add(more,nil)
  1737. else
  1738. add_package(more,true,true);
  1739. end;
  1740. 'p' :
  1741. begin
  1742. if ispara then
  1743. parapackagepath.AddPath(More,false)
  1744. else
  1745. packagesearchpath.AddPath(More,true);
  1746. end;
  1747. 'r' :
  1748. Msgfilename:=More;
  1749. 'R' :
  1750. ResCompiler:=More;
  1751. 'u' :
  1752. begin
  1753. if ispara then
  1754. ParaUnitPath.AddPath(More,false)
  1755. else
  1756. unitsearchpath.AddPath(More,true);
  1757. end;
  1758. 'U' :
  1759. OutputUnitDir:=FixPath(More,true);
  1760. 'W',
  1761. 'w':
  1762. begin
  1763. if More<>'' then
  1764. begin
  1765. DefaultReplacements(More);
  1766. D:=ExtractFilePath(More);
  1767. if (D<>'') then
  1768. D:=FixPath(D,True);
  1769. D:=D+ExtractFileName(More);
  1770. if (c='W') then
  1771. WpoFeedbackOutput:=D
  1772. else
  1773. WpoFeedbackInput:=D;
  1774. end
  1775. else
  1776. IllegalPara(opt);
  1777. end;
  1778. else
  1779. IllegalPara(opt);
  1780. end;
  1781. end;
  1782. 'g' :
  1783. begin
  1784. if UnsetBool(More, 0, opt, false) then
  1785. begin
  1786. exclude(init_settings.moduleswitches,cs_debuginfo);
  1787. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1788. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1789. exclude(init_settings.localswitches,cs_checkpointer);
  1790. paratargetdbg:=dbg_none;
  1791. localvartrashing := -1;
  1792. end
  1793. else
  1794. begin
  1795. include(init_settings.moduleswitches,cs_debuginfo);
  1796. if paratargetdbg=dbg_none then
  1797. paratargetdbg:=target_info.dbg;
  1798. end;
  1799. if not RelocSectionSetExplicitly then
  1800. RelocSection:=false;
  1801. j:=1;
  1802. while j<=length(more) do
  1803. begin
  1804. case more[j] of
  1805. 'c' :
  1806. begin
  1807. if UnsetBool(More, j, opt, false) then
  1808. exclude(init_settings.localswitches,cs_checkpointer)
  1809. else if (target_info.system in systems_support_checkpointer) then
  1810. begin
  1811. if do_release then
  1812. Message(option_gc_incompatible_with_release_flag)
  1813. else
  1814. include(init_settings.localswitches,cs_checkpointer);
  1815. end
  1816. else
  1817. UnsupportedPara('-gc');
  1818. end;
  1819. 'h' :
  1820. begin
  1821. if UnsetBool(More, j, opt, false) then
  1822. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1823. else
  1824. begin
  1825. if cs_gdb_valgrind in init_settings.globalswitches then
  1826. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1827. include(init_settings.globalswitches,cs_use_heaptrc);
  1828. end;
  1829. end;
  1830. 'l' :
  1831. begin
  1832. if UnsetBool(More, j, opt, false) then
  1833. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1834. else
  1835. include(init_settings.globalswitches,cs_use_lineinfo);
  1836. end;
  1837. 'm' :
  1838. begin
  1839. paratargetdbg:=dbg_codeview;
  1840. end;
  1841. 'o' :
  1842. begin
  1843. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1844. IllegalPara(opt);
  1845. break;
  1846. end;
  1847. 'p' :
  1848. begin
  1849. if UnsetBool(More, j, opt, false) then
  1850. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1851. else
  1852. include(init_settings.globalswitches,cs_stabs_preservecase);
  1853. end;
  1854. 's' :
  1855. begin
  1856. paratargetdbg:=dbg_stabs;
  1857. end;
  1858. 't' :
  1859. begin
  1860. if UnsetBool(More, j, opt, false) then
  1861. localvartrashing := -1
  1862. else
  1863. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1864. end;
  1865. 'v' :
  1866. begin
  1867. if UnsetBool(More, j, opt, false) then
  1868. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1869. else
  1870. begin
  1871. if cs_use_heaptrc in init_settings.globalswitches then
  1872. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1873. include(init_settings.globalswitches,cs_gdb_valgrind);
  1874. end;
  1875. end;
  1876. 'w' :
  1877. begin
  1878. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1879. begin
  1880. case more[j+1] of
  1881. '2': paratargetdbg:=dbg_dwarf2;
  1882. '3': paratargetdbg:=dbg_dwarf3;
  1883. '4': paratargetdbg:=dbg_dwarf4;
  1884. end;
  1885. inc(j);
  1886. end
  1887. else
  1888. paratargetdbg:=dbg_dwarf2;
  1889. end;
  1890. else
  1891. IllegalPara(opt);
  1892. end;
  1893. inc(j);
  1894. end;
  1895. end;
  1896. 'h' :
  1897. begin
  1898. NoPressEnter:=true;
  1899. if (More <> '') and (More [1] = 'F') then
  1900. begin
  1901. FPCHelpLines := true;
  1902. Delete (More, 1, 1);
  1903. FPCBinaryPath := More;
  1904. end;
  1905. WriteHelpPages;
  1906. end;
  1907. 'i' :
  1908. begin
  1909. if (More='') or
  1910. (More [1] in ['a', 'b', 'c', 'f', 'i', 'm', 'o', 'r', 't', 'u', 'w', 'x']) then
  1911. WriteInfo (More)
  1912. else
  1913. QuickInfo:=QuickInfo+More;
  1914. end;
  1915. 'I' :
  1916. begin
  1917. if ispara then
  1918. ParaIncludePath.AddPath(More,false)
  1919. else
  1920. includesearchpath.AddPath(More,false);
  1921. end;
  1922. 'k' :
  1923. begin
  1924. if more<>'' then
  1925. ParaLinkOptions:=ParaLinkOptions+' '+More
  1926. else
  1927. IllegalPara(opt);
  1928. end;
  1929. 'l' :
  1930. ParaLogo:=not UnSetBool(more,0,opt,true);
  1931. {$ifdef PREPROCWRITE}
  1932. 'm' :
  1933. parapreprocess:=not UnSetBool(more,0,opt,true);
  1934. {$endif PREPROCWRITE}
  1935. 'M' :
  1936. begin
  1937. more:=Upper(more);
  1938. if not SetCompileMode(more, true) then
  1939. if not SetCompileModeSwitch(more, true) then
  1940. IllegalPara(opt);
  1941. end;
  1942. 'n' :
  1943. begin
  1944. if More='' then
  1945. disable_configfile:=true
  1946. else
  1947. IllegalPara(opt);
  1948. end;
  1949. 'o' :
  1950. begin
  1951. if More<>'' then
  1952. begin
  1953. DefaultReplacements(More);
  1954. D:=ExtractFilePath(More);
  1955. if (D<>'') then
  1956. OutputExeDir:=FixPath(D,True);
  1957. OutputFileName:=ExtractFileName(More);
  1958. end
  1959. else
  1960. IllegalPara(opt);
  1961. end;
  1962. 'O' :
  1963. begin
  1964. j:=1;
  1965. while j<=length(more) do
  1966. begin
  1967. case more[j] of
  1968. '1' :
  1969. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1970. '2' :
  1971. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1972. '3' :
  1973. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1974. '4' :
  1975. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1976. 'a' :
  1977. begin
  1978. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1979. IllegalPara(opt);
  1980. break;
  1981. end;
  1982. 's' :
  1983. include(init_settings.optimizerswitches,cs_opt_size);
  1984. 'p' :
  1985. begin
  1986. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1987. begin
  1988. OptCPUSetExplicitly:=true;
  1989. { Give warning for old i386 switches }
  1990. if (Length(More)-j=1) and
  1991. (More[j+1]>='1') and (More[j+1]<='5')then
  1992. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1993. else
  1994. IllegalPara(opt);
  1995. end;
  1996. break;
  1997. end;
  1998. 'o' :
  1999. begin
  2000. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  2001. IllegalPara(opt);
  2002. break;
  2003. end;
  2004. '-' :
  2005. begin
  2006. init_settings.optimizerswitches:=[];
  2007. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2008. end;
  2009. { Obsolete switches }
  2010. 'g' :
  2011. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  2012. 'G' :
  2013. Message1(option_obsolete_switch,'-OG');
  2014. 'r' :
  2015. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  2016. 'u' :
  2017. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  2018. 'w' :
  2019. begin
  2020. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  2021. IllegalPara(opt);
  2022. break;
  2023. end;
  2024. 'W' :
  2025. begin
  2026. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  2027. IllegalPara(opt);
  2028. break;
  2029. end;
  2030. else
  2031. IllegalPara(opt);
  2032. end;
  2033. inc(j);
  2034. end;
  2035. end;
  2036. 'p' :
  2037. begin
  2038. if UnsetBool(More, 0, opt, false) then
  2039. begin
  2040. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  2041. undef_system_macro('FPC_PROFILE');
  2042. end
  2043. else
  2044. if Length(More)=0 then
  2045. IllegalPara(opt)
  2046. else
  2047. case more[1] of
  2048. 'g' : if UnsetBool(more, 1, opt, false) then
  2049. begin
  2050. exclude(init_settings.moduleswitches,cs_profile);
  2051. undef_system_macro('FPC_PROFILE');
  2052. end
  2053. else if (target_info.system in supported_targets_pg) then
  2054. begin
  2055. include(init_settings.moduleswitches,cs_profile);
  2056. def_system_macro('FPC_PROFILE');
  2057. end
  2058. else
  2059. UnsupportedPara('-pg');
  2060. else
  2061. IllegalPara(opt);
  2062. end;
  2063. end;
  2064. 'P' :
  2065. begin
  2066. { used to select the target processor with the "fpc" binary;
  2067. give an error if it's not the target architecture supported by
  2068. this compiler binary (will be verified after the target_info
  2069. is set) }
  2070. processorstr:=More;
  2071. end;
  2072. 'R' :
  2073. begin
  2074. if not SetAsmReadMode(More,init_settings.asmmode) then
  2075. IllegalPara(opt);
  2076. end;
  2077. 's' :
  2078. begin
  2079. if UnsetBool(More, 0, opt, false) then
  2080. begin
  2081. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2082. if more<>'' then
  2083. IllegalPara(opt);
  2084. end
  2085. else
  2086. begin
  2087. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2088. if more='h' then
  2089. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  2090. else if more='t' then
  2091. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  2092. else if more='T' then
  2093. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  2094. else if more='r' then
  2095. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  2096. else if more<>'' then
  2097. IllegalPara(opt);
  2098. end;
  2099. end;
  2100. 'S' :
  2101. begin
  2102. if more='' then
  2103. IllegalPara(opt);
  2104. if more[1]='I' then
  2105. begin
  2106. {$ifdef jvm}
  2107. UnsupportedPara('-SI');
  2108. {$endif}
  2109. if upper(more)='ICOM' then
  2110. init_settings.interfacetype:=it_interfacecom
  2111. else if upper(more)='ICORBA' then
  2112. init_settings.interfacetype:=it_interfacecorba
  2113. else
  2114. IllegalPara(opt);
  2115. end
  2116. else
  2117. begin
  2118. j:=1;
  2119. while j<=length(more) do
  2120. begin
  2121. case more[j] of
  2122. '2' : //an alternative to -Mobjfpc
  2123. SetCompileMode('OBJFPC',true);
  2124. 'a' :
  2125. If UnsetBool(More, j, opt, false) then
  2126. exclude(init_settings.localswitches,cs_do_assertion)
  2127. else
  2128. include(init_settings.localswitches,cs_do_assertion);
  2129. 'c' :
  2130. If UnsetBool(More, j, opt, false) then
  2131. exclude(init_settings.moduleswitches,cs_support_c_operators)
  2132. else
  2133. include(init_settings.moduleswitches,cs_support_c_operators);
  2134. 'C':
  2135. If UnsetBool(More, j, opt, false) then
  2136. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  2137. else
  2138. include(init_settings.localswitches,cs_check_all_case_coverage);
  2139. 'd' : //an alternative to -Mdelphi
  2140. SetCompileMode('DELPHI',true);
  2141. 'e' :
  2142. begin
  2143. SetErrorFlags(copy(more,j+1,length(more)));
  2144. break;
  2145. end;
  2146. 'f' :
  2147. begin
  2148. if not(cs_compilesystem in init_settings.moduleswitches) then
  2149. Message(option_features_only_for_system_unit);
  2150. inc(j);
  2151. if more[j]='-' then
  2152. begin
  2153. if length(more)>j then
  2154. IllegalPara(opt)
  2155. else
  2156. features:=[];
  2157. end
  2158. else
  2159. begin
  2160. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  2161. j:=length(more)
  2162. else
  2163. IllegalPara(opt);
  2164. end;
  2165. end;
  2166. 'g' :
  2167. If UnsetBool(More, j, opt, false) then
  2168. exclude(init_settings.moduleswitches,cs_support_goto)
  2169. else
  2170. include(init_settings.moduleswitches,cs_support_goto);
  2171. 'h' :
  2172. If UnsetBool(More, j, opt, false) then
  2173. exclude(init_settings.localswitches,cs_refcountedstrings)
  2174. else
  2175. include(init_settings.localswitches,cs_refcountedstrings);
  2176. 'i' :
  2177. If UnsetBool(More, j, opt, false) then
  2178. exclude(init_settings.localswitches,cs_do_inline)
  2179. else
  2180. include(init_settings.localswitches,cs_do_inline);
  2181. 'j' :
  2182. If UnsetBool(More, j, opt, false) then
  2183. exclude(init_settings.localswitches,cs_typed_const_writable)
  2184. else
  2185. include(init_settings.localswitches,cs_typed_const_writable);
  2186. 'k' :
  2187. If UnsetBool(More, j, opt, false) then
  2188. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  2189. else
  2190. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2191. 'm' :
  2192. If UnsetBool(More, j, opt, false) then
  2193. exclude(init_settings.moduleswitches,cs_support_macro)
  2194. else
  2195. include(init_settings.moduleswitches,cs_support_macro);
  2196. 'o' : //an alternative to -Mtp
  2197. SetCompileMode('TP',true);
  2198. 'r' :
  2199. If UnsetBool(More, j, opt, false) then
  2200. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2201. else
  2202. include(init_settings.globalswitches,cs_transparent_file_names);
  2203. {$ifdef gpc_mode}
  2204. 'p' : //an alternative to -Mgpc
  2205. SetCompileMode('GPC',true);
  2206. {$endif}
  2207. 's' :
  2208. If UnsetBool(More, j, opt, false) then
  2209. exclude(init_settings.globalswitches,cs_constructor_name)
  2210. else
  2211. include(init_settings.globalswitches,cs_constructor_name);
  2212. 't' :
  2213. Message1(option_obsolete_switch,'-St');
  2214. 'v' :
  2215. If UnsetBool(More, j, opt, false) then
  2216. exclude(init_settings.globalswitches,cs_support_vectors)
  2217. else
  2218. include(init_settings.globalswitches,cs_support_vectors);
  2219. 'x' :
  2220. If UnsetBool(More, j, opt, false) then
  2221. SetCompileModeSwitch('EXCEPTIONS-',true)
  2222. else
  2223. SetCompileModeSwitch('EXCEPTIONS',true);
  2224. 'y' :
  2225. If UnsetBool(More, j, opt, false) then
  2226. exclude(init_settings.localswitches,cs_typed_addresses)
  2227. else
  2228. include(init_settings.localswitches,cs_typed_addresses);
  2229. '-' :
  2230. begin
  2231. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2232. cs_support_vectors,cs_load_fpcylix_unit];
  2233. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2234. cs_typed_addresses];
  2235. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2236. cs_support_macro];
  2237. end;
  2238. else
  2239. IllegalPara(opt);
  2240. end;
  2241. inc(j);
  2242. end;
  2243. end;
  2244. end;
  2245. 'T' :
  2246. begin
  2247. more:=Upper(More);
  2248. if paratarget=system_none then
  2249. begin
  2250. { remove old target define }
  2251. TargetOptions(false);
  2252. { load new target }
  2253. paratarget:=find_system_by_string(More);
  2254. if paratarget<>system_none then
  2255. set_target(paratarget)
  2256. else
  2257. IllegalPara(opt);
  2258. { set new define }
  2259. TargetOptions(true);
  2260. end
  2261. else
  2262. if More<>upper(target_info.shortname) then
  2263. Message1(option_target_is_already_set,target_info.shortname);
  2264. end;
  2265. 'u' :
  2266. if is_identifier(more) then
  2267. undef_system_macro(more)
  2268. else
  2269. begin
  2270. if (more='') then
  2271. Message1(option_missing_arg,'-u')
  2272. else
  2273. Message1(option_malformed_para,opt);
  2274. StopOptions(1);
  2275. end;
  2276. 'U' :
  2277. begin
  2278. j:=1;
  2279. while j<=length(more) do
  2280. begin
  2281. case more[j] of
  2282. {$ifdef UNITALIASES}
  2283. 'a' :
  2284. begin
  2285. AddUnitAlias(Copy(More,j+1,255));
  2286. break;
  2287. end;
  2288. {$endif UNITALIASES}
  2289. 'n' :
  2290. exclude(init_settings.globalswitches,cs_check_unit_name);
  2291. 'p' :
  2292. begin
  2293. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2294. break;
  2295. end;
  2296. 'r' :
  2297. begin
  2298. do_release:=true;
  2299. if (cs_checkpointer in init_settings.localswitches) then
  2300. begin
  2301. Message(option_gc_incompatible_with_release_flag);
  2302. exclude(init_settings.localswitches,cs_checkpointer);
  2303. end;
  2304. end;
  2305. 's' :
  2306. include(init_settings.moduleswitches,cs_compilesystem);
  2307. '-' :
  2308. begin
  2309. exclude(init_settings.moduleswitches,cs_compilesystem);
  2310. exclude(init_settings.globalswitches,cs_check_unit_name);
  2311. end;
  2312. else
  2313. IllegalPara(opt);
  2314. end;
  2315. inc(j);
  2316. end;
  2317. end;
  2318. 'v' :
  2319. begin
  2320. if not setverbosity(More) then
  2321. IllegalPara(opt);
  2322. end;
  2323. 'V' : ; { Ignore used by fpc }
  2324. 'W' :
  2325. begin
  2326. j:=1;
  2327. while j<=length(More) do
  2328. begin
  2329. case More[j] of
  2330. 'A':
  2331. begin
  2332. if target_info.system in systems_all_windows then
  2333. begin
  2334. if UnsetBool(More, j, opt, false) then
  2335. SetApptype(app_cui)
  2336. else
  2337. SetApptype(app_native);
  2338. end
  2339. else
  2340. IllegalPara(opt);
  2341. end;
  2342. 'b':
  2343. begin
  2344. if target_info.system in systems_darwin then
  2345. begin
  2346. if UnsetBool(More, j, opt, false) then
  2347. SetApptype(app_cui)
  2348. else
  2349. SetApptype(app_bundle)
  2350. end
  2351. else
  2352. IllegalPara(opt);
  2353. end;
  2354. 'B':
  2355. begin
  2356. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  2357. begin
  2358. { -WB200000 means set trefered base address
  2359. to $200000, but does not change relocsection boolean
  2360. this way we can create both relocatble and
  2361. non relocatable DLL at a specific base address PM }
  2362. if (length(More)>j) then
  2363. begin
  2364. val('$'+Copy(More,j+1,255),imagebase,code);
  2365. if code<>0 then
  2366. IllegalPara(opt);
  2367. ImageBaseSetExplicity:=true;
  2368. end
  2369. else
  2370. begin
  2371. RelocSection:=true;
  2372. RelocSectionSetExplicitly:=true;
  2373. end;
  2374. break;
  2375. end
  2376. else
  2377. IllegalPara(opt);
  2378. end;
  2379. 'C':
  2380. begin
  2381. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2382. begin
  2383. if UnsetBool(More, j, opt, false) then
  2384. SetApptype(app_gui)
  2385. else
  2386. SetApptype(app_cui);
  2387. end
  2388. else
  2389. IllegalPara(opt);
  2390. end;
  2391. 'D':
  2392. begin
  2393. if target_info.system in systems_all_windows then
  2394. begin
  2395. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2396. UseDeffileForExportsSetExplicitly:=true;
  2397. end
  2398. else
  2399. IllegalPara(opt);
  2400. end;
  2401. 'e':
  2402. begin
  2403. if (target_info.system in systems_darwin) then
  2404. begin
  2405. set_target_res(res_ext);
  2406. target_info.resobjext:='.fpcres';
  2407. end
  2408. else
  2409. IllegalPara(opt);
  2410. end;
  2411. 'F':
  2412. begin
  2413. if target_info.system in systems_os2 then
  2414. begin
  2415. if UnsetBool(More, j, opt, false) then
  2416. SetApptype(app_cui)
  2417. else
  2418. SetApptype(app_fs);
  2419. end
  2420. else
  2421. IllegalPara(opt);
  2422. end;
  2423. 'G':
  2424. begin
  2425. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2426. begin
  2427. if UnsetBool(More, j, opt, false) then
  2428. SetApptype(app_cui)
  2429. else
  2430. SetApptype(app_gui);
  2431. end
  2432. else
  2433. IllegalPara(opt);
  2434. end;
  2435. {$if defined(i8086)}
  2436. 'h':
  2437. begin
  2438. if UnsetBool(More, j, opt, false) then
  2439. exclude(init_settings.moduleswitches,cs_huge_code)
  2440. else
  2441. include(init_settings.moduleswitches,cs_huge_code);
  2442. end;
  2443. {$endif defined(i8086)}
  2444. 'I':
  2445. begin
  2446. if target_info.system in systems_all_windows then
  2447. begin
  2448. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2449. GenerateImportSectionSetExplicitly:=true;
  2450. end
  2451. else
  2452. IllegalPara(opt);
  2453. end;
  2454. 'i':
  2455. begin
  2456. if (target_info.system in systems_darwin) then
  2457. begin
  2458. set_target_res(res_macho);
  2459. target_info.resobjext:=
  2460. targetinfos[target_info.system]^.resobjext;
  2461. end
  2462. else
  2463. IllegalPara(opt);
  2464. end;
  2465. 'm':
  2466. begin
  2467. {$if defined(i8086)}
  2468. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2469. begin
  2470. case Upper(Copy(More,j+1,255)) of
  2471. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2472. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2473. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2474. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2475. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2476. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2477. else
  2478. IllegalPara(opt);
  2479. end;
  2480. break;
  2481. end
  2482. else
  2483. {$endif defined(i8086)}
  2484. IllegalPara(opt);
  2485. end;
  2486. 'M':
  2487. begin
  2488. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2489. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2490. begin
  2491. break;
  2492. end
  2493. else
  2494. IllegalPara(opt);
  2495. end;
  2496. 'N':
  2497. begin
  2498. if target_info.system in systems_all_windows then
  2499. begin
  2500. RelocSection:=UnsetBool(More,j,opt,false);
  2501. RelocSectionSetExplicitly:=true;
  2502. end
  2503. else
  2504. IllegalPara(opt);
  2505. end;
  2506. 'p':
  2507. begin
  2508. {$push}
  2509. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2510. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  2511. ControllerSupport then
  2512. begin
  2513. s:=upper(copy(more,j+1,length(more)-j));
  2514. if not(SetControllerType(s,init_settings.controllertype)) then
  2515. IllegalPara(opt)
  2516. else
  2517. begin
  2518. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2519. begin
  2520. Message(scan_n_changecputype);
  2521. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2522. end;
  2523. end;
  2524. break;
  2525. end
  2526. else
  2527. IllegalPara(opt);
  2528. {$pop}
  2529. end;
  2530. 'P':
  2531. begin
  2532. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2533. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2534. begin
  2535. break;
  2536. end
  2537. else
  2538. IllegalPara(opt);
  2539. end;
  2540. {$if defined(m68k)}
  2541. 'Q':
  2542. begin
  2543. if (target_info.system in [system_m68k_sinclairql]) then
  2544. begin
  2545. sinclairql_metadata_format:=Upper(Copy(More,j+1,255));
  2546. case sinclairql_metadata_format of
  2547. 'QHDR', 'XTCC': ; { allowed formats }
  2548. else
  2549. IllegalPara(opt);
  2550. end;
  2551. break;
  2552. end
  2553. else
  2554. IllegalPara(opt);
  2555. end;
  2556. {$endif defined(m68k)}
  2557. 'R':
  2558. begin
  2559. if target_info.system in systems_all_windows then
  2560. begin
  2561. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2562. RelocSection:=not UnsetBool(More,j,opt,false);
  2563. RelocSectionSetExplicitly:=true;
  2564. end
  2565. else
  2566. IllegalPara(opt);
  2567. end;
  2568. 't':
  2569. begin
  2570. {$if defined(i8086)}
  2571. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2572. begin
  2573. case Upper(Copy(More,j+1,255)) of
  2574. 'EXE': SetAppType(app_cui);
  2575. 'COM': SetAppType(app_com);
  2576. else
  2577. IllegalPara(opt);
  2578. end;
  2579. break;
  2580. end
  2581. else
  2582. {$endif defined(i8086)}
  2583. IllegalPara(opt);
  2584. end;
  2585. 'T':
  2586. begin
  2587. if target_info.system in systems_macos then
  2588. begin
  2589. if UnsetBool(More, j, opt, false) then
  2590. SetApptype(app_cui)
  2591. else
  2592. SetApptype(app_tool);
  2593. end
  2594. else
  2595. IllegalPara(opt);
  2596. end;
  2597. 'X':
  2598. begin
  2599. if (target_info.system in systems_linux) then
  2600. begin
  2601. if UnsetBool(More, j, opt, false) then
  2602. exclude(init_settings.moduleswitches,cs_executable_stack)
  2603. else
  2604. include(init_settings.moduleswitches,cs_executable_stack)
  2605. end
  2606. else
  2607. IllegalPara(opt);
  2608. end;
  2609. else
  2610. IllegalPara(opt);
  2611. end;
  2612. inc(j);
  2613. end;
  2614. end;
  2615. 'X' :
  2616. begin
  2617. j:=1;
  2618. while j<=length(more) do
  2619. begin
  2620. case More[j] of
  2621. '9' :
  2622. begin
  2623. if target_info.system in systems_linux then
  2624. begin
  2625. if UnsetBool(More, j, opt, false) then
  2626. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2627. else
  2628. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2629. end
  2630. else
  2631. IllegalPara(opt);
  2632. end;
  2633. 'a' :
  2634. begin
  2635. If UnsetBool(More, j, opt, false) then
  2636. exclude(init_settings.globalswitches,cs_large)
  2637. else
  2638. include(init_settings.globalswitches,cs_large);
  2639. end;
  2640. 'c' : Cshared:=TRUE;
  2641. 'd' : Dontlinkstdlibpath:=TRUE;
  2642. 'e' :
  2643. begin
  2644. If UnsetBool(More, j, opt, false) then
  2645. exclude(init_settings.globalswitches,cs_link_extern)
  2646. else
  2647. include(init_settings.globalswitches,cs_link_extern);
  2648. end;
  2649. 'f' :
  2650. include(init_settings.globalswitches,cs_link_pthread);
  2651. 'g' :
  2652. begin
  2653. If UnsetBool(More, j, opt, false) then
  2654. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2655. else
  2656. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2657. end;
  2658. 'i' :
  2659. begin
  2660. If UnsetBool(More, j, opt, false) then
  2661. include(init_settings.globalswitches,cs_link_extern)
  2662. else
  2663. exclude(init_settings.globalswitches,cs_link_extern);
  2664. end;
  2665. 'n' :
  2666. begin
  2667. If UnsetBool(More, j, opt, false) then
  2668. exclude(init_settings.globalswitches,cs_link_native)
  2669. else
  2670. include(init_settings.globalswitches,cs_link_native);
  2671. end;
  2672. {$ifdef llvm}
  2673. 'l' :
  2674. begin
  2675. if j=length(more) then
  2676. IllegalPara(opt)
  2677. else
  2678. begin
  2679. case more[j+1] of
  2680. 'S':
  2681. begin
  2682. llvmutilssuffix:=copy(more,j+2,length(more));
  2683. j:=length(more);
  2684. end
  2685. else
  2686. IllegalPara(opt);
  2687. end;
  2688. end;
  2689. end;
  2690. {$endif}
  2691. 'm' :
  2692. begin
  2693. If UnsetBool(More, j, opt, false) then
  2694. exclude(init_settings.globalswitches,cs_link_map)
  2695. else
  2696. include(init_settings.globalswitches,cs_link_map);
  2697. end;
  2698. 'p' : ; { Ignore used by fpc.pp }
  2699. 'r' :
  2700. begin
  2701. if (target_info.system in suppported_targets_x_smallr) then
  2702. begin
  2703. rlinkpath:=Copy(more,2,length(More)-1);
  2704. DefaultReplacements(rlinkpath);
  2705. end
  2706. else
  2707. IgnoredPara('-Xr');
  2708. more:='';
  2709. end;
  2710. 'R' :
  2711. begin
  2712. sysrootpath:=copy(more,2,length(more)-1);
  2713. defaultreplacements(sysrootpath);
  2714. more:='';
  2715. end;
  2716. 's' :
  2717. begin
  2718. If UnsetBool(More, j, opt, false) then
  2719. exclude(init_settings.globalswitches,cs_link_strip)
  2720. else
  2721. include(init_settings.globalswitches,cs_link_strip);
  2722. end;
  2723. 't' :
  2724. include(init_settings.globalswitches,cs_link_staticflag);
  2725. 'u' :
  2726. begin
  2727. if target_info.system in systems_support_uf2 then
  2728. begin
  2729. if UnsetBool(More, j, opt, false) then
  2730. exclude(init_settings.globalswitches,cs_generate_uf2)
  2731. else
  2732. include(init_settings.globalswitches,cs_generate_uf2);
  2733. end
  2734. else
  2735. IgnoredPara('-Xu');
  2736. end;
  2737. 'v' :
  2738. begin
  2739. If UnsetBool(More, j, opt, false) then
  2740. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2741. else
  2742. include(init_settings.globalswitches,cs_link_opt_vtable);
  2743. end;
  2744. 'D' :
  2745. begin
  2746. def_system_macro('FPC_LINK_DYNAMIC');
  2747. undef_system_macro('FPC_LINK_SMART');
  2748. undef_system_macro('FPC_LINK_STATIC');
  2749. exclude(init_settings.globalswitches,cs_link_static);
  2750. exclude(init_settings.globalswitches,cs_link_smart);
  2751. include(init_settings.globalswitches,cs_link_shared);
  2752. LinkTypeSetExplicitly:=true;
  2753. end;
  2754. 'M' :
  2755. begin
  2756. mainaliasname:=Copy(more,2,length(More)-1);
  2757. More:='';
  2758. end;
  2759. 'P' :
  2760. begin
  2761. utilsprefix:=Copy(more,2,length(More)-1);
  2762. DefaultReplacements(utilsprefix);
  2763. More:='';
  2764. end;
  2765. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2766. // these are not aggregable.
  2767. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2768. IllegalPara(opt)
  2769. else
  2770. begin
  2771. case more[j+1] of
  2772. 'A' : begin
  2773. s:=Copy(more,3,length(More)-2);
  2774. if not LinkLibraryAliases.AddDep(s) Then
  2775. IllegalPara(opt);
  2776. end;
  2777. 'O' : begin
  2778. s:=Copy(more,3,length(More)-2);
  2779. if not LinkLibraryOrder.AddWeight(s) Then
  2780. IllegalPara(opt);
  2781. end;
  2782. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2783. else
  2784. IllegalPara(opt);
  2785. end; {case}
  2786. j:=length(more);
  2787. end; {else begin}
  2788. end;
  2789. 'S' :
  2790. begin
  2791. ForceStaticLinking;
  2792. end;
  2793. 'V' :
  2794. begin
  2795. if UnsetBool(More, j, opt, false) then
  2796. exclude(init_settings.globalswitches,cs_link_vlink)
  2797. else
  2798. begin
  2799. include(init_settings.globalswitches,cs_link_vlink);
  2800. include(init_settings.globalswitches,cs_link_extern);
  2801. end;
  2802. LinkerSetExplicitly:=true;
  2803. end;
  2804. 'X' :
  2805. begin
  2806. def_system_macro('FPC_LINK_SMART');
  2807. undef_system_macro('FPC_LINK_STATIC');
  2808. undef_system_macro('FPC_LINK_DYNAMIC');
  2809. exclude(init_settings.globalswitches,cs_link_static);
  2810. include(init_settings.globalswitches,cs_link_smart);
  2811. exclude(init_settings.globalswitches,cs_link_shared);
  2812. LinkTypeSetExplicitly:=true;
  2813. end;
  2814. '-' :
  2815. begin
  2816. exclude(init_settings.globalswitches,cs_link_staticflag);
  2817. exclude(init_settings.globalswitches,cs_link_strip);
  2818. exclude(init_settings.globalswitches,cs_link_map);
  2819. set_default_link_type;
  2820. end;
  2821. else
  2822. IllegalPara(opt);
  2823. end;
  2824. inc(j);
  2825. end;
  2826. end;
  2827. else
  2828. IllegalPara(opt);
  2829. end;
  2830. end;
  2831. '@' :
  2832. begin
  2833. Message(option_no_nested_response_file);
  2834. StopOptions(1);
  2835. end;
  2836. else
  2837. begin
  2838. if (length(param_file)<>0) then
  2839. Message2(option_only_one_source_support,param_file,opt);
  2840. param_file:=opt;
  2841. Message1(option_found_file,opt);
  2842. end;
  2843. end;
  2844. end;
  2845. procedure Toption.Interpret_file(const filename : TPathStr);
  2846. procedure RemoveSep(var fn:TPathStr);
  2847. var
  2848. i : longint;
  2849. begin
  2850. i:=0;
  2851. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2852. inc(i);
  2853. Delete(fn,1,i);
  2854. i:=length(fn);
  2855. while (i>0) and (fn[i] in [',',' ',#9]) do
  2856. dec(i);
  2857. fn:=copy(fn,1,i);
  2858. end;
  2859. function GetName(var fn:TPathStr):TPathStr;
  2860. var
  2861. i : longint;
  2862. begin
  2863. i:=0;
  2864. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2865. inc(i);
  2866. GetName:=Copy(fn,1,i);
  2867. Delete(fn,1,i);
  2868. end;
  2869. const
  2870. maxlevel = 15;
  2871. var
  2872. f : text;
  2873. s, tmp,
  2874. opts : TCmdStr;
  2875. skip : array[0..maxlevel] of boolean;
  2876. line,
  2877. level : longint;
  2878. option_read : boolean;
  2879. oldfilemode : byte;
  2880. ConfigFile: TPathStr;
  2881. begin
  2882. { avoid infinite loop }
  2883. Inc(FileLevel);
  2884. Option_read:=false;
  2885. If FileLevel>MaxLevel then
  2886. Message(option_too_many_cfg_files);
  2887. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2888. ConfigFile := ExpandFileName(filename);
  2889. { Maybe It's Directory ?} //Jaro Change:
  2890. if PathExists(ConfigFile,false) then
  2891. begin
  2892. Message1(option_config_is_dir,filename);
  2893. exit;
  2894. end;
  2895. { open file }
  2896. Message1(option_using_file,filename);
  2897. oldfilemode:=filemode;
  2898. filemode:=0;
  2899. assign(f,ConfigFile);
  2900. {$push}{$I-}
  2901. reset(f);
  2902. {$pop}
  2903. filemode:=oldfilemode;
  2904. if ioresult<>0 then
  2905. begin
  2906. Message1(option_unable_open_file,filename);
  2907. exit;
  2908. end;
  2909. Message1(option_start_reading_configfile,filename);
  2910. fillchar(skip,sizeof(skip),0);
  2911. level:=0;
  2912. line:=0;
  2913. while not eof(f) do
  2914. begin
  2915. readln(f,opts);
  2916. inc(line);
  2917. RemoveSep(opts);
  2918. if (opts<>'') and (opts[1]<>';') then
  2919. begin
  2920. if opts[1]='#' then
  2921. begin
  2922. Message1(option_interpreting_file_option,opts);
  2923. Delete(opts,1,1);
  2924. s:=upper(GetName(opts));
  2925. if (s='SECTION') then
  2926. begin
  2927. RemoveSep(opts);
  2928. s:=upper(GetName(opts));
  2929. if level=0 then
  2930. skip[level]:=not defined_macro(s) or (s='COMMON');
  2931. end
  2932. else
  2933. if (s='IFDEF') then
  2934. begin
  2935. RemoveSep(opts);
  2936. if Level>=maxlevel then
  2937. begin
  2938. Message2(option_too_many_ifdef,filename,tostr(line));
  2939. stopOptions(1);
  2940. end;
  2941. inc(Level);
  2942. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2943. end
  2944. else
  2945. if (s='IFNDEF') then
  2946. begin
  2947. RemoveSep(opts);
  2948. if Level>=maxlevel then
  2949. begin
  2950. Message2(option_too_many_ifdef,filename,tostr(line));
  2951. stopOptions(1);
  2952. end;
  2953. inc(Level);
  2954. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2955. end
  2956. else
  2957. if (s='ELSE') then
  2958. begin
  2959. if Level=0 then
  2960. begin
  2961. Message2(option_else_without_if,filename,tostr(line));
  2962. stopOptions(1);
  2963. end
  2964. else
  2965. skip[level]:=skip[level-1] or (not skip[level])
  2966. end
  2967. else
  2968. if (s='ENDIF') then
  2969. begin
  2970. skip[level]:=false;
  2971. if Level=0 then
  2972. begin
  2973. Message2(option_too_many_endif,filename,tostr(line));
  2974. stopOptions(1);
  2975. end;
  2976. dec(level);
  2977. end
  2978. else
  2979. if (not skip[level]) then
  2980. begin
  2981. if (s='DEFINE') then
  2982. begin
  2983. RemoveSep(opts);
  2984. tmp:= GetName(opts);
  2985. if tmp <> '' then
  2986. def_system_macro(tmp);
  2987. Option_read:=true;
  2988. end
  2989. else
  2990. if (s='UNDEF') then
  2991. begin
  2992. RemoveSep(opts);
  2993. tmp:= GetName(opts);
  2994. if tmp <> '' then
  2995. undef_system_macro(tmp);
  2996. Option_read:=true;
  2997. end
  2998. else
  2999. if (s='WRITE') then
  3000. begin
  3001. Delete(opts,1,1);
  3002. DefaultReplacements(opts);
  3003. WriteLn(opts);
  3004. Option_read:=true;
  3005. end
  3006. else
  3007. if (s='INCLUDE') then
  3008. begin
  3009. Delete(opts,1,1);
  3010. DefaultReplacements(opts);
  3011. Interpret_file(opts);
  3012. Option_read:=true;
  3013. end
  3014. else
  3015. if (s='CFGDIR') then
  3016. begin
  3017. Delete(opts,1,1);
  3018. DefaultReplacements(opts);
  3019. ParaIncludeCfgPath.AddPath(opts,false);
  3020. Option_read:=true;
  3021. end;
  3022. end;
  3023. end
  3024. else
  3025. begin
  3026. if (opts[1]='-') or (opts[1]='@') then
  3027. begin
  3028. if (not skip[level]) then
  3029. interpret_option(opts,false);
  3030. Option_read:=true;
  3031. end
  3032. else
  3033. Message1(option_illegal_para,opts);
  3034. end;
  3035. end;
  3036. end;
  3037. if Level>0 then
  3038. Message(option_too_less_endif);
  3039. if Not Option_read then
  3040. Message1(option_no_option_found,filename)
  3041. else
  3042. Message1(option_end_reading_configfile,filename);
  3043. Close(f);
  3044. Dec(FileLevel);
  3045. end;
  3046. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  3047. var
  3048. argstart,
  3049. env,
  3050. pc : pchar;
  3051. arglen : longint;
  3052. quote : set of char;
  3053. hs : TCmdStr;
  3054. begin
  3055. Message1(option_using_env,envname);
  3056. env:=GetEnvPChar(envname);
  3057. pc:=env;
  3058. hs:='';
  3059. if assigned(pc) then
  3060. begin
  3061. repeat
  3062. { skip leading spaces }
  3063. while pc^ in [' ',#9,#13] do
  3064. inc(pc);
  3065. case pc^ of
  3066. #0 :
  3067. break;
  3068. '"' :
  3069. begin
  3070. quote:=['"'];
  3071. inc(pc);
  3072. end;
  3073. '''' :
  3074. begin
  3075. quote:=[''''];
  3076. inc(pc);
  3077. end;
  3078. else
  3079. quote:=[' ',#9,#13];
  3080. end;
  3081. { scan until the end of the argument }
  3082. argstart:=pc;
  3083. while (pc^<>#0) and not(pc^ in quote) do
  3084. inc(pc);
  3085. { create argument }
  3086. arglen:=pc-argstart;
  3087. { TODO: FIXME: silent truncation of environment parameters }
  3088. if (arglen > 255) then
  3089. arglen := 255;
  3090. setlength(hs,arglen);
  3091. move(argstart^,hs[1],arglen);
  3092. interpret_option(hs,true);
  3093. { skip quote }
  3094. if pc^ in quote then
  3095. inc(pc);
  3096. until false;
  3097. end
  3098. else
  3099. Message1(option_no_option_found,'(env) '+envname);
  3100. FreeEnvPChar(env);
  3101. end;
  3102. procedure toption.read_parameters;
  3103. var
  3104. opts : TCmdStr;
  3105. paramindex : longint;
  3106. begin
  3107. paramindex:=0;
  3108. while paramindex<paramcount do
  3109. begin
  3110. inc(paramindex);
  3111. opts:=objpas.paramstr(paramindex);
  3112. if length(opts)>0 then
  3113. case opts[1] of
  3114. '@' :
  3115. if not firstpass then
  3116. begin
  3117. Delete(opts,1,1);
  3118. Message1(option_reading_further_from,opts);
  3119. interpret_file(opts);
  3120. end;
  3121. '!' :
  3122. if not firstpass then
  3123. begin
  3124. Delete(opts,1,1);
  3125. Message1(option_reading_further_from,'(env) '+opts);
  3126. interpret_envvar(opts);
  3127. end;
  3128. else
  3129. interpret_option(opts,true);
  3130. end;
  3131. end;
  3132. end;
  3133. procedure toption.parsecmd(cmd:TCmdStr);
  3134. var
  3135. i,ps : longint;
  3136. opts : TCmdStr;
  3137. begin
  3138. while (cmd<>'') do
  3139. begin
  3140. while cmd[1]=' ' do
  3141. delete(cmd,1,1);
  3142. i:=pos(' ',cmd);
  3143. if i=0 then
  3144. i:=2147483647;
  3145. opts:=Copy(cmd,1,i-1);
  3146. Delete(cmd,1,i);
  3147. case opts[1] of
  3148. '@' :
  3149. if not firstpass then
  3150. begin
  3151. Delete(opts,1,1);
  3152. Message1(option_reading_further_from,opts);
  3153. interpret_file(opts);
  3154. end;
  3155. '!' :
  3156. if not firstpass then
  3157. begin
  3158. Delete(opts,1,1);
  3159. Message1(option_reading_further_from,'(env) '+opts);
  3160. interpret_envvar(opts);
  3161. end;
  3162. '"' :
  3163. begin
  3164. Delete(opts,1,1);
  3165. ps:=pos('"',cmd);
  3166. if (i<>256) and (ps>0) then
  3167. begin
  3168. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3169. cmd:=copy(cmd,ps+1,255);
  3170. end;
  3171. interpret_option(opts,true);
  3172. end;
  3173. else
  3174. interpret_option(opts,true);
  3175. end;
  3176. end;
  3177. end;
  3178. procedure toption.writequickinfo;
  3179. var
  3180. s : string;
  3181. i : longint;
  3182. procedure addinfo(const hs:string);
  3183. begin
  3184. if s<>'' then
  3185. s:=s+' '+hs
  3186. else
  3187. s:=hs;
  3188. end;
  3189. begin
  3190. s:='';
  3191. i:=0;
  3192. while (i<length(quickinfo)) do
  3193. begin
  3194. inc(i);
  3195. case quickinfo[i] of
  3196. 'S' :
  3197. begin
  3198. inc(i);
  3199. case quickinfo[i] of
  3200. 'O' :
  3201. addinfo(lower(source_info.shortname));
  3202. 'P' :
  3203. addinfo(source_cpu_string);
  3204. else
  3205. IllegalPara('-i'+QuickInfo);
  3206. end;
  3207. end;
  3208. 'T' :
  3209. begin
  3210. inc(i);
  3211. case quickinfo[i] of
  3212. 'O' :
  3213. addinfo(lower(target_info.shortname));
  3214. 'P' :
  3215. AddInfo(target_cpu_string);
  3216. else
  3217. IllegalPara('-i'+QuickInfo);
  3218. end;
  3219. end;
  3220. 'V' :
  3221. AddInfo(version_string);
  3222. 'W' :
  3223. AddInfo(full_version_string);
  3224. 'D' :
  3225. AddInfo(date_string);
  3226. '_' :
  3227. ;
  3228. else
  3229. IllegalPara('-i'+QuickInfo);
  3230. end;
  3231. end;
  3232. if s<>'' then
  3233. begin
  3234. writeln(s);
  3235. stopoptions(0);
  3236. end;
  3237. end;
  3238. procedure TOption.TargetOptions(def:boolean);
  3239. var
  3240. s : string;
  3241. i : integer;
  3242. target_unsup_features : tfeatures;
  3243. begin
  3244. if def then
  3245. def_system_macro(target_info.shortname)
  3246. else
  3247. undef_system_macro(target_info.shortname);
  3248. s:=target_info.extradefines;
  3249. while (s<>'') do
  3250. begin
  3251. i:=pos(';',s);
  3252. if i=0 then
  3253. i:=length(s)+1;
  3254. if def then
  3255. def_system_macro(Copy(s,1,i-1))
  3256. else
  3257. undef_system_macro(Copy(s,1,i-1));
  3258. delete(s,1,i);
  3259. end;
  3260. if (tf_winlikewidestring in target_info.flags) then
  3261. if def then
  3262. def_system_macro('FPC_WINLIKEWIDESTRING')
  3263. else
  3264. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3265. if (tf_requires_proper_alignment in target_info.flags) then
  3266. if def then
  3267. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3268. else
  3269. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3270. if (tf_init_final_units_by_calls in target_info.flags) then
  3271. if def then
  3272. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3273. else
  3274. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3275. if source_info.system<>target_info.system then
  3276. if def then
  3277. def_system_macro('FPC_CROSSCOMPILING')
  3278. else
  3279. undef_system_macro('FPC_CROSSCOMPILING');
  3280. if source_info.cpu<>target_info.cpu then
  3281. if def then
  3282. def_system_macro('FPC_CPUCROSSCOMPILING')
  3283. else
  3284. def_system_macro('FPC_CPUCROSSCOMPILING');
  3285. if (tf_no_generic_stackcheck in target_info.flags) then
  3286. if def then
  3287. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3288. else
  3289. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3290. if (tf_section_threadvars in target_info.flags) then
  3291. if def then
  3292. def_system_macro('FPC_SECTION_THREADVARS')
  3293. else
  3294. undef_system_macro('FPC_SECTION_THREADVARS');
  3295. if (tf_use_psabieh in target_info.flags) then
  3296. if def then
  3297. def_system_macro('FPC_USE_PSABIEH')
  3298. else
  3299. undef_system_macro('FPC_USE_PSABIEH');
  3300. { Code generation flags }
  3301. if (tf_pic_default in target_info.flags) then
  3302. if def then
  3303. include(init_settings.moduleswitches,cs_create_pic)
  3304. else
  3305. exclude(init_settings.moduleswitches,cs_create_pic);
  3306. { Resources support }
  3307. if (tf_has_winlike_resources in target_info.flags) then
  3308. if def then
  3309. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3310. else
  3311. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3312. { Features }
  3313. case target_info.system of
  3314. system_arm_gba:
  3315. target_unsup_features:=[f_dynlibs];
  3316. system_arm_nds:
  3317. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3318. system_i386_nativent:
  3319. // until these features are implemented, they are disabled in the compiler
  3320. target_unsup_features:=[f_stackcheck];
  3321. system_i8086_msdos:
  3322. target_unsup_features:=[f_threading,f_dynlibs];
  3323. system_i8086_win16:
  3324. target_unsup_features:=[f_threading];
  3325. system_jvm_java32,
  3326. system_jvm_android32:
  3327. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3328. f_variants,f_objects,f_commandargs,
  3329. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3330. system_arm_palmos,
  3331. system_m68k_palmos:
  3332. target_unsup_features:=[f_threading];
  3333. system_m68k_atari:
  3334. target_unsup_features:=[f_threading];
  3335. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3336. normal dynlibs infrastructure due to architectural differences, so therefore
  3337. lets disable the feature. }
  3338. system_m68k_amiga:
  3339. target_unsup_features:=[f_dynlibs];
  3340. system_m68k_sinclairql:
  3341. target_unsup_features:=[f_threading,f_dynlibs,f_commandargs,f_exitcode];
  3342. system_z80_zxspectrum:
  3343. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3344. system_z80_msxdos:
  3345. target_unsup_features:=[f_threading,f_dynlibs];
  3346. else
  3347. target_unsup_features:=[];
  3348. end;
  3349. if def then
  3350. features:=features-target_unsup_features
  3351. else
  3352. features:=features+target_unsup_features;
  3353. {$if defined(atari) or defined(hasamiga)}
  3354. { enable vlink as default linker on Atari and Amiga but not for cross compilers (for now) }
  3355. if (target_info.system in [system_m68k_amiga,system_m68k_atari,system_powerpc_amiga]) and
  3356. not LinkerSetExplicitly then
  3357. include(init_settings.globalswitches,cs_link_vlink);
  3358. {$endif}
  3359. {$ifdef m68k}
  3360. if (target_info.system in [system_m68k_sinclairql]) and
  3361. not LinkerSetExplicitly then
  3362. include(init_settings.globalswitches,cs_link_vlink);
  3363. {$endif m68k}
  3364. end;
  3365. procedure TOption.checkoptionscompatibility;
  3366. begin
  3367. {$ifdef i8086}
  3368. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3369. begin
  3370. Message(option_com_files_require_tiny_model);
  3371. StopOptions(1);
  3372. end;
  3373. {$endif i8086}
  3374. {$ifndef i8086_link_intern_debuginfo}
  3375. if (cs_debuginfo in init_settings.moduleswitches) and
  3376. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3377. not (cs_link_extern in init_settings.globalswitches) then
  3378. begin
  3379. Message(option_debug_info_requires_external_linker);
  3380. include(init_settings.globalswitches,cs_link_extern);
  3381. end;
  3382. {$endif i8086_link_intern_debuginfo}
  3383. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3384. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3385. begin
  3386. { smartlink creation does not yet work with DWARF
  3387. debug info on most targets, but it works in internal assembler }
  3388. if (cs_create_smart in init_settings.moduleswitches) and
  3389. not (af_outputbinary in target_asm.flags) then
  3390. begin
  3391. Message(option_dwarf_smartlink_creation);
  3392. exclude(init_settings.moduleswitches,cs_create_smart);
  3393. end;
  3394. { smart linking does not yet work with DWARF debug info on most targets }
  3395. if (cs_link_smart in init_settings.globalswitches) then
  3396. begin
  3397. Message(option_dwarf_smart_linking);
  3398. ForceStaticLinking;
  3399. end;
  3400. end;
  3401. { external debug info is only supported for DWARF on darwin }
  3402. if (target_info.system in systems_darwin) and
  3403. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3404. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3405. begin
  3406. Message(option_debug_external_unsupported);
  3407. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3408. end;
  3409. { Also create a smartlinked version, on an assembler that
  3410. does not support smartlink sections like nasm?
  3411. This is not compatible with using internal linker. }
  3412. if ((cs_link_smart in init_settings.globalswitches) or
  3413. (cs_create_smart in init_settings.moduleswitches)) and
  3414. (af_needar in target_asm.flags) and
  3415. not (af_smartlink_sections in target_asm.flags) and
  3416. not (cs_link_extern in init_settings.globalswitches) and
  3417. (target_info.link<>ld_none) and
  3418. not (cs_link_nolink in init_settings.globalswitches) then
  3419. begin
  3420. Message(option_smart_link_requires_external_linker);
  3421. include(init_settings.globalswitches,cs_link_extern);
  3422. end;
  3423. end;
  3424. constructor TOption.create;
  3425. begin
  3426. LogoWritten:=false;
  3427. NoPressEnter:=false;
  3428. FirstPass:=false;
  3429. ABISetExplicitly:=false;
  3430. FPUSetExplicitly:=false;
  3431. CPUSetExplicitly:=false;
  3432. OptCPUSetExplicitly:=false;
  3433. FileLevel:=0;
  3434. Quickinfo:='';
  3435. ParaIncludeCfgPath:=TSearchPathList.Create;
  3436. ParaIncludePath:=TSearchPathList.Create;
  3437. ParaObjectPath:=TSearchPathList.Create;
  3438. ParaUnitPath:=TSearchPathList.Create;
  3439. ParaLibraryPath:=TSearchPathList.Create;
  3440. ParaFrameworkPath:=TSearchPathList.Create;
  3441. parapackagepath:=TSearchPathList.Create;
  3442. parapackages:=TFPHashObjectList.Create;
  3443. paranamespaces:=TCmdStrList.Create;
  3444. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3445. MacVersionSet:=false;
  3446. paratarget:=system_none;
  3447. paratargetasm:=as_none;
  3448. paratargetdbg:=dbg_none;
  3449. LinkTypeSetExplicitly:=false;
  3450. LinkerSetExplicitly:=false;
  3451. end;
  3452. destructor TOption.destroy;
  3453. begin
  3454. ParaIncludeCfgPath.Free;
  3455. ParaIncludePath.Free;
  3456. ParaObjectPath.Free;
  3457. ParaUnitPath.Free;
  3458. ParaLibraryPath.Free;
  3459. ParaFrameworkPath.Free;
  3460. parapackagepath.Free;
  3461. ParaPackages.Free;
  3462. paranamespaces.free;
  3463. end;
  3464. {****************************************************************************
  3465. Callable Routines
  3466. ****************************************************************************}
  3467. function check_configfile(fn:string; var foundfn:string):boolean;
  3468. function CfgFileExists(const fn:string):boolean;
  3469. begin
  3470. Comment(V_Tried,'Configfile search: '+fn);
  3471. CfgFileExists:=FileExists(fn);
  3472. end;
  3473. var
  3474. {$ifdef Unix}
  3475. hs,
  3476. {$endif Unix}
  3477. configpath : string;
  3478. begin
  3479. foundfn:=fn;
  3480. check_configfile:=true;
  3481. { retrieve configpath }
  3482. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3483. {$ifdef Unix}
  3484. if configpath='' then
  3485. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3486. {$endif}
  3487. {
  3488. Order to read configuration file :
  3489. try reading fpc.cfg in :
  3490. 1 - current dir
  3491. 2 - configpath
  3492. 3 - compiler path
  3493. }
  3494. if not FileExists(fn) then
  3495. begin
  3496. {$ifdef Unix}
  3497. hs:=GetEnvironmentVariable('HOME');
  3498. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3499. foundfn:=FixPath(hs,false)+'.'+fn
  3500. else
  3501. {$endif}
  3502. if CfgFileExists(configpath+fn) then
  3503. foundfn:=configpath+fn
  3504. else
  3505. {$ifdef WINDOWS}
  3506. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3507. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3508. else
  3509. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3510. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3511. else
  3512. {$endif WINDOWS}
  3513. {$ifndef Unix}
  3514. if CfgFileExists(exepath+fn) then
  3515. foundfn:=exepath+fn
  3516. else
  3517. {$else}
  3518. if CfgFileExists('/etc/'+fn) then
  3519. foundfn:='/etc/'+fn
  3520. else
  3521. {$endif}
  3522. check_configfile:=false;
  3523. end;
  3524. end;
  3525. procedure read_arguments(cmd:TCmdStr);
  3526. procedure def_cpu_macros;
  3527. var
  3528. abi : tabi;
  3529. fputype : tfputype;
  3530. cputype : tcputype;
  3531. controller: tcontrollertype;
  3532. s: string;
  3533. begin
  3534. {$ifdef llvm}
  3535. def_system_macro('CPULLVM');
  3536. {$endif}
  3537. for cputype:=low(tcputype) to high(tcputype) do
  3538. undef_system_macro('CPU'+Cputypestr[cputype]);
  3539. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3540. for fputype:=low(tfputype) to high(tfputype) do
  3541. undef_system_macro('FPU'+fputypestr[fputype]);
  3542. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3543. {$PUSH}
  3544. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3545. if ControllerSupport then
  3546. begin
  3547. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3548. begin
  3549. s:=embedded_controllers[controller].controllertypestr;
  3550. if s<>'' then
  3551. undef_system_macro('FPC_MCU_'+s);
  3552. end;
  3553. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3554. if s<>'' then
  3555. def_system_macro('FPC_MCU_'+s);
  3556. end;
  3557. {$POP}
  3558. { define abi }
  3559. for abi:=low(tabi) to high(tabi) do
  3560. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3561. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3562. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3563. systems since most code needs to behave the same on both}
  3564. if target_info.abi = abi_eabihf then
  3565. def_system_macro('FPC_ABI_EABI');
  3566. { using a case is pretty useless here (FK) }
  3567. { some stuff for TP compatibility }
  3568. {$ifdef i386}
  3569. def_system_macro('CPU86');
  3570. def_system_macro('CPU87');
  3571. def_system_macro('CPU386');
  3572. {$endif}
  3573. { new processor stuff }
  3574. {$ifdef i386}
  3575. def_system_macro('CPUI386');
  3576. def_system_macro('CPU32');
  3577. def_system_macro('CPUX86');
  3578. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3579. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3580. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3581. {$endif}
  3582. {$ifdef m68k}
  3583. def_system_macro('CPU68');
  3584. def_system_macro('CPU68K');
  3585. def_system_macro('CPUM68K');
  3586. def_system_macro('CPU32');
  3587. def_system_macro('FPC_CURRENCY_IS_INT64');
  3588. def_system_macro('FPC_COMP_IS_INT64');
  3589. {$endif}
  3590. {$ifdef powerpc}
  3591. def_system_macro('CPUPOWERPC');
  3592. def_system_macro('CPUPOWERPC32');
  3593. def_system_macro('CPU32');
  3594. def_system_macro('FPC_CURRENCY_IS_INT64');
  3595. def_system_macro('FPC_COMP_IS_INT64');
  3596. {$endif}
  3597. {$ifdef POWERPC64}
  3598. def_system_macro('CPUPOWERPC');
  3599. def_system_macro('CPUPOWERPC64');
  3600. def_system_macro('CPU64');
  3601. def_system_macro('FPC_CURRENCY_IS_INT64');
  3602. def_system_macro('FPC_COMP_IS_INT64');
  3603. {$endif}
  3604. {$ifdef x86_64}
  3605. def_system_macro('CPUX86_64');
  3606. def_system_macro('CPUAMD64');
  3607. def_system_macro('CPU64');
  3608. def_system_macro('CPUX64');
  3609. { not supported for now, afaik (FK)
  3610. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3611. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3612. { normally, win64 doesn't support the legacy fpu }
  3613. if target_info.system=system_x86_64_win64 then
  3614. begin
  3615. def_system_macro('FPC_CURRENCY_IS_INT64');
  3616. def_system_macro('FPC_COMP_IS_INT64');
  3617. end;
  3618. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3619. {$endif}
  3620. {$ifdef sparc}
  3621. def_system_macro('CPUSPARCGEN');
  3622. def_system_macro('CPUSPARC');
  3623. def_system_macro('CPUSPARC32');
  3624. def_system_macro('CPU32');
  3625. def_system_macro('FPC_CURRENCY_IS_INT64');
  3626. def_system_macro('FPC_COMP_IS_INT64');
  3627. {$endif}
  3628. {$ifdef sparc64}
  3629. def_system_macro('CPUSPARCGEN');
  3630. def_system_macro('CPUSPARC64');
  3631. def_system_macro('CPU64');
  3632. def_system_macro('FPC_CURRENCY_IS_INT64');
  3633. def_system_macro('FPC_COMP_IS_INT64');
  3634. {$endif}
  3635. {$ifdef arm}
  3636. def_system_macro('CPUARM');
  3637. def_system_macro('CPU32');
  3638. def_system_macro('FPC_CURRENCY_IS_INT64');
  3639. def_system_macro('FPC_COMP_IS_INT64');
  3640. {$endif arm}
  3641. {$ifdef avr}
  3642. def_system_macro('CPUAVR');
  3643. def_system_macro('CPU16');
  3644. def_system_macro('FPC_CURRENCY_IS_INT64');
  3645. def_system_macro('FPC_COMP_IS_INT64');
  3646. {$endif avr}
  3647. {$ifdef jvm}
  3648. def_system_macro('CPUJVM');
  3649. def_system_macro('CPU32');
  3650. def_system_macro('FPC_CURRENCY_IS_INT64');
  3651. def_system_macro('FPC_COMP_IS_INT64');
  3652. {$endif jvm}
  3653. {$ifdef mipsel}
  3654. def_system_macro('CPUMIPS');
  3655. def_system_macro('CPUMIPS32');
  3656. def_system_macro('CPUMIPSEL');
  3657. def_system_macro('CPUMIPSEL32');
  3658. def_system_macro('CPU32');
  3659. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3660. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3661. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3662. def_system_macro('FPC_CURRENCY_IS_INT64');
  3663. def_system_macro('FPC_COMP_IS_INT64');
  3664. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3665. { On most systems, locals are accessed relative to base pointer,
  3666. but for MIPS cpu, they are accessed relative to stack pointer.
  3667. This needs adaptation for so low level routines,
  3668. like MethodPointerLocal and related objects unit functions. }
  3669. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3670. {$endif mipsel}
  3671. {$ifdef mipseb}
  3672. def_system_macro('CPUMIPS');
  3673. def_system_macro('CPUMIPS32');
  3674. def_system_macro('CPUMIPSEB');
  3675. def_system_macro('CPUMIPSEB32');
  3676. def_system_macro('CPU32');
  3677. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3678. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3679. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3680. def_system_macro('FPC_CURRENCY_IS_INT64');
  3681. def_system_macro('FPC_COMP_IS_INT64');
  3682. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3683. { See comment above for mipsel }
  3684. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3685. {$endif}
  3686. {$ifdef i8086}
  3687. def_system_macro('CPU86'); { Borland compatibility }
  3688. def_system_macro('CPU87'); { Borland compatibility }
  3689. def_system_macro('CPUI8086');
  3690. def_system_macro('CPU16');
  3691. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3692. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3693. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3694. case init_settings.x86memorymodel of
  3695. mm_tiny: def_system_macro('FPC_MM_TINY');
  3696. mm_small: def_system_macro('FPC_MM_SMALL');
  3697. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3698. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3699. mm_large: def_system_macro('FPC_MM_LARGE');
  3700. mm_huge: def_system_macro('FPC_MM_HUGE');
  3701. end;
  3702. {$endif i8086}
  3703. {$ifdef aarch64}
  3704. def_system_macro('CPUAARCH64');
  3705. def_system_macro('CPU64');
  3706. def_system_macro('FPC_CURRENCY_IS_INT64');
  3707. def_system_macro('FPC_COMP_IS_INT64');
  3708. {$endif aarch64}
  3709. {$ifdef riscv32}
  3710. def_system_macro('CPURISCV');
  3711. def_system_macro('CPURISCV32');
  3712. def_system_macro('CPU32');
  3713. def_system_macro('FPC_CURRENCY_IS_INT64');
  3714. def_system_macro('FPC_COMP_IS_INT64');
  3715. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3716. {$endif riscv32}
  3717. {$ifdef riscv64}
  3718. def_system_macro('CPURISCV');
  3719. def_system_macro('CPURISCV64');
  3720. def_system_macro('CPU64');
  3721. def_system_macro('FPC_CURRENCY_IS_INT64');
  3722. def_system_macro('FPC_COMP_IS_INT64');
  3723. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3724. {$endif riscv64}
  3725. {$ifdef xtensa}
  3726. def_system_macro('CPUXTENSA');
  3727. def_system_macro('CPU32');
  3728. def_system_macro('FPC_CURRENCY_IS_INT64');
  3729. def_system_macro('FPC_COMP_IS_INT64');
  3730. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3731. {$endif xtensa}
  3732. {$ifdef z80}
  3733. def_system_macro('CPUZ80');
  3734. def_system_macro('CPU16');
  3735. def_system_macro('FPC_CURRENCY_IS_INT64');
  3736. def_system_macro('FPC_COMP_IS_INT64');
  3737. {$endif z80}
  3738. {$if defined(cpu8bitalu)}
  3739. def_system_macro('CPUINT8');
  3740. {$elseif defined(cpu16bitalu)}
  3741. def_system_macro('CPUINT16');
  3742. {$elseif defined(cpu32bitalu)}
  3743. def_system_macro('CPUINT32');
  3744. {$elseif defined(cpu64bitalu)}
  3745. def_system_macro('CPUINT64');
  3746. {$endif defined(cpu64bitalu)}
  3747. {$if defined(avr)}
  3748. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3749. {$endif}
  3750. {$if defined(i8086) or defined(avr)}
  3751. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3752. {$endif i8086 or avr}
  3753. { abs(long) is handled internally on all CPUs }
  3754. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3755. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3756. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3757. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3758. def_system_macro('FPC_HAS_UNICODESTRING');
  3759. def_system_macro('FPC_RTTI_PACKSET1');
  3760. def_system_macro('FPC_HAS_CPSTRING');
  3761. {$ifdef x86_64}
  3762. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3763. {$endif x86_64}
  3764. def_system_macro('FPC_HAS_CEXTENDED');
  3765. def_system_macro('FPC_HAS_RESSTRINITS');
  3766. { these cpus have an inline rol/ror implementaion }
  3767. {$ifdef cpurox}
  3768. {$ifdef m68k}
  3769. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3770. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3771. {$else}
  3772. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3773. {$endif}
  3774. {$endif}
  3775. {$ifdef powerpc64}
  3776. def_system_macro('FPC_HAS_LWSYNC');
  3777. {$endif}
  3778. { currently, all supported CPUs have an internal sar implementation }
  3779. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3780. {$ifdef SUPPORT_GET_FRAME}
  3781. def_system_macro('INTERNAL_BACKTRACE');
  3782. {$endif SUPPORT_GET_FRAME}
  3783. def_system_macro('STR_CONCAT_PROCS');
  3784. {$warnings off}
  3785. if pocall_default = pocall_register then
  3786. def_system_macro('REGCALL');
  3787. {$warnings on}
  3788. end;
  3789. var
  3790. env: ansistring;
  3791. i : tfeature;
  3792. j : longint;
  3793. tmplist : TCmdStrList;
  3794. cmditem,
  3795. tmpcmditem : TCmdStrListItem;
  3796. cmdstr : TCmdStr;
  3797. {$if defined(cpucapabilities)}
  3798. cpuflag : tcpuflags;
  3799. {$endif defined(cpucapabilities)}
  3800. {$if defined(fpucapabilities)}
  3801. fpuflag : tfpuflags;
  3802. {$endif defined(fpucapabilities)}
  3803. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  3804. hs : string;
  3805. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  3806. begin
  3807. option:=coption.create;
  3808. disable_configfile:=false;
  3809. { Non-core target defines }
  3810. Option.TargetOptions(true);
  3811. { get default messagefile }
  3812. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3813. { default configfile can be specified on the commandline,
  3814. remove it first }
  3815. if (cmd<>'') and (cmd[1]='[') then
  3816. begin
  3817. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3818. Delete(cmd,1,pos(']',cmd));
  3819. end
  3820. else
  3821. ppccfg:='fpc.cfg';
  3822. { first pass reading of parameters, only -i -v -T etc.}
  3823. option.firstpass:=true;
  3824. if cmd<>'' then
  3825. option.parsecmd(cmd)
  3826. else
  3827. begin
  3828. option.read_parameters;
  3829. { Write only quickinfo }
  3830. if option.quickinfo<>'' then
  3831. option.writequickinfo;
  3832. end;
  3833. option.firstpass:=false;
  3834. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3835. Option.TargetOptions(true);
  3836. { target is set here, for wince the default app type is gui }
  3837. if target_info.system in systems_wince then
  3838. SetApptype(app_gui)
  3839. else
  3840. SetApptype(apptype);
  3841. { default defines }
  3842. def_system_macro(target_info.shortname);
  3843. def_system_macro('FPC');
  3844. def_system_macro('VER'+version_nr);
  3845. def_system_macro('VER'+version_nr+'_'+release_nr);
  3846. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3847. { Temporary defines, until things settle down }
  3848. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3849. def_system_macro('FPC_HAS_CONSTREF');
  3850. def_system_macro('FPC_STATICRIPFIXED');
  3851. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3852. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3853. def_system_macro('FPC_HAS_MEMBAR');
  3854. def_system_macro('FPC_SETBASE_USED');
  3855. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  3856. { don't remove this, it's also for fpdoc necessary (FK) }
  3857. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3858. { make cpu makros available when reading the config files the second time }
  3859. def_cpu_macros;
  3860. if tf_cld in target_info.flags then
  3861. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3862. InternalError(2013092801);
  3863. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3864. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3865. InternalError(2013092802);
  3866. { Use standard Android NDK prefixes when cross-compiling }
  3867. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  3868. case target_info.system of
  3869. system_arm_android:
  3870. utilsprefix:='arm-linux-androideabi-';
  3871. system_i386_android:
  3872. utilsprefix:='i686-linux-android-';
  3873. else
  3874. utilsprefix:=target_cpu_string + '-linux-android-';
  3875. end;
  3876. { Set up default value for the heap }
  3877. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  3878. begin
  3879. case target_info.system of
  3880. {$ifdef AVR}
  3881. system_avr_embedded:
  3882. if init_settings.controllertype=ct_avrsim then
  3883. heapsize:=8192
  3884. else
  3885. heapsize:=128;
  3886. {$endif AVR}
  3887. system_arm_freertos:
  3888. heapsize:=8192;
  3889. system_xtensa_freertos:
  3890. { keep default value }
  3891. ;
  3892. system_arm_embedded:
  3893. heapsize:=256;
  3894. system_mipsel_embedded:
  3895. heapsize:=256;
  3896. else
  3897. heapsize:=256;
  3898. end;
  3899. end;
  3900. { read configuration file }
  3901. if (not disable_configfile) and
  3902. (ppccfg<>'') then
  3903. read_configfile:=check_configfile(ppccfg,ppccfg)
  3904. else
  3905. read_configfile := false;
  3906. { Read commandline and configfile }
  3907. param_file:='';
  3908. { read configfile }
  3909. if read_configfile then
  3910. option.interpret_file(ppccfg);
  3911. { read parameters again to override config file }
  3912. if cmd<>'' then
  3913. option.parsecmd(cmd)
  3914. else
  3915. begin
  3916. { Write help pages if no parameters are passed }
  3917. if (paramcount=0) then
  3918. Option.WriteHelpPages;
  3919. option.read_parameters;
  3920. { Write only quickinfo }
  3921. if option.quickinfo<>'' then
  3922. option.writequickinfo;
  3923. end;
  3924. { check the compatibility of different options and adjust them if necessary
  3925. (and print possible errors)
  3926. }
  3927. option.checkoptionscompatibility;
  3928. { uses the CPUXXX-defines and target_info to determine whether the selected
  3929. target processor, if any, is supported }
  3930. Option.VerifyTargetProcessor;
  3931. { Stop if errors in options }
  3932. if ErrorCount>0 then
  3933. StopOptions(1);
  3934. { endian define }
  3935. case target_info.endian of
  3936. endian_little :
  3937. begin
  3938. def_system_macro('ENDIAN_LITTLE');
  3939. def_system_macro('FPC_LITTLE_ENDIAN');
  3940. end;
  3941. endian_big :
  3942. begin
  3943. def_system_macro('ENDIAN_BIG');
  3944. def_system_macro('FPC_BIG_ENDIAN');
  3945. end;
  3946. end;
  3947. { Write logo }
  3948. if option.ParaLogo then
  3949. option.writelogo;
  3950. { Check file to compile }
  3951. if param_file='' then
  3952. begin
  3953. Message(option_no_source_found);
  3954. StopOptions(1);
  3955. end;
  3956. {$ifndef Unix}
  3957. param_file:=FixFileName(param_file);
  3958. {$endif not unix}
  3959. inputfilepath:=ExtractFilePath(param_file);
  3960. inputfilename:=ExtractFileName(param_file);
  3961. if ExtractFileExt(inputfilename)='' then
  3962. begin
  3963. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3964. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3965. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3966. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3967. else if ((m_mac in current_settings.modeswitches) or
  3968. (tf_p_ext_support in target_info.flags))
  3969. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3970. inputfilename:=ChangeFileExt(inputfilename,pext);
  3971. end;
  3972. { Check output dir }
  3973. if (OutputExeDir<>'') and
  3974. not PathExists(OutputExeDir,false) then
  3975. begin
  3976. Message1(general_e_path_does_not_exist,OutputExeDir);
  3977. StopOptions(1);
  3978. end;
  3979. { Add paths specified with parameters to the searchpaths }
  3980. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3981. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3982. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3983. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3984. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3985. packagesearchpath.addlist(option.parapackagepath,true);
  3986. for j:=0 to option.parapackages.count-1 do
  3987. add_package(option.parapackages.NameOfIndex(j),true,true);
  3988. { add default namespaces }
  3989. tmplist:=TCmdStrList.Create;
  3990. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  3991. while assigned(cmditem) do
  3992. begin
  3993. { use a temporary list cause if ";" are involved we need to reverse the
  3994. order due to how TCmdStrList behaves }
  3995. cmdstr:=cmditem.str;
  3996. repeat
  3997. j:=Pos(';',cmdstr);
  3998. if j>0 then
  3999. begin
  4000. tmplist.insert(copy(cmdstr,1,j-1));
  4001. delete(cmdstr,1,j);
  4002. end
  4003. else
  4004. tmplist.insert(cmdstr);
  4005. until j=0;
  4006. tmpcmditem:=TCmdStrListItem(tmplist.First);
  4007. while assigned(tmpcmditem) do
  4008. begin
  4009. namespacelist.insert(tmpcmditem.Str);
  4010. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  4011. end;
  4012. tmplist.clear;
  4013. cmditem:=TCmdStrListItem(cmditem.Next);
  4014. end;
  4015. tmplist.Free;
  4016. { add unit environment and exepath to the unit search path }
  4017. if inputfilepath<>'' then
  4018. Unitsearchpath.AddPath(inputfilepath,true);
  4019. if not disable_configfile then
  4020. begin
  4021. env:=GetEnvironmentVariable(target_info.unit_env);
  4022. if env<>'' then
  4023. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  4024. end;
  4025. {$ifdef Unix}
  4026. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4027. if fpcdir='' then
  4028. begin
  4029. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  4030. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  4031. else
  4032. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  4033. end;
  4034. {$else unix}
  4035. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4036. if fpcdir='' then
  4037. begin
  4038. fpcdir:=ExePath+'../';
  4039. if not(PathExists(fpcdir+'units',true)) and
  4040. not(PathExists(fpcdir+'rtl',true)) then
  4041. fpcdir:=fpcdir+'../';
  4042. end;
  4043. {$endif unix}
  4044. { first try development RTL, else use the default installation path }
  4045. if not disable_configfile then
  4046. begin
  4047. if PathExists(FpcDir+'rtl',true) then
  4048. if (tf_use_8_3 in Source_Info.Flags) or
  4049. (tf_use_8_3 in Target_Info.Flags) then
  4050. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4051. else
  4052. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4053. else
  4054. if (tf_use_8_3 in Source_Info.Flags) or
  4055. (tf_use_8_3 in Target_Info.Flags) then
  4056. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4057. else
  4058. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4059. end;
  4060. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4061. Do not add it when linking on the target because then we can maybe already find
  4062. .o files that are not for the target }
  4063. if (ExePath<>cfileutl.GetCurrentDir) and
  4064. not(cs_link_on_target in init_settings.globalswitches) then
  4065. UnitSearchPath.AddPath(ExePath,false);
  4066. { Add unit dir to the object and library path }
  4067. objectsearchpath.AddList(unitsearchpath,false);
  4068. librarysearchpath.AddList(unitsearchpath,false);
  4069. {$ifdef llvm}
  4070. { default to clang }
  4071. if (option.paratargetasm=as_none) then
  4072. begin
  4073. option.paratargetasm:=as_clang_llvm;
  4074. end;
  4075. {$endif llvm}
  4076. { maybe override assembler }
  4077. if (option.paratargetasm<>as_none) then
  4078. begin
  4079. if not set_target_asm(option.paratargetasm) then
  4080. begin
  4081. if assigned(asminfos[option.paratargetasm]) then
  4082. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4083. else
  4084. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4085. set_target_asm(target_info.assemextern);
  4086. Message1(option_asm_forced,target_asm.idtxt);
  4087. end;
  4088. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4089. (option.paratargetdbg<>dbg_none) then
  4090. begin
  4091. Message1(option_confict_asm_debug,
  4092. asminfos[option.paratargetasm]^.idtxt);
  4093. option.paratargetdbg:=dbg_none;
  4094. exclude(init_settings.moduleswitches,cs_debuginfo);
  4095. end;
  4096. { Some assemblers, like clang, do not support
  4097. stabs debugging format, switch to dwardé in that case }
  4098. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4099. (option.paratargetdbg=dbg_stabs) then
  4100. begin
  4101. option.paratargetdbg:=dbg_dwarf2;
  4102. end;
  4103. end;
  4104. {TOptionheck a second time as we might have changed assembler just above }
  4105. option.checkoptionscompatibility;
  4106. { maybe override debug info format }
  4107. if (option.paratargetdbg<>dbg_none) then
  4108. if not set_target_dbg(option.paratargetdbg) then
  4109. Message(option_w_unsupported_debug_format);
  4110. { switch assembler if it's binary and we got -a on the cmdline }
  4111. if ((cs_asm_leave in init_settings.globalswitches) and
  4112. (af_outputbinary in target_asm.flags)) or
  4113. { if -s is passed, we shouldn't call the internal assembler }
  4114. (cs_asm_extern in init_settings.globalswitches) then
  4115. begin
  4116. Message(option_switch_bin_to_src_assembler);
  4117. {$ifdef llvm}
  4118. set_target_asm(as_clang_llvm);
  4119. {$else}
  4120. set_target_asm(target_info.assemextern);
  4121. {$endif}
  4122. { At least i8086 needs that for nasm and -CX
  4123. which is incompatible with internal linker }
  4124. option.checkoptionscompatibility;
  4125. end;
  4126. { Force use of external linker if there is no
  4127. internal linker or the linking is skipped }
  4128. if not(cs_link_extern in init_settings.globalswitches) and
  4129. ((target_info.link=ld_none) or
  4130. (cs_link_nolink in init_settings.globalswitches)) then
  4131. begin
  4132. include(init_settings.globalswitches,cs_link_extern);
  4133. end;
  4134. { turn off stripping if compiling with debuginfo or profile }
  4135. if (
  4136. (cs_debuginfo in init_settings.moduleswitches) or
  4137. (cs_profile in init_settings.moduleswitches)
  4138. ) and
  4139. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4140. exclude(init_settings.globalswitches,cs_link_strip);
  4141. { choose a reasonable tls model }
  4142. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4143. begin
  4144. if cs_create_pic in init_settings.moduleswitches then
  4145. init_settings.tlsmodel:=tlsm_global_dynamic
  4146. else
  4147. init_settings.tlsmodel:=tlsm_local_exec;
  4148. end;
  4149. { set Mac OS X version default macros if not specified explicitly }
  4150. option.MaybeSetDefaultMacVersionMacro;
  4151. {$ifdef cpufpemu}
  4152. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4153. if fpu type not explicitly set }
  4154. if not(option.FPUSetExplicitly) and
  4155. ((target_info.system in [system_arm_wince,system_arm_gba,
  4156. system_m68k_amiga,system_m68k_atari,
  4157. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4158. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4159. system_z80_embedded,system_z80_zxspectrum])
  4160. {$ifdef arm}
  4161. or (target_info.abi=abi_eabi)
  4162. {$endif arm}
  4163. )
  4164. or (init_settings.fputype=fpu_soft)
  4165. then
  4166. begin
  4167. include(init_settings.moduleswitches,cs_fp_emulation);
  4168. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4169. init_settings.fputype:=fpu_soft;
  4170. end;
  4171. {$endif cpufpemu}
  4172. {$ifdef i386}
  4173. if target_info.system in systems_i386_default_486 then
  4174. begin
  4175. { Avoid use of MMX/CMOVcc instructions on older systems.
  4176. Some systems might not handle these instructions correctly,
  4177. Used emulators might also be problematic. PM }
  4178. if not option.CPUSetExplicitly then
  4179. init_settings.cputype:=cpu_486;
  4180. end;
  4181. case target_info.system of
  4182. system_i386_android:
  4183. begin
  4184. { set default cpu type to PentiumM for Android unless specified otherwise }
  4185. if not option.CPUSetExplicitly then
  4186. init_settings.cputype:=cpu_PentiumM;
  4187. if not option.OptCPUSetExplicitly then
  4188. init_settings.optimizecputype:=cpu_PentiumM;
  4189. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4190. if not option.FPUSetExplicitly then
  4191. init_settings.fputype:=fpu_ssse3;
  4192. end;
  4193. else
  4194. ;
  4195. end;
  4196. {$endif i386}
  4197. {$ifdef xtensa}
  4198. { xtensa-linux target does not support controller setting option -Wp }
  4199. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4200. begin
  4201. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4202. if (init_settings.fputype=fpu_soft) then
  4203. include(init_settings.moduleswitches,cs_fp_emulation);
  4204. end;
  4205. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4206. init_settings.cputype:=cpu_lx6;
  4207. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4208. begin
  4209. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4210. target_info.abi:=abi_xtensa_windowed
  4211. else
  4212. target_info.abi:=abi_xtensa_call0;
  4213. end;
  4214. {$endif xtensa}
  4215. {$ifdef arm}
  4216. case target_info.system of
  4217. system_arm_ios:
  4218. begin
  4219. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4220. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4221. }
  4222. if not option.CPUSetExplicitly then
  4223. init_settings.cputype:=cpu_armv7;
  4224. if not option.OptCPUSetExplicitly then
  4225. init_settings.optimizecputype:=cpu_armv7;
  4226. if not option.FPUSetExplicitly then
  4227. init_settings.fputype:=fpu_vfpv3;
  4228. end;
  4229. system_arm_android:
  4230. begin
  4231. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4232. if not option.CPUSetExplicitly then
  4233. init_settings.cputype:=cpu_armv5t;
  4234. if not option.OptCPUSetExplicitly then
  4235. init_settings.optimizecputype:=cpu_armv5t;
  4236. end;
  4237. else
  4238. ;
  4239. end;
  4240. { set ABI defaults }
  4241. case target_info.abi of
  4242. abi_eabihf:
  4243. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4244. begin
  4245. {$ifdef CPUARMV6}
  4246. { if the compiler is built for armv6, then
  4247. inherit this setting, e.g. Raspian is armhf but
  4248. only armv6, this makes rebuilds of the compiler
  4249. easier }
  4250. if not option.CPUSetExplicitly then
  4251. init_settings.cputype:=cpu_armv6;
  4252. if not option.OptCPUSetExplicitly then
  4253. init_settings.optimizecputype:=cpu_armv6;
  4254. {$else CPUARMV6}
  4255. if not option.CPUSetExplicitly then
  4256. init_settings.cputype:=cpu_armv7a;
  4257. if not option.OptCPUSetExplicitly then
  4258. init_settings.optimizecputype:=cpu_armv7a;
  4259. {$endif CPUARMV6}
  4260. { Set FPU type }
  4261. if not(option.FPUSetExplicitly) then
  4262. begin
  4263. if init_settings.cputype < cpu_armv7 then
  4264. init_settings.fputype:=fpu_vfpv2
  4265. else
  4266. init_settings.fputype:=fpu_vfpv3_d16;
  4267. end
  4268. else
  4269. begin
  4270. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4271. or (target_info.system = system_arm_ios) then
  4272. begin
  4273. Message(option_illegal_fpu_eabihf);
  4274. StopOptions(1);
  4275. end;
  4276. end;
  4277. end;
  4278. abi_eabi:
  4279. begin
  4280. if target_info.system=system_arm_linux then
  4281. begin
  4282. { this is what Debian uses }
  4283. if not option.CPUSetExplicitly then
  4284. init_settings.cputype:=cpu_armv4t;
  4285. if not option.OptCPUSetExplicitly then
  4286. init_settings.optimizecputype:=cpu_armv4t;
  4287. if not(option.FPUSetExplicitly) then
  4288. init_settings.fputype:=fpu_soft;
  4289. end;
  4290. end;
  4291. else
  4292. ;
  4293. end;
  4294. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4295. begin
  4296. def_system_macro('CPUTHUMB');
  4297. if not option.FPUSetExplicitly then
  4298. init_settings.fputype:=fpu_soft;
  4299. if not(init_settings.fputype in [fpu_none,fpu_soft,fpu_libgcc]) then
  4300. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],'Thumb');
  4301. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4302. target_info.llvmdatalayout:='e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:32-n32-S64';
  4303. {$else FPC_ARMAL or FPC_ARMHF}
  4304. if target_info.endian=endian_little then
  4305. target_info.llvmdatalayout:='e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32';
  4306. {$endif FPC_ARMAL or FPC_ARMHF}
  4307. end;
  4308. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4309. def_system_macro('CPUTHUMB2');
  4310. {$endif arm}
  4311. {$if defined(riscv32) or defined(riscv64)}
  4312. { RISC-V defaults }
  4313. if (target_info.abi = abi_riscv_hf) then
  4314. begin
  4315. {$ifdef riscv32}
  4316. if not option.CPUSetExplicitly then
  4317. init_settings.cputype:=cpu_rv32ima;
  4318. if not option.OptCPUSetExplicitly then
  4319. init_settings.optimizecputype:=cpu_rv32ima;
  4320. {$else}
  4321. if not option.CPUSetExplicitly then
  4322. init_settings.cputype:=cpu_rv64imac;
  4323. if not option.OptCPUSetExplicitly then
  4324. init_settings.optimizecputype:=cpu_rv64imac;
  4325. {$endif}
  4326. { Set FPU type }
  4327. if not(option.FPUSetExplicitly) then
  4328. init_settings.fputype:=fpu_fd
  4329. else
  4330. begin
  4331. if not (init_settings.fputype in [fpu_fd]) then
  4332. begin
  4333. Message(option_illegal_fpu_eabihf);
  4334. StopOptions(1);
  4335. end;
  4336. end;
  4337. end;
  4338. {$endif defined(riscv32) or defined(riscv64)}
  4339. {$ifdef jvm}
  4340. { set default CPU type to Dalvik when targeting Android }
  4341. if target_info.system=system_jvm_android32 then
  4342. begin
  4343. if not option.CPUSetExplicitly then
  4344. init_settings.cputype:=cpu_dalvik;
  4345. end;
  4346. {$endif jvm}
  4347. {$ifdef llvm}
  4348. { standard extension for llvm bitcode files }
  4349. target_info.asmext:='.ll';
  4350. { don't generate dwarf cfi, llvm will do that }
  4351. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4352. {$endif llvm}
  4353. {$ifdef mipsel}
  4354. case target_info.system of
  4355. system_mipsel_android:
  4356. begin
  4357. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4358. if not option.CPUSetExplicitly then
  4359. init_settings.cputype:=cpu_mips32;
  4360. if not option.OptCPUSetExplicitly then
  4361. init_settings.optimizecputype:=cpu_mips32;
  4362. if not option.FPUSetExplicitly then
  4363. init_settings.fputype:=fpu_mips2;
  4364. end;
  4365. system_mipsel_embedded:
  4366. begin
  4367. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4368. if not option.CPUSetExplicitly then
  4369. init_settings.cputype:=cpu_pic32mx;
  4370. if not option.OptCPUSetExplicitly then
  4371. init_settings.optimizecputype:=cpu_pic32mx;
  4372. if not option.FPUSetExplicitly then
  4373. init_settings.fputype:=fpu_soft;
  4374. end;
  4375. else
  4376. ;
  4377. end;
  4378. {$endif mipsel}
  4379. {$ifdef m68k}
  4380. if init_settings.cputype in cpu_coldfire then
  4381. def_system_macro('CPUCOLDFIRE');
  4382. case target_info.system of
  4383. system_m68k_linux,
  4384. system_m68k_netbsd:
  4385. begin
  4386. if not (option.FPUSetExplicitly) and
  4387. not (init_settings.cputype in cpu_coldfire) then
  4388. begin
  4389. { enable HW FPU for UNIX by default, but only for
  4390. original 68k, not Coldfire }
  4391. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4392. init_settings.fputype:=fpu_68881;
  4393. end;
  4394. end;
  4395. system_m68k_sinclairql:
  4396. begin
  4397. if not option.CPUSetExplicitly then
  4398. init_settings.cputype:=cpu_mc68000;
  4399. end;
  4400. system_m68k_palmos:
  4401. begin
  4402. if not option.CPUSetExplicitly then
  4403. init_settings.cputype:=cpu_mc68000;
  4404. if not (option.FPUSetExplicitly) then
  4405. begin
  4406. { No FPU for PalmOS by default }
  4407. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4408. init_settings.fputype:=fpu_none;
  4409. end;
  4410. end;
  4411. else
  4412. ;
  4413. end;
  4414. {$endif m68k}
  4415. { now we can define cpu and fpu type }
  4416. def_cpu_macros;
  4417. { Use init_settings cpu type for asm cpu type,
  4418. if asmcputype is cpu_none,
  4419. at least as long as there is no explicit
  4420. option to set it on command line PM }
  4421. if init_settings.asmcputype = cpu_none then
  4422. init_settings.asmcputype:=init_settings.cputype;
  4423. {$ifdef llvm}
  4424. def_system_macro('CPULLVM');
  4425. {$endif llvm}
  4426. {$if defined(cpucapabilities)}
  4427. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4428. begin
  4429. str(cpuflag,hs);
  4430. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4431. def_system_macro(hs)
  4432. else
  4433. undef_system_macro(hs);
  4434. end;
  4435. {$endif defined(cpucapabilities)}
  4436. {$if defined(fpucapabilities)}
  4437. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4438. begin
  4439. str(fpuflag,hs);
  4440. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4441. def_system_macro(hs)
  4442. else
  4443. undef_system_macro(hs);
  4444. end;
  4445. {$endif defined(fpucapabilities)}
  4446. if init_settings.fputype<>fpu_none then
  4447. begin
  4448. {$if defined(i386) or defined(i8086)}
  4449. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4450. {$endif}
  4451. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4452. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4453. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4454. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4455. {$endif}
  4456. {$if defined(m68k)}
  4457. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4458. {$endif}
  4459. {$ifdef x86_64}
  4460. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4461. { normally, win64 doesn't support the legacy fpu }
  4462. if target_info.system=system_x86_64_win64 then
  4463. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4464. else
  4465. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4466. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4467. {$endif}
  4468. end;
  4469. { Enable now for testing }
  4470. {$ifndef DISABLE_TLS_DIRECTORY}
  4471. if target_info.system in systems_windows then
  4472. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4473. {$endif not DISABLE_TLS_DIRECTORY}
  4474. {$ifndef DISABLE_WIN64_SEH}
  4475. if target_info.system=system_x86_64_win64 then
  4476. def_system_macro('FPC_USE_WIN64_SEH');
  4477. {$endif DISABLE_WIN64_SEH}
  4478. {$ifndef DISABLE_WIN32_SEH}
  4479. if target_info.system=system_i386_win32 then
  4480. def_system_macro('FPC_USE_WIN32_SEH');
  4481. {$endif not DISABLE_WIN32_SEH}
  4482. {$ifdef ARM}
  4483. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4484. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4485. not(cs_fp_emulation in init_settings.moduleswitches) then
  4486. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4487. {$endif ARM}
  4488. { inline bsf/bsr implementation }
  4489. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4490. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4491. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4492. {$endif}
  4493. { hardware FMA support }
  4494. {$if defined(i386) or defined(x86_64)}
  4495. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  4496. begin
  4497. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4498. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4499. end;
  4500. {$endif defined(i386) or defined(x86_64)}
  4501. {$if defined(arm)}
  4502. { it is determined during system unit compilation if clz is used for bsf or not,
  4503. this is not perfect but the current implementation bsf/bsr does not allow another
  4504. solution }
  4505. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4506. ((init_settings.instructionset=is_arm) or
  4507. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4508. begin
  4509. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4510. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4511. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4512. end;
  4513. {$endif}
  4514. {$if defined(xtensa)}
  4515. { it is determined during system unit compilation if nsau is used for bsr or not,
  4516. this is not perfect but the current implementation bsf/bsr does not allow another
  4517. solution }
  4518. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  4519. begin
  4520. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4521. end;
  4522. {$endif}
  4523. {$if defined(powerpc64)}
  4524. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4525. big endian (unless specified otherwise). As the gcc man page says:
  4526. "Overriding the default ABI requires special system support and is
  4527. likely to fail in spectacular ways" }
  4528. if not option.ABISetExplicitly then
  4529. begin
  4530. if (target_info.abi=abi_powerpc_sysv) and
  4531. (target_info.endian=endian_little) then
  4532. target_info.abi:=abi_powerpc_elfv2
  4533. else
  4534. if (target_info.abi=abi_powerpc_elfv2) and
  4535. (target_info.endian=endian_big) then
  4536. target_info.abi:=abi_powerpc_sysv
  4537. end;
  4538. {$endif}
  4539. {$if defined(powerpc) or defined(powerpc64)}
  4540. { define _CALL_ELF symbol like gcc }
  4541. case target_info.abi of
  4542. abi_powerpc_sysv:
  4543. set_system_compvar('_CALL_ELF','1');
  4544. abi_powerpc_elfv2:
  4545. set_system_compvar('_CALL_ELF','2');
  4546. else
  4547. ;
  4548. end;
  4549. {$endif}
  4550. { Section smartlinking conflicts with import sections on Windows }
  4551. if GenerateImportSection and
  4552. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  4553. exclude(target_info.flags,tf_smartlink_sections);
  4554. if not option.LinkTypeSetExplicitly then
  4555. set_default_link_type;
  4556. { Default alignment settings,
  4557. 1. load the defaults for the target
  4558. 2. override with generic optimizer setting (little size)
  4559. 3. override with the user specified -Oa }
  4560. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4561. if (cs_opt_size in init_settings.optimizerswitches) then
  4562. begin
  4563. init_settings.alignment.procalign:=1;
  4564. init_settings.alignment.jumpalign:=1;
  4565. init_settings.alignment.coalescealign:=1;
  4566. init_settings.alignment.loopalign:=1;
  4567. {$ifdef x86}
  4568. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4569. all processors except x86 are really hurt by this or might even crash }
  4570. init_settings.alignment.constalignmax:=1;
  4571. {$endif x86}
  4572. end;
  4573. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4574. set_system_macro('FPC_VERSION',version_nr);
  4575. set_system_macro('FPC_RELEASE',release_nr);
  4576. set_system_macro('FPC_PATCH',patch_nr);
  4577. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4578. if target_info.system in systems_indirect_entry_information then
  4579. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4580. if not (tf_winlikewidestring in target_info.flags) then
  4581. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4582. if tf_supports_packages in target_info.flags then
  4583. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4584. if target_info.system in systems_indirect_var_imports then
  4585. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4586. if cs_compilesystem in init_settings.moduleswitches then
  4587. for i:=low(tfeature) to high(tfeature) do
  4588. if i in features then
  4589. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4590. {$push}
  4591. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4592. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  4593. (init_settings.controllertype<>ct_none) then
  4594. begin
  4595. with embedded_controllers[init_settings.controllertype] do
  4596. begin
  4597. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4598. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4599. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4600. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4601. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4602. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4603. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4604. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4605. end;
  4606. end;
  4607. {$pop}
  4608. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4609. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4610. option.free;
  4611. Option:=nil;
  4612. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  4613. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4614. if (tf_safecall_clearstack in target_info.flags) then
  4615. begin
  4616. include (cdecl_pocalls, pocall_safecall);
  4617. include (clearstack_pocalls, pocall_safecall)
  4618. end;
  4619. end;
  4620. initialization
  4621. coption:=toption;
  4622. finalization
  4623. if assigned(option) then
  4624. option.free;
  4625. end.