-
Notifications
You must be signed in to change notification settings - Fork 41
/
Makefile
133 lines (94 loc) · 2.75 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Birdseye Makefile
#
PROG=birdwatcher
ARCH=amd64
APP_VERSION=$(shell cat VERSION)
VERSION=$(APP_VERSION)_$(shell git rev-parse --short HEAD)
BUILD_SERVER=''
SYSTEM_INIT=systemd
DIST=DIST/
REMOTE_DIST=$(PROG)-$(DIST)
RPM=$(PROG)-$(VERSION)-1.x86_64.rpm
LOCAL_RPMS=RPMS
# OS Detection
UNAME=$(shell uname)
ifeq ($(UNAME), Darwin)
TARGET=osx
endif
ifeq ($(UNAME), FreeBSD)
TARGET=freebsd
endif
ifeq ($(UNAME), Linux)
TARGET=linux
endif
ifneq ($(UNAME),$(filter $(UNAME),Darwin FreeBSD Linux))
$(error error: Unkown OS )
endif
LDFLAGS_STATIC=-ldflags="-extldflags '-static'"
all: $(TARGET)
@echo "Built $(VERSION) @ $(TARGET)"
osx:
GO111MODULE=on GOARCH=$(ARCH) GOOS=darwin go build -o $(PROG)-osx-$(ARCH)
linux:
GO111MODULE=on GOARCH=$(ARCH) GOOS=linux go build -o $(PROG)-linux-$(ARCH)
freebsd:
GO111MODULE=on GOARCH=$(ARCH) GOOS=freebsd go build -o $(PROG)-freebsd-$(ARCH)
linux_static:
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) \
go build $(CFLAGS) \
-a $(LDFLAGS_STATIC) \
-o $(PROG)-linux-$(ARCH)
build_server:
ifeq ($(BUILD_SERVER), '')
$(error BUILD_SERVER not configured)
endif
dist: clean linux
mkdir -p $(DIST)opt/birdwatcher/birdwatcher/bin
mkdir -p $(DIST)etc/birdwatcher
ifeq ($(SYSTEM_INIT), systemd)
# Installing systemd services
mkdir -p $(DIST)usr/lib/systemd/system/
cp install/systemd/* $(DIST)usr/lib/systemd/system/.
else
# Installing upstart configuration
mkdir -p $(DIST)/etc/init/
cp install/upstart/init/* $(DIST)etc/init/.
endif
# Copy config and startup script
cp etc/birdwatcher/* DIST/etc/birdwatcher/.
rm -f DIST/etc/birdwatcher/*.local.*
# Copy bin
cp $(PROG)-linux-$(ARCH) DIST/opt/birdwatcher/birdwatcher/bin/.
release: linux
mkdir -p ../birdseye-static/birdwatcher-builds/$(APP_VERSION)/
cp birdwatcher-linux-amd64 ../birdseye-static/birdwatcher-builds/$(APP_VERSION)/
rm -f ../birdseye-static/birdwatcher-builds/latest
cd ../birdseye-static/birdwatcher-builds && ln -s $(APP_VERSION) latest
rpm: dist
# Clear tmp failed build (if any)
mkdir -p $(LOCAL_RPMS)
# Create RPM from dist
fpm -s dir -t rpm -n $(PROG) -v $(VERSION) -C $(DIST) \
--config-files /etc/birdwatcher/birdwatcher.conf \
opt/ etc/
mv $(RPM) $(LOCAL_RPMS)
remote_rpm: build_server dist
mkdir -p $(LOCAL_RPMS)
# Copy distribution to build server
ssh $(BUILD_SERVER) -- rm -rf $(REMOTE_DIST)
scp -r $(DIST) $(BUILD_SERVER):$(REMOTE_DIST)
ssh $(BUILD_SERVER) -- fpm -s dir -t rpm -n $(PROG) -v $(VERSION) -C $(REMOTE_DIST) \
--config-files /etc/birdwatcher/birdwatcher.conf \
opt/ etc/
# Get rpm from server
scp $(BUILD_SERVER):$(RPM) $(LOCAL_RPMS)/.
.PHONY: test clean
test:
go test -v
cd endpoints/ && go test -v
cd bird/ && go test -v
clean:
rm -f $(PROG)-osx-$(ARCH)
rm -f $(PROG)-linux-$(ARCH)
rm -rf $(DIST)