Skip to content

Commit

Permalink
Update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
daichirata committed Dec 12, 2019
1 parent c815ebe commit 1a807e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/tmp/
/build/
/package/
/bin/
/dist/
34 changes: 11 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
VERSION := 0.1.0
BIN_NAME := hammer

GOFLAGS := -tags netgo -installsuffix netgo -ldflags '-w -s --extldflags "-static"'
GOVERSION=$(shell go version)
GOOS=$(word 1,$(subst /, ,$(lastword $(GOVERSION))))
GOARCH=$(word 2,$(subst /, ,$(lastword $(GOVERSION))))
BUILD_DIR=build/$(GOOS)-$(GOARCH)
GOFILES := $(shell find . -type f -name '*.go')

.PHONY: all build clean deps package package-zip package-targz
all: bin/$(BIN_NAME)

all: build
bin/$(BIN_NAME): $(GOFILES)
go build $(GOFLAGS) -o $@ .

build: deps
mkdir -p $(BUILD_DIR)
GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(GOFLAGS) -o $(BUILD_DIR)/hammer
build-cross:
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -o dist/$(BIN_NAME)_$(VERSION)_amd64_linux
GOOS=darwin GOARCH=amd64 go build $(GOFLAGS) -o dist/$(BIN_NAME)_$(VERSION)_amd64_darwin

clean:
rm -rf build package
rm -rf bin dist

deps:
go get -t ./...
go mod tidy

package:
$(MAKE) package-targz GOOS=linux GOARCH=amd64
$(MAKE) package-targz GOOS=linux GOARCH=arm64
$(MAKE) package-zip GOOS=darwin GOARCH=amd64

package-zip: build
mkdir -p package
cd $(BUILD_DIR) && zip ../../package/$(GOOS)_$(GOARCH).zip hammer

package-targz: build
mkdir -p package
cd $(BUILD_DIR) && tar zcvf ../../package/$(GOOS)_$(GOARCH).tar.gz hammer

test:
go test -race -v ./...

0 comments on commit 1a807e7

Please sign in to comment.