1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 // pkgConfig runs pkg-config with the specified arguments and returns the flags it prints.
16 func pkgConfig(mode string, pkgs []string) (flags []string, err error) {
17 cmd := exec.Command("pkg-config", append([]string{mode}, pkgs...)...)
18 out, err := cmd.CombinedOutput()
20 s := fmt.Sprintf("%s failed: %v", strings.Join(cmd.Args, " "), err)
22 s = fmt.Sprintf("%s: %s", s, out)
24 return nil, errors.New(s)
27 flags = strings.Fields(string(out))
32 // pkgConfigFlags calls pkg-config if needed and returns the cflags
33 // needed to build the package.
34 func pkgConfigFlags(p *build.Package) (cflags []string, err error) {
35 if len(p.CgoPkgConfig) == 0 {
38 return pkgConfig("--cflags", p.CgoPkgConfig)