-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
64 lines (53 loc) · 1.57 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Package configuration
PROJECT = beanstool
COMMANDS = beanstool
DEPENDENCIES =
# Environment
BASE_PATH := $(shell pwd)
BUILD_PATH := $(BASE_PATH)/build
VERSION ?= $(shell git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
BUILD ?= $(shell date)
ASSETS := static
# PACKAGES
PKG_OS = darwin linux
PKG_ARCH = amd64
PKG_CONTENT = LICENSE
# Go parameters
GOCMD = go
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOGET = $(GOCMD) get
GOTEST = $(GOCMD) test
# Rules
all: test build
build: dependencies
for cmd in $(COMMANDS); do \
$(GOCMD) build -ldflags "-X main.version $(VERSION) -X main.build \"$(BUILD)\"" $${cmd}.go; \
done
test: dependencies
cd $(BASE_PATH); $(GOTEST) -v ./...
dependencies:
$(GOGET) -d -v ./...
for i in $(DEPENDENCIES); do $(GOGET) $$i; done
install:
for cmd in $(COMMANDS); do \
cp -rf $${cmd} /usr/bin/; \
done
packages: clean
for os in $(PKG_OS); do \
for arch in $(PKG_ARCH); do \
cd $(BASE_PATH); \
mkdir -p $(BUILD_PATH)/$(PROJECT)_$(VERSION)_$${os}_$${arch}; \
for cmd in $(COMMANDS); do \
GOOS=$${os} GOARCH=$${arch} $(GOCMD) build -ldflags "-X main.version $(VERSION) -X main.build \"$(BUILD)\"" -o $(BUILD_PATH)/$(PROJECT)_$(VERSION)_$${os}_$${arch}/$${cmd} $${cmd}.go ; \
done; \
for content in $(PKG_CONTENT); do \
cp -rf $${content} $(BUILD_PATH)/$(PROJECT)_$(VERSION)_$${os}_$${arch}/; \
done; \
cd $(BUILD_PATH) && tar -cvzf $(BUILD_PATH)/$(PROJECT)_$(VERSION)_$${os}_$${arch}.tar.gz $(PROJECT)_$(VERSION)_$${os}_$${arch}/; \
done; \
done;
clean:
echo $(VERSION)
rm -rf $(BUILD_PATH)
$(GOCLEAN) .