Merge pull request #371 from libgit2/static-dynamic

Allow building statically via the "static" build tag
diff --git a/.travis.yml b/.travis.yml
index d9130bc..f3b8b46 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,13 @@
 language: go
 
-sudo: required
-
-install: ./script/install-libgit2.sh
-
 go:
   - 1.5
   - 1.6
   - 1.7
   - tip
 
+script: make test-static
+
 matrix:
   allow_failures:
     - go: tip
diff --git a/Makefile b/Makefile
index 39fc558..b2399f8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,21 @@
 default: test
 
-build-libgit2:
-	./script/build-libgit2-static.sh
-
 test: build-libgit2
 	go run script/check-MakeGitError-thread-lock.go
 	go test ./...
 
 install: build-libgit2
 	go install ./...
+
+build-libgit2:
+	./script/build-libgit2-static.sh
+
+static: build-libgit2
+	go run script/check-MakeGitError-thread-lock.go
+	go test --tags "static" ./...
+
+install-static: build-libgit2
+	go install --tags "static" ./...
+
+test-static: build-libgit2
+	go test --tags "static" ./...
diff --git a/git.go b/git.go
index c032b0a..5181b8b 100644
--- a/git.go
+++ b/git.go
@@ -1,17 +1,8 @@
 package git
 
 /*
-#cgo CFLAGS: -I${SRCDIR}/vendor/libgit2/include
-#cgo LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2
-#cgo windows LDFLAGS: -lwinhttp
-#cgo !windows pkg-config: --static ${SRCDIR}/vendor/libgit2/build/libgit2.pc
 #include <git2.h>
 #include <git2/sys/openssl.h>
-
-#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 25
-# error "Invalid libgit2 version; this git2go supports libgit2 v0.25"
-#endif
-
 */
 import "C"
 import (
diff --git a/git_dynamic.go b/git_dynamic.go
new file mode 100644
index 0000000..f89d509
--- /dev/null
+++ b/git_dynamic.go
@@ -0,0 +1,14 @@
+// +build !static
+
+package git
+
+/*
+#include <git2.h>
+#cgo pkg-config: libgit2
+
+#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 25
+# error "Invalid libgit2 version; this git2go supports libgit2 v0.25"
+#endif
+
+*/
+import "C"
diff --git a/git_static.go b/git_static.go
new file mode 100644
index 0000000..d0acb3a
--- /dev/null
+++ b/git_static.go
@@ -0,0 +1,17 @@
+// +build static
+
+package git
+
+/*
+#cgo CFLAGS: -I${SRCDIR}/vendor/libgit2/include
+#cgo LDFLAGS: -L${SRCDIR}/vendor/libgit2/build/ -lgit2
+#cgo windows LDFLAGS: -lwinhttp
+#cgo !windows pkg-config: --static ${SRCDIR}/vendor/libgit2/build/libgit2.pc
+#include <git2.h>
+
+#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 25
+# error "Invalid libgit2 version; this git2go supports libgit2 v0.25"
+#endif
+
+*/
+import "C"