github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/spec/buildconf/compiler.go (about) 1 package buildconf 2 3 import ( 4 "github.com/metux/go-metabuild/util/compiler" 5 "github.com/metux/go-metabuild/util/specobj" 6 ) 7 8 const ( 9 KeyForLang = Key("lang") 10 ) 11 12 // Suffixes for per-language compiler attributes 13 const ( 14 KeyCompilerTarget = Key("target") 15 KeyCompilerArch = Key("arch") 16 KeyCompilerVendor = Key("vendor") 17 KeyCompilerKernel = Key("kernel") 18 KeyCompilerSystem = Key("system") 19 KeyCompilerCommand = Key("command") 20 KeyCompilerArchiver = Key("archiver") 21 KeyCompilerId = Key("id") 22 KeyCompilerCrossForHost = Key("cross-for-host") 23 KeyCompilerCrossForBuild = Key("cross-for-build") 24 KeyCompilerCrossPrefix = Key("cross-prefix") 25 KeyCompilerSysroot = Key("sysroot") 26 ) 27 28 func (bc BuildConf) CompilerSub(build bool, lang string) specobj.SpecObj { 29 return bc.SubForBuild(build, KeyForLang.AppendStr(lang)) 30 } 31 32 // Store CompilerInfo in BuildConfig 33 // build - true if it's the compiler for the build system (different from host on crosscompile) 34 func (bc BuildConf) SetCompilerInfo(build bool, ci compiler.CompilerInfo) { 35 sub := bc.CompilerSub(build, ci.Language) 36 sub.EntryPutBool(KeyCompilerCrossForHost, ci.CrossForHost) 37 sub.EntryPutBool(KeyCompilerCrossForBuild, ci.CrossForBuild) 38 sub.EntryPutStr(KeyCompilerCrossPrefix, ci.CrossPrefix) 39 sub.EntryPutStrList(KeyCompilerArchiver, ci.Archiver) 40 sub.EntryPutStr(KeyCompilerTarget, ci.Machine.String()) 41 sub.EntryPutStr(KeyCompilerArch, ci.Machine.Arch) 42 sub.EntryPutStr(KeyCompilerVendor, ci.Machine.Vendor) 43 sub.EntryPutStr(KeyCompilerKernel, ci.Machine.Kernel) 44 sub.EntryPutStr(KeyCompilerSystem, ci.Machine.System) 45 sub.EntryPutStr(KeyCompilerId, ci.Id) 46 sub.EntryPutStr(KeyCompilerSysroot, ci.Sysroot) 47 sub.EntryPutStrList(KeyCompilerCommand, ci.Command) 48 } 49 50 func (bc BuildConf) CompilerInfo(build bool, lang string) compiler.CompilerInfo { 51 sub := bc.CompilerSub(build, lang) 52 return compiler.CompilerInfo{ 53 Language: lang, 54 CrossForHost: sub.EntryBoolDef(KeyCompilerCrossForHost, false), 55 CrossForBuild: sub.EntryBoolDef(KeyCompilerCrossForBuild, false), 56 CrossPrefix: sub.EntryStr(KeyCompilerCrossPrefix), 57 Machine: compiler.ParseMachine(sub.EntryStr(KeyCompilerTarget)), 58 Command: sub.EntryStrList(KeyCompilerCommand), 59 Archiver: sub.EntryStrList(KeyCompilerArchiver), 60 Id: sub.EntryStr(KeyCompilerId), 61 Sysroot: sub.EntryStr(KeyCompilerSysroot), 62 } 63 }