-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
45 lines (35 loc) · 1.66 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
NAME := swiro
VERSION := $(shell git describe --tags --exact-match 2> /dev/null || git rev-parse --short HEAD || echo "unknown")
SRCS := $(shell find . -type f -name '*.go')
LDFLAGS := -s -w -extldflags "-static"
LDFLAGS += \
-X "github.com/hatena/swiro/build.version=$(VERSION)" \
-X "github.com/hatena/swiro/build.name=$(NAME)"
.DEFAULT_GOAL := bin/$(NAME)
bin/$(NAME): $(SRCS)
go build -a -tags netgo -installsuffix netgo -ldflags '$(LDFLAGS)' -o bin/$(NAME)
.PHONY: cross-build
cross-build: deps
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags '$(LDFLAGS)' -o dist/$(NAME)_darwin_amd64
GOOS=darwin GOARCH=386 CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags '$(LDFLAGS)' -o dist/$(NAME)_darwin_386
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags '$(LDFLAGS)' -o dist/$(NAME)_linux_amd64
GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags '$(LDFLAGS)' -o dist/$(NAME)_linux_386
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags '$(LDFLAGS)' -o dist/$(NAME)_windows_amd64.exe
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags '$(LDFLAGS)' -o dist/$(NAME)_windows_386.exe
.PHONY: dep
dep:
ifeq ($(shell command -v dep 2> /dev/null),)
go get github.com/golang/dep/cmd/dep
endif
.PHONY: deps
deps: dep
dep ensure
.PHONY: fmt
fmt:
gofmt -s -w $$(find . -type f -name '*.go' | grep -v -e vendor)
.PHONY: imports
imports:
goimports -w $$(find . -type f -name '*.go' | grep -v -e vendor)
.PHONY: test
test:
go test -v -race $$(go list ./...)