github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/util/compiler/base/compilerinfo.go (about) 1 package base 2 3 import ( 4 "fmt" 5 6 "github.com/metux/go-metabuild/util" 7 cmdrun "github.com/metux/go-metabuild/util/cmd" 8 ) 9 10 const ( 11 LangC = "C" 12 LangCxx = "C++" 13 ) 14 15 const ( 16 CompilerGCC = "gcc" 17 CompilerClang = "clang" 18 ) 19 20 const ( 21 ErrNoUsableCompiler = util.Error("CC no usable compiler") 22 ErrCrossMissingCC = util.Error("when crosscompiling, either HOST_CC must be set or CROSS_COMPILE set to target toolchain prefix") 23 ErrCrossMissingCXX = util.Error("when crosscompiling, either HOST_CXX must be set or CROSS_COMPILE set to target toolchain prefix") 24 ) 25 26 type CompilerInfo struct { 27 Language string 28 Id string 29 Command []string 30 Archiver []string 31 Linker []string 32 Version string 33 Machine Machine 34 CrossForHost bool // this is crosscompiler for foreign target 35 CrossForBuild bool // on crosscompile this is the host compiler 36 Sysroot string 37 CrossPrefix string 38 } 39 40 func (ci CompilerInfo) Found() bool { 41 return ci.Id != "" 42 } 43 44 func (ci CompilerInfo) String() string { 45 return fmt.Sprintf( 46 "lang=%s: ID=%s VER=\"%s\" MACH=\"%s\" CMD=%s", 47 ci.Language, 48 ci.Id, 49 ci.Version, 50 ci.Machine, 51 ci.Command) 52 } 53 54 func (ci *CompilerInfo) RunCatchOut(param string) string { 55 out, _ := cmdrun.RunOutOne(append(ci.Command, param), false) 56 return out 57 }