-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
194 lines (156 loc) · 4.39 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
SHELL=/bin/bash
# DIRECTORIES
BASE_DIR = .
NODE_MODULES_DIR = $(BASE_DIR)/node_modules
DIST_DIR = $(BASE_DIR)/dist
BUILD_DIR = $(BASE_DIR)/build
PACK_DIR = $(BASE_DIR)/pack
INSTALL_PREFIX = "/"
# VERSION
ifeq ($(VERSION),)
VERSION := "0.0.1"
endif
# PACKAGES
DEB = $(DIST_DIR)/balloon-web-$(VERSION).deb
TAR = $(DIST_DIR)/balloon-web-$(VERSION).tar.gz
# NPM STUFF
NPM_BIN = npm
ESLINT_BIN = $(NODE_MODULES_DIR)/.bin/eslint
# TARGET ALIASES
INSTALL_TARGET = "$(INSTALL_PREFIX)usr/share/balloon-web"
NPM_TARGET = $(NODE_MODULES_DIR)
WEBPACK_TARGET = $(BUILD_DIR)
ESLINT_TARGET = $(BASE_DIR)
CHANGELOG_TARGET = $(PACK_DIR)/DEBIAN/changelog
BUILD_TARGET = $(ESLINT_TARGET) $(WEBPACK_TARGET)
# TARGETS
.PHONY: all
all: build
.PHONY: clean
clean: mostlyclean
@-test ! -d $(BUILD_DIR) || rm -rfv $(BUILD_DIR)
.PHONY: mostlyclean
mostlyclean:
@-test ! -f $(TAR) || rm -fv $(TAR)
@-test ! -d $(NODE_MODULES_DIR) || rm -rfv $(NODE_MODULES_DIR)
@-test ! -f $(DIST_DIR)/* || rm -fv $(DIST_DIR)/*
.PHONY: deps
deps: npm
.PHONY: build
build: $(BUILD_TARGET)
.PHONY: dist
dist: tar deb
.PHONY: deb
deb: $(DIST_DIR)/balloon-web-$(VERSION).deb
$(DIST_DIR)/balloon-web-$(VERSION).deb: $(CHANGELOG_TARGET) $(BUILD_TARGET)
@-test ! -d $(PACK_DIR) || rm -rfv $(PACK_DIR)
@mkdir -p $(PACK_DIR)/DEBIAN
@cp $(BASE_DIR)/packaging/debian/control $(PACK_DIR)/DEBIAN/control
@sed -i s/'{version}'/$(VERSION)/g $(PACK_DIR)/DEBIAN/control
@cp $(BASE_DIR)/packaging/debian/postinst $(PACK_DIR)/DEBIAN/postinst
@mkdir -p $(PACK_DIR)/usr/share/balloon-web
@cp -Rp $(BUILD_DIR)/* $(PACK_DIR)/usr/share/balloon-web
@mkdir $(PACK_DIR)/usr/share/balloon-web/nginx
@cp -Rp $(BASE_DIR)/packaging/debian/nginx.conf $(PACK_DIR)/usr/share/balloon-web/nginx
@cp -Rp $(BASE_DIR)/packaging/debian/nginx-web.conf $(PACK_DIR)/usr/share/balloon-web/nginx
@-test -d $(DIST_DIR) || mkdir $(DIST_DIR)
@dpkg-deb --build $(PACK_DIR) $@
@rm -rf $(PACK_DIR)
.PHONY: tar
tar: $(TAR)
$(TAR): $(BUILD_TARGET)
@-test ! -f $(TAR) || rm -fv $(TAR)
@-test ! -d $(PACK_DIR) || rm -rfv $(PACK_DIR)
@-test -d $(DIST_DIR) || mkdir $(DIST_DIR)
@mkdir $(PACK_DIR)
@cp -Rp $(BUILD_DIR)/* $(PACK_DIR)
@tar -czvf $(TAR) -C $(PACK_DIR) .
@rm -rf $(PACK_DIR)
@touch $@
.PHONY: changelog
changelog: $(CHANGELOG_TARGET)
$(CHANGELOG_TARGET): CHANGELOG.md
@-test -d $(@D) || mkdir -p $(@D)
@v=""
@stable="stable"
@author=""
@category=""
@date=""
@changes=""
@-test ! -f $@ || rm $@
@while read l; \
do \
if [ "$${l:0:3}" == "###" ]; \
then \
category=$${l:4}; \
elif [ "$${l:0:2}" == "##" ]; \
then \
if [ "$$v" != "" ]; \
then \
echo "balloon ($$v) $$stable; urgency=low" >> $@; \
echo -e "$$changes" >> $@; \
echo >> $@; \
echo " -- $$author $$date" >> $@; \
echo >> $@; \
v=""; \
stable="stable"; \
author=";" \
date=";" \
changes=""; \
fi; \
v=$${l:3}; \
if [[ "$$v" == *"RC"* ]]; \
then \
stable="unstable"; \
elif [[ "$$v" == *"BETA"* ]]; \
then \
stable="unstable"; \
elif [[ "$$v" == *"ALPHA"* ]]; \
then \
stable="unstable"; \
elif [[ "$$v" == *"dev"* ]]; \
then \
stable="unstable"; \
fi \
elif [ "$${l:0:5}" == "**Mai" ]; \
then \
p1=`echo $$l | cut -d '>' -f1`; \
p2=`echo $$l | cut -d '>' -f2`; \
author="$${p1:16}>"; \
date=$${p2:13}; \
date=`date -d"$$date" +'%a, %d %b %Y %H:%M:%S %z'`; \
if [ $$? -ne 0 ]; \
then \
date=`date +'%a, %d %b %Y %H:%M:%S %z'`; \
fi; \
echo $$date; \
elif [ "$${l:0:2}" == "* " ]; \
then \
changes=" $$changes\n $$l"; \
fi; \
done < $<
@echo generated $@ from $<
.PHONY: npm
npm: $(NPM_TARGET)
$(NPM_TARGET) : $(BASE_DIR)/package.json
@test "`$(NPM_BIN) install --dry-run 2>&1 >/dev/null | grep Failed`" == ""
$(NPM_BIN) run install
$(NPM_BIN) update
@touch $@
.PHONY: eslint
eslint: $(ESLINT_TARGET)
$(ESLINT_TARGET) : $(NPM_TARGET)
$(ESLINT_BIN) src *.js
@touch $@
.PHONY: webpack
webpack: $(WEBPACK_TARGET)
$(WEBPACK_TARGET) : $(NPM_TARGET) $(BASE_DIR)/webpack.common.js
$(NPM_BIN) run build
@touch $@
.PHONY: install
install: $(INSTALL_TARGET)
$(INSTALL_TARGET): $(BUILD_TARGET)
@cp -Rp $(BUILD_DIR)/* $(INSTALL_PREFIX)/usr/share/balloon-web
@mkdir -p /etc/nginx/conf.d/balloon
@cp -Rp $(BASE_DIR)/packaging/debian/nginx.conf /etc/nginx/conf.d/balloon.conf
@cp -Rp $(BASE_DIR)/packaging/debian/nginx-web.conf /etc/nginx/conf.d/balloon/web.conf