diff --git a/Makefile b/Makefile index 65e612c..901e00e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ LDFLAGS = -ldflags "-X main.gitSHA=$(shell git rev-parse HEAD)" +OS := $(shell uname) + build: clean go build $(LDFLAGS) -o simple-httpd @@ -13,5 +15,16 @@ clean: go clean rm -f simple-httpd -install: clean - go install +install: clean release +ifeq ($(OS),Darwin) + cp -f bin/simple-httpd-darwin /usr/local/bin/simple-httpd +endif +ifeq ($(OS),Linux) + cp -f bin/simple-httpd-linux /usr/local/bin/simple-httpd +endif + +uninstall: clean + rm -f /usr/local/bin/simple-httpd* + +release: + @./build.sh diff --git a/build.sh b/build.sh index efbe14e..247055a 100755 --- a/build.sh +++ b/build.sh @@ -1,10 +1,43 @@ #!/bin/sh +FREEBSD="freebsd" +LINUX="linux" +DARWIN="darwin" +WINDOWS="windows" + VERSION="0.1" -ARCHS="darwin linux freebsd windows" +ARCHS="${DARWIN} ${LINUX} ${FREEBSD} ${WINDOWS}" + +if [ $1 == "release" ]; then + echo "Generating simple-httpd release binaries..." + for arch in ${ARCHS}; do + GOOS=${arch} GOARCH=amd64 go build -v -ldflags "-X main.gitSHA=$(git rev-parse HEAD)" -o bin/simple-httpd-${arch} + done +fi -echo "Generating simple-httpd release binaries..." +case "$1" in + "release") + echo "Building release..." + for arch in ${ARCHS}; do + GOOS=${arch} GOARCH=amd64 go build -v -ldflags "-X main.gitSHA=$(git rev-parse HEAD)" -o bin/simple-httpd-${arch} + done + ;; + "freebsd") + echo "Building binary for FreeBSD" + GOOS=${FREEBSD} GOARCH=amd64 go build -v -ldflags "-X main.gitSHA=$(git rev-parse HEAD)" -o bin/simple-httpd-${FREEBSD} + ;; + "darwin") + echo "Building binary for Darwin" + GOOS=${DARWIN} GOARCH=amd64 go build -v -ldflags "-X main.gitSHA=$(git rev-parse HEAD)" -o bin/simple-httpd-${DARWIN} + ;; + "linux") + echo "Building binary for Linux" + GOOS=${LINUX} GOARCH=amd64 go build -v -ldflags "-X main.gitSHA=$(git rev-parse HEAD)" -o bin/simple-httpd-${LINUX} + ;; + "windows") + echo "Building binary for Windows" + GOOS=${WINDOWS} GOARCH=amd64 go build -v -ldflags "-X main.gitSHA=$(git rev-parse HEAD)" -o bin/simple-httpd-${WINDOWS} + ;; +esac -for arch in ${ARCHS}; do - GOOS=windows GOARCH=amd64 go build -v -ldflags "-X main.gitSHA=$(git rev-parse HEAD)" -o bin/simple-httpd-${arch} -done +exit 0 diff --git a/main.go b/main.go index eb8b83d..db7c4a2 100644 --- a/main.go +++ b/main.go @@ -70,6 +70,7 @@ func (r requestData) String() string { return string(b) } +// setHeaders sets the base headers for all requests func setHeaders(w http.ResponseWriter) { w.Header().Set("Server", name+pathSeperator+version) w.Header().Add("Date", time.Now().Format(time.RFC822)) @@ -332,6 +333,6 @@ const htmlTemplate = `
` diff --git a/simple-httpd b/simple-httpd deleted file mode 100755 index 030face..0000000 Binary files a/simple-httpd and /dev/null differ