Skip to content

Commit

Permalink
Add Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumar committed Apr 8, 2020
1 parent db551a1 commit cd089b8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
goodhosts
goodhosts.exe
.idea
dist
dist
out
release
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Go and compilation related variables
BUILD_DIR ?= out

BINARY_NAME := goodhosts
RELEASE_DIR ?= release

# Add default target
.PHONY: all
all: build

vendor:
go mod vendor

$(BUILD_DIR):
mkdir -p $(BUILD_DIR)

.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
rm -rf vendor
rm -fr release

$(BUILD_DIR)/macos-amd64/$(BINARY_NAME):
GOARCH=amd64 GOOS=darwin go build -o $(BUILD_DIR)/macos-amd64/$(BINARY_NAME) ./main.go

$(BUILD_DIR)/linux-amd64/$(BINARY_NAME):
GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/linux-amd64/$(BINARY_NAME) ./main.go

$(BUILD_DIR)/windows-amd64/$(BINARY_NAME).exe:
GOARCH=amd64 GOOS=windows go build -o $(BUILD_DIR)/windows-amd64/$(BINARY_NAME).exe ./main.go

.PHONY: cross ## Cross compiles all binaries
cross: $(BUILD_DIR)/macos-amd64/$(BINARY_NAME) $(BUILD_DIR)/linux-amd64/$(BINARY_NAME) $(BUILD_DIR)/windows-amd64/$(BINARY_NAME).exe

.PHONY: release
release: clean cross
mkdir $(RELEASE_DIR)
tar cJSf $(RELEASE_DIR)/goodhosts-cli-macos-amd64.tar.xz -C $(BUILD_DIR)/macos-amd64 $(BINARY_NAME)
tar cJSf $(RELEASE_DIR)/goodhosts-cli-linux-amd64.tar.xz -C $(BUILD_DIR)/linux-amd64 $(BINARY_NAME)
tar cJSf $(RELEASE_DIR)/goodhosts-cli-windows-amd64.tar.xz -C $(BUILD_DIR)/windows-amd64 $(BINARY_NAME).exe

pushd $(RELEASE_DIR) && sha256sum * > sha256sum.txt && popd

.PHONY: build
build:
go build -o $(BINARY_NAME) ./main.go

0 comments on commit cd089b8

Please sign in to comment.