github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/engine/autoconf/features.go (about) 1 package autoconf 2 3 import ( 4 "os" 5 "strings" 6 7 "github.com/metux/go-metabuild/spec" 8 "github.com/metux/go-metabuild/spec/features" 9 "github.com/metux/go-metabuild/spec/global" 10 "github.com/metux/go-metabuild/util" 11 ) 12 13 type Key = spec.Key 14 15 // FIXME: move this out to frontend code 16 // FIXME: move env lookup into FeatureMap, but pass in env [] 17 func featuresFromEnv(cf global.Global, fm features.FeatureMap) { 18 for _, f := range fm.All() { 19 fup := strings.ToUpper(string(f.Id)) 20 if v := os.Getenv("ENABLE_" + fup); v != "" { 21 f.SetOn() 22 } 23 if v := os.Getenv("DISABLE_" + fup); v != "" { 24 f.SetOff() 25 } 26 if v := os.Getenv("WITH_" + fup); v != "" { 27 f.Set(v) 28 } 29 } 30 } 31 32 func featuresProcess(cf global.Global, fm features.FeatureMap) error { 33 bc := cf.BuildConf() 34 35 subBuild := bc.SubForBuild(true, "flags") 36 subHost := bc.SubForBuild(false, "flags") 37 38 for _, f := range fm.All() { 39 flags := f.FlagsOn() 40 for _, k := range flags.Keys() { 41 data := flags.EntryStrList(k) 42 subBuild.EntryStrListAppendList(k, data) 43 subHost.EntryStrListAppendList(k, data) 44 } 45 if f.ValueYN() == "y" { 46 req := f.PkgconfRequire() 47 for _, pkg := range req { 48 if !bc.PkgConfig(true, pkg).Valid() && !bc.PkgConfig(false, pkg).Valid() { 49 return util.ConfigError("missing package import \"%s\" for feature \"%s\"", pkg, f.Id) 50 } 51 } 52 } 53 } 54 return nil 55 } 56 57 func RunConfigureFeatures(cf global.Global) error { 58 fmap := cf.GetFeatureMap() 59 featuresFromEnv(cf, fmap) 60 return featuresProcess(cf, fmap) 61 }