Makefile
-include .env
BUILD_DIR=$(shell pwd)
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-s -w"
## install: Compile the binary.
install:
@echo " > Building binary..."
@cd ${BUILD_DIR}; \
go build ${LDFLAGS} -o ${BINARY}-linux-${GOARCH} . ; \
cd - >/dev/null
## linux: Compile the binary with linux.
linux:
@cd ${BUILD_DIR}; \
GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-linux-${GOARCH} . ; \
cd - >/dev/null
## darwin: Compile the binary with macos.
darwin:
@cd ${BUILD_DIR}; \
GOOS=darwin GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH} . ; \
cd - >/dev/null
## windows: Compile the binary with windows.
windows:
@cd ${BUILD_DIR}; \
GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-windows-${GOARCH}.exe . ; \
cd - >/dev/null
## format: format source codes
format:
@cd ${BUILD_DIR}; \
go fmt $$(go list ./... | grep -v /vendor/) ; \
cd - >/dev/null
## clean: Clean build files. Runs `go clean` internally.
clean:
@echo " > Cleaning build cache"
@cd ${BUILD_DIR}; \
rm -f ${BINARY}-*
.PHONY: help
all: help
help: Makefile
@echo
@echo " Choose a command run in "$(BUILD_DIR)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
.env
BINARY=example
GOARCH=amd64
VERSION=v1.0.0