-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
240 lines (210 loc) · 8.79 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# In some dists (e.g. Ubuntu) bash is not the default shell. Statements like
# cp -a etc/rear/{mappings,templates} ...
# assumes bash. So its better to set SHELL
SHELL=/bin/bash
DESTDIR =
OFFICIAL =
### Get version from Relax-and-Recover itself
rearbin = usr/sbin/rear
name = rear
version := $(shell awk 'BEGIN { FS="=" } /^VERSION=/ { print $$2}' $(rearbin))
### Get the branch information from git
ifeq ($(OFFICIAL),)
ifneq ($(shell which git),)
git_date := $(shell git log -n 1 --format="%ai")
git_ref := $(shell git symbolic-ref -q HEAD)
git_branch = $(lastword $(subst /, ,$(git_ref)))
endif
else
git_branch = rear-$(version)
endif
git_branch ?= master
date := $(shell date --date="$(git_date)" +%Y%m%d%H%M)
release_date := $(shell date --date="$(git_date)" +%Y-%m-%d)
prefix = /usr
sysconfdir = /etc
sbindir = $(prefix)/sbin
datadir = $(prefix)/share
mandir = $(datadir)/man
localstatedir = /var
specfile = packaging/rpm/$(name).spec
dscfile = packaging/debian/$(name).dsc
distversion = $(version)
debrelease = 0
rpmrelease = %nil
obsproject = Archiving:Backup:Rear
obspackage = $(name)-$(version)
ifeq ($(OFFICIAL),)
distversion = $(version)-git$(date)
debrelease = 0git$(date)
rpmrelease = .git$(date)
obsproject = Archiving:Backup:Rear:Snapshot
obspackage = $(name)
endif
.PHONY: doc
all:
@echo "Nothing to build. Use \`make help' for more information."
help:
@echo -e "Relax-and-Recover make targets:\n\
\n\
validate - Check source code\n\
install - Install Relax-and-Recover (may replace files)\n\
uninstall - Uninstall Relax-and-Recover (may remove files)\n\
dist - Create tar file\n\
deb - Create DEB package\n\
rpm - Create RPM package\n\
pacman - Create Pacman package\n\
obs - Initiate OBS builds\n\
\n\
Relax-and-Recover make variables (optional):\n\
\n\
DESTDIR= - Location to install/uninstall\n\
OFFICIAL= - Build an official release\n\
"
clean:
rm -f $(name)-$(distversion).tar.gz
rm -f build-stamp
make -C doc clean
### You can call 'make validate' directly from your .git/hooks/pre-commit script
validate:
@echo -e "\033[1m== Validating scripts and configuration ==\033[0;0m"
find etc/ usr/share/rear/conf/ -name '*.conf' | xargs -n 1 bash -n
bash -n $(rearbin)
find . -name '*.sh' | xargs -n 1 bash -n
### Fails to work on RHEL4
# find -L . -type l
man:
@echo -e "\033[1m== Prepare manual ==\033[0;0m"
make -C doc man
doc:
@echo -e "\033[1m== Prepare documentation ==\033[0;0m"
make -C doc docs
ifneq ($(git_date),)
rewrite:
@echo -e "\033[1m== Rewriting $(specfile), $(dscfile) and $(rearbin) ==\033[0;0m"
sed -i.orig \
-e 's#^Source:.*#Source: https://sourceforge.net/projects/rear/files/rear/${version}/$(name)-${distversion}.tar.gz#' \
-e 's#^Version:.*#Version: $(version)#' \
-e 's#^%define rpmrelease.*#%define rpmrelease $(rpmrelease)#' \
-e 's#^%setup.*#%setup -q -n $(name)-$(distversion)#' \
$(specfile)
sed -i.orig \
-e 's#^Version:.*#Version: $(version)-$(debrelease)#' \
$(dscfile)
sed -i.orig \
-e 's#^VERSION=.*#VERSION=$(distversion)#' \
-e 's#^RELEASE_DATE=.*#RELEASE_DATE="$(release_date)"#' \
$(rearbin)
restore:
@echo -e "\033[1m== Restoring $(specfile) and $(rearbin) ==\033[0;0m"
mv -f $(specfile).orig $(specfile)
mv -f $(dscfile).orig $(dscfile)
mv -f $(rearbin).orig $(rearbin)
else
rewrite:
@echo "Nothing to do."
restore:
@echo "Nothing to do."
endif
install-config:
@echo -e "\033[1m== Installing configuration ==\033[0;0m"
install -d -m0700 $(DESTDIR)$(sysconfdir)/rear/
-[[ ! -e $(DESTDIR)$(sysconfdir)/rear/local.conf ]] && \
install -Dp -m0600 etc/rear/local.conf $(DESTDIR)$(sysconfdir)/rear/local.conf
-[[ ! -e $(DESTDIR)$(sysconfdir)/rear/os.conf && -e etc/rear/os.conf ]] && \
install -Dp -m0600 etc/rear/os.conf $(DESTDIR)$(sysconfdir)/rear/os.conf
-find $(DESTDIR)$(sysconfdir)/rear/ -name '.gitignore' -exec rm -rf {} \; &>/dev/null
install-bin:
@echo -e "\033[1m== Installing binary ==\033[0;0m"
install -Dp -m0755 $(rearbin) $(DESTDIR)$(sbindir)/rear
sed -i -e 's,^CONFIG_DIR=.*,CONFIG_DIR="$(sysconfdir)/rear",' \
-e 's,^SHARE_DIR=.*,SHARE_DIR="$(datadir)/rear",' \
-e 's,^VAR_DIR=.*,VAR_DIR="$(localstatedir)/lib/rear",' \
$(DESTDIR)$(sbindir)/rear
install-data:
@echo -e "\033[1m== Installing scripts ==\033[0;0m"
install -d -m0755 $(DESTDIR)$(datadir)/rear/
cp -a usr/share/rear/. $(DESTDIR)$(datadir)/rear/
-find $(DESTDIR)$(datadir)/rear/ -name '.gitignore' -exec rm -rf {} \; &>/dev/null
install-var:
@echo -e "\033[1m== Installing working directory ==\033[0;0m"
install -d -m0755 $(DESTDIR)$(localstatedir)/lib/rear/
install -d -m0755 $(DESTDIR)$(localstatedir)/log/rear/
install-doc:
@echo -e "\033[1m== Installing documentation ==\033[0;0m"
make -C doc install
sed -i -e 's,/etc,$(sysconfdir),' \
-e 's,/usr/sbin,$(sbindir),' \
-e 's,/usr/share,$(datadir),' \
-e 's,/usr/share/doc/packages,$(datadir)/doc,' \
$(DESTDIR)$(mandir)/man8/rear.8
install: validate man install-config rewrite install-bin restore install-data install-var install-doc
uninstall:
@echo -e "\033[1m== Uninstalling Relax-and-Recover ==\033[0;0m"
-rm -v $(DESTDIR)$(sbindir)/rear
-rm -v $(DESTDIR)$(mandir)/man8/rear.8
-rm -rv $(DESTDIR)$(datadir)/rear/
# rm -rv $(DESTDIR)$(sysconfdir)/rear/
# rm -rv $(DESTDIR)$(localstatedir)/lib/rear/
dist: clean validate man rewrite $(name)-$(distversion).tar.gz restore
$(name)-$(distversion).tar.gz:
@echo -e "\033[1m== Building archive $(name)-$(distversion) ==\033[0;0m"
git checkout $(git_branch)
git ls-tree -r --name-only --full-tree $(git_branch) | \
tar -czf $(name)-$(distversion).tar.gz --transform='s,^,$(name)-$(distversion)/,S' --files-from=-
rpm: dist
@echo -e "\033[1m== Building RPM package $(name)-$(distversion) ==\033[0;0m"
rpmbuild -tb --clean \
--define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
--define "debug_package %{nil}" \
--define "_rpmdir %(pwd)" $(name)-$(distversion).tar.gz
deb: dist
@echo -e "\033[1m== Building DEB package $(name)-$(distversion) ==\033[0;0m"
cp -r packaging/debian/ .
chmod 755 debian/rules
fakeroot debian/rules clean
fakeroot dh_install
fakeroot debian/rules binary
-rm -rf debian/
pacman: BUILD_DIR = /tmp/rear-$(distversion)
pacman: dist
@echo -e "\033[1m== Building Pacman package $(name)-$(distversion) ==\033[0;0m"
rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
cp packaging/arch/PKGBUILD.local $(BUILD_DIR)/PKGBUILD
cp $(name)-$(distversion).tar.gz $(BUILD_DIR)/
cd $(BUILD_DIR) ; sed -i -e 's/VERSION/$(date)/' \
-e 's/SOURCE/$(name)-$(distversion).tar.gz/' \
-e 's/MD5SUM/$(shell md5sum $(name)-$(distversion).tar.gz | cut -d' ' -f1)/' \
PKGBUILD ; makepkg -c
cp $(BUILD_DIR)/*.pkg.* .
rm -rf $(BUILD_DIR)
obs: BUILD_DIR = /tmp/rear-$(distversion)
obs: obsname = $(shell osc ls $(obsproject) $(obspackage) | awk '/.tar.gz$$/ { gsub(".tar.gz$$","",$$1); print }')
obs: dist
@echo -e "\033[1m== Updating OBS from $(obsname) to $(name)-$(distversion)== \033[0;0m"
ifneq ($(obsname),$(name)-$(distversion))
-rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
ifneq ($(OFFICIAL),)
# osc rdelete -m 'Recreating branch $(obspackage)' $(obsproject) $(obspackage)
-osc branch Archiving:Backup:Rear:Snapshot rear $(obsproject) $(obspackage)
-osc detachbranch $(obsproject) $(obspackage)
endif
(cd $(BUILD_DIR) ; osc co -c $(obsproject) $(obspackage) )
-(cd $(BUILD_DIR)/$(obspackage) ; osc del *.tar.gz )
cp $(name)-$(distversion).tar.gz $(BUILD_DIR)/$(obspackage)
tar -xOzf $(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/$(specfile) >$(BUILD_DIR)/$(obspackage)/$(name).spec
tar -xOzf $(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/$(dscfile) >$(BUILD_DIR)/$(obspackage)/$(name).dsc
tar -xOzf $(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/control >$(BUILD_DIR)/$(obspackage)/debian.control
tar -xOzf $(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/rules >$(BUILD_DIR)/$(obspackage)/debian.rules
echo -e "rear ($(version)-$(debrelease)) stable; urgency=low\n\n * new snapshot build\n\n -- OpenSUSE Build System <[email protected]> $$(date -R)" >$(BUILD_DIR)/$(obspackage)/debian.changelog
tar -xOzf $(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/changelog >>$(BUILD_DIR)/$(obspackage)/debian.changelog
cd $(BUILD_DIR)/$(obspackage); osc addremove
cd $(BUILD_DIR)/$(obspackage); osc ci -m "Update to $(name)-$(distversion)" $(BUILD_DIR)/$(obspackage)
rm -rf $(BUILD_DIR)
@echo -e "\033[1mNow visit https://build.opensuse.org/package/show?package=rear&project=$(obsproject)"
@echo -e "or inspect the queue at: https://build.opensuse.org/monitor\033[0;0m"
else
@echo -e "OBS already updated to this release."
endif