options.pas 159 KB

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