4 ms·
I agree. This Makefile would be clearer with something like: BINARY_NAME := mybinary BINARY_UNIX := $(BINARY_NAME)_unix .PHONY: all test build
by jgrahamc 9y ago
I agree. This Makefile would be clearer with something like:
BINARY_NAME := mybinary
BINARY_UNIX := $(BINARY_NAME)_unix
.PHONY: all test build clean run deps
all: test build
build: ; go build -o $(BINARY_NAME) -v
test: ; go test -v ./...
clean: ; go clean && rm -f $(BINARY_NAME) $(BINARY_UNIX)
run: ; go run $(BINARY_NAME) -v ./...
deps: DEPS := $(addprefix github.com/markbates/,goth pop)
deps: ; go get $(DEPS)
build-linux: ; CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BINARY_UNIX) -v
docker-build: ; docker run --rm -it -v "$(GOPATH)":/go -w /go/src/bitbucket.org/rsohlich/makepost golang:latest go build -o "$(BINARY_UNIX)" -v
Caveat. I haven't tested that, but something close to that would be much clearer.
- titanomachy 9y agoShould `all` also be in `.PHONY` or is it a special case?
- jgrahamc 9y agoI just forgot it.
- jokr004 9y agoWell, the idea is that maybe the command 'go' is different on different build systems/targets and if you need to change it to something else (go-x86, or something like that) then it's going to be more difficult the way you wrote things.
- skybrian 9y agoSure, that's what variables are for. But in a small makefile, it's a simple search-and-replace to move it out to a variable. Adding indirection slightly degrades readability, so better to wait until it's first needed.
- jokr004 9y agoVery true.
- vog 9y agoIndeed, those variables are very handy for cross compiling. If you don't do anything else, at least define and use a $(CROSS) prefix. (Or, don't and wait for some cross compiling distro to approach you and to offer a patch that introduces such a variable.)