From 8c2195d5ce3d80d6c693002d337481194070d209 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 22 Jun 2013 17:20:32 -0700 Subject: [PATCH] On Mac, automatically find the brew sqlite3. Change-Id: Iafa852a414d4f87553bd51ee75fe077b0f5cea1d --- make.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/make.go b/make.go index f2a3baf59..ab702357a 100644 --- a/make.go +++ b/make.go @@ -96,8 +96,7 @@ func main() { log.Printf("SQLite not found. Either install it, or run make.go with --sqlite=false") switch runtime.GOOS { case "darwin": - // TODO: search for /usr/local/Cellar/sqlite/*/lib/pkgconfig for the user. - log.Printf("On OS X, run 'brew install sqlite3' and set PKG_CONFIG_PATH=/usr/local/Cellar/sqlite/3.7.17/lib/pkgconfig/") + log.Printf("On OS X, run 'brew install sqlite3' and 'brew install pkg-config'") case "linux": log.Printf("On Linux, run 'sudo apt-get install libsqlite3-dev' or equivalent.") case "windows": @@ -426,7 +425,15 @@ func haveSQLite() bool { if err != nil { log.Fatalf("No pkg-config found. Can't determine whether sqlite3 is available, and where.") } - out, err := exec.Command("pkg-config", "--libs", "sqlite3").Output() + cmd := exec.Command("pkg-config", "--libs", "sqlite3") + if runtime.GOOS == "darwin" && os.Getenv("PKG_CONFIG_PATH") == "" { + matches, err := filepath.Glob("/usr/local/Cellar/sqlite/*/lib/pkgconfig/sqlite3.pc") + if err == nil && len(matches) > 0 { + cmd.Env = append(os.Environ(), "PKG_CONFIG_PATH=" + filepath.Dir(matches[0])) + } + } + + out, err := cmd.Output() if err != nil && err.Error() == "exit status 1" { // This is sloppy (comparing against a string), but // doing it correctly requires using multiple *.go