options.pas 159 KB

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