@@ -4496,3 +4496,36 @@ func TestBadCgoDirectives(t *testing.T) {
44964496 tg .run ("build" , "-n" , "x" )
44974497 tg .grepStderr ("-D@foo" , "did not find -D@foo in commands" )
44984498}
4499+
4500+ func TestTwoPkgConfigs (t * testing.T ) {
4501+ if ! canCgo {
4502+ t .Skip ("no cgo" )
4503+ }
4504+ if runtime .GOOS == "windows" || runtime .GOOS == "plan9" {
4505+ t .Skipf ("no shell scripts on %s" , runtime .GOOS )
4506+ }
4507+ tg := testgo (t )
4508+ defer tg .cleanup ()
4509+ tg .parallel ()
4510+ tg .tempFile ("src/x/a.go" , `package x
4511+ // #cgo pkg-config: --static a
4512+ import "C"
4513+ ` )
4514+ tg .tempFile ("src/x/b.go" , `package x
4515+ // #cgo pkg-config: --static a
4516+ import "C"
4517+ ` )
4518+ tg .tempFile ("pkg-config.sh" , `#!/bin/sh
4519+ echo $* >>` + tg .path ("pkg-config.out" ))
4520+ tg .must (os .Chmod (tg .path ("pkg-config.sh" ), 0755 ))
4521+ tg .setenv ("GOPATH" , tg .path ("." ))
4522+ tg .setenv ("PKG_CONFIG" , tg .path ("pkg-config.sh" ))
4523+ tg .run ("build" , "x" )
4524+ out , err := ioutil .ReadFile (tg .path ("pkg-config.out" ))
4525+ tg .must (err )
4526+ out = bytes .TrimSpace (out )
4527+ want := "--cflags --static --static -- a a\n --libs --static --static -- a a"
4528+ if ! bytes .Equal (out , []byte (want )) {
4529+ t .Errorf ("got %q want %q" , out , want )
4530+ }
4531+ }
0 commit comments