-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
157 lines (126 loc) · 3.29 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
SHELL=/bin/bash
# DIRECTORIES
BASE_DIR = .
NODE_MODULES_DIR = $(BASE_DIR)/node_modules
DIST_DIR = $(BASE_DIR)/build
DIST_DIR = $(BASE_DIR)/dist
PACK_DIR = $(BASE_DIR)/pack
INSTALL_PREFIX = "/usr/bin"
# VERSION
ifeq ($(VERSION),)
VERSION := "0.0.1"
endif
# PACKAGES
DEB = $(DIST_DIR)/tubectl-$(VERSION).deb
# NPM STUFF
NPM_BIN = npm
# TARGET ALIASES
INSTALL_TARGET = "$(INSTALL_PREFIX)/tubectl"
NPM_TARGET = $(NODE_MODULES_DIR)
CHANGELOG_TARGET = $(PACK_DIR)/DEBIAN/changelog
BUILD_TARGET = $(BUILD_DIR) $(NPM_TARGET)
# TARGETS
.PHONY: all
all: build
.PHONY: clean
clean: mostlyclean
@-test ! -d $(BUILD_DIR) || rm -rfv $(BUILD_DIR)
.PHONY: mostlyclean
mostlyclean:
@-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: deb
.PHONY: deb
deb: $(DIST_DIR)/tubectl-$(VERSION).deb
$(DIST_DIR)/tubectl-$(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
@mkdir -p $(PACK_DIR)/$(INSTALL_PREFIX)
@cp $(DIST_DIR)/tubectl-linux-x64 $(PACK_DIR)/$(INSTALL_PREFIX)/tubectl
@-test -d $(DIST_DIR) || mkdir $(DIST_DIR)
@dpkg-deb --build $(PACK_DIR) $@
@rm -rf $(PACK_DIR)
.PHONY: changelog
changelog: $(CHANGELOG_TARGET)
$(CHANGELOG_TARGET): CHANGELOG.md
@-test -d $(@D) || mkdir -p $(@D)
@v=""
@stable="stable"
@author=""
@date=""
@changes=""
@-test ! -f $@ || rm $@
@while read l; \
do \
if [ "$${l:0:2}" == "##" ]; \
then \
if [ "$$v" != "" ]; \
then \
echo "tubectl ($$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: build
build: $(BUILD_TARGET)
$(BUILD_TARGET) : $(BASE_DIR)/build
@test "`$(NPM_BIN) install --dry-run 2>&1 >/dev/null | grep Failed`" == ""
$(NPM_BIN) run build
@touch $@
.PHONY: install
install: $(INSTALL_TARGET)
$(INSTALL_TARGET): $(BUILD_TARGET)
@cp -Rp $(DIST_DIR)/tubectl-linux-x64 $(INSTALL_PREFIX)/tubectl
@chmod +x $(INSTALL_PREFIX)/tubectl