options.pas 161 KB

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