github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/spec/target/pkgconfig.go (about)

     1  package target
     2  
     3  import (
     4  	"github.com/metux/go-metabuild/util"
     5  	"github.com/metux/go-metabuild/util/compiler"
     6  )
     7  
     8  // pkgconfig settings
     9  const (
    10  	// importing by pkgconf from within a target
    11  	KeyPkgconfImport = Key("pkgconf/import")
    12  
    13  	// pkgconf descriptor attributes
    14  	KeyPkgName         = Key("name")
    15  	KeyPkgVersion      = Key("version")
    16  	KeyPkgDescription  = Key("description")
    17  	KeyPkgPrefix       = Key("prefix")
    18  	KeyPkgExecPrefix   = Key("exec-prefix")
    19  	KeyPkgLibdir       = Key("libdir")
    20  	KeyPkgIncludedir   = Key("includedir")
    21  	KeyPkgSharedLibdir = Key("sharedlibdir")
    22  	KeyPkgArchive      = Key("archive")
    23  	KeyPkgLibname      = Key("libname")
    24  	KeyPkgPackage      = Key("package")
    25  )
    26  
    27  func (o TargetObject) tryImport(id string) compiler.PkgConfigInfo {
    28  	forBuild := o.ForBuild()
    29  	pkg := o.BuildConf.PkgConfig(forBuild, id)
    30  	if pkg.Valid() {
    31  		return pkg
    32  	}
    33  	return pkg
    34  }
    35  
    36  func (o TargetObject) PkgImports() []compiler.PkgConfigInfo {
    37  	imports := o.FeaturedStrList(KeyPkgconfImport)
    38  	pkgs := make([]compiler.PkgConfigInfo, len(imports))
    39  	for idx, i := range imports {
    40  		pkgs[idx] = o.tryImport(i)
    41  		if !pkgs[idx].Valid() {
    42  			util.Panicf("config error: missing pkg-config check for: %s", pkgs[idx].Id)
    43  		}
    44  	}
    45  	return pkgs
    46  }