-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
35 lines (25 loc) · 1.09 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
# Custom Makefile
# Inspired by https://gist.github.com/subfuzion/0bd969d08fe0d8b5cc4b23c795854a13
TARGET := $(shell echo $${PWD\#\#*/})
VERSION := $(shell cat VERSION)
IMPORTPATH := "github.com/catay"
CURRENT_COMMIT := $(shell git log -n 1 --format="%H")
RELEASE_COMMIT := $(shell git log -n 1 --format="%H" $(VERSION))
# Inject version info into the targets
LDFLAGS=-ldflags "-X $(IMPORTPATH)/$(TARGET)/version.Version=$(VERSION)"
CURRENT_LDFLAGS=-ldflags "-X $(IMPORTPATH)/$(TARGET)/version.Commit=$(CURRENT_COMMIT)"
RELEASE_LDFLAGS=-ldflags "-X $(IMPORTPATH)/$(TARGET)/version.Version=$(VERSION) -X $(IMPORTPATH)/$(TARGET)/version.Commit=$(RELEASE_COMMIT)"
# go source files, ignore vendor directory
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
.PHONY: build clean $(TARGET)
build: $(TARGET)
release: $(SRC)
ifeq ($(CURRENT_COMMIT), $(RELEASE_COMMIT))
@go build $(RELEASE_LDFLAGS) -o $(TARGET)
else
@echo "Current and tagged version commit hash don't match. Do nothing !!"
endif
$(TARGET): $(SRC)
@go build $(CURRENT_LDFLAGS) -o $(TARGET)
clean:
@rm -f $(TARGET)