Debian Codegraph @

Makefile

raw symbols SCIP
1 # In some dists (e.g. Ubuntu) bash is not the default shell. Statements like
2 # cp -a etc/rear/{mappings,templates} ...
3 # assumes bash. So its better to set SHELL to bash explicitly, using the one from PATH
4 # to also work on MacOS with Homebrew-installed bash
5 SHELL = bash
6
7 # disable parallel execution of make
8 .NOTPARALLEL:
9
10 DESTDIR =
11 OFFICIAL =
12 DIST_CONTENT = COPYING doc etc MAINTAINERS Makefile packaging README.md tests tools usr
13
14 ### Get version from Relax-and-Recover itself
15 rearbin = usr/sbin/rear
16 name = rear
17 version := $(shell awk 'BEGIN { FS="=" } /^readonly VERSION=/ { print $$2}' $(rearbin))
18
19 ifneq ($(OFFICIAL),)
20 distversion = $(version)
21 debrelease = 0
22 rpmrelease = %nil
23 obsproject = Archiving:Backup:Rear
24 obspackage = $(name)-$(version)
25
26 date := $(shell date +%Y%m%d%H%M)
27 release_date := $(shell date +%Y-%m-%d)
28 else
29 # Not official build, so we need to get the git info
30 # Some distros have older git, hence we need to do more processing
31 # of the output to get the exact same output on all the distros
32 ifneq ($(wildcard .git),)
33 ifneq ($(shell type -p git),)
34 git_date := $(shell git log -n 1 --format="%ai")
35 git_ref := $(shell git rev-parse HEAD | cut -c 1-8)
36 git_count := $(shell git rev-list HEAD --no-merges | wc -l)
37 git_branch_suffix = $(shell git symbolic-ref HEAD | sed -e 's,^.*/,,' -e "s/[^A-Za-z0-9]//g")
38 git_status := $(shell git status --porcelain)
39 git_stamp := $(git_count).$(git_ref).$(git_branch_suffix)
40 ifneq ($(git_status),)
41 git_stamp := $(git_stamp).changed
42 endif # git_status
43 else # no git
44 git_date := now
45 git_ref := 0
46 git_count := 0
47 git_branch_suffix := unknown
48 git_stamp := $(git_count).$(git_ref).$(git_branch_suffix)
49 endif # has git
50 endif # has .git
51 git_stamp ?= 0.0.unknown
52
53 distversion = $(version)-git.$(git_stamp)
54 debrelease = 0git.$(git_stamp)
55 rpmrelease = .git.$(git_stamp)
56 obsproject = Archiving:Backup:Rear:Snapshot
57 obspackage = $(name)
58
59 date := $(shell date --date="$(git_date)" +%Y%m%d%H%M)
60 release_date := $(shell date --date="$(git_date)" +%Y-%m-%d)
61 endif
62
63
64 BUILD_DIR = /var/tmp/build-$(name)-$(distversion)
65
66 prefix = /usr
67 sysconfdir = /etc
68 sbindir = $(prefix)/sbin
69 datadir = $(prefix)/share
70 mandir = $(datadir)/man
71 localstatedir = /var
72
73 specfile = packaging/rpm/$(name).spec
74 dscfile = packaging/debian/$(name).dsc
75
76 # Spec file that will be actually used to build the package
77 # - a bit modified from the source $(specfile)
78 effectivespecfile = $(name)-$(distversion)/$(specfile)
79
80 rpmdefines = --define="_topdir $(BUILD_DIR)/rpmbuild" \
81 --define="debug_package %{nil}"
82
83 ifeq ($(shell id -u),0)
84 RUNASUSER := runuser -u nobody --
85 else
86 RUNASUSER :=
87 endif
88
89 # .gitignore is optional, avoid tar errors if it does not exist, e.g. in a dist archive
90 tarparams = $(shell test -f .gitignore && echo --exclude-from=.gitignore --exclude=.gitignore) --exclude=".??*" $(DIST_CONTENT)
91
92 DIST_FILES := $(shell tar -cv -f /dev/null $(tarparams))
93
94 .PHONY: doc dump package
95
96 all:
97 @echo "Nothing to build. Use 'make help' for more information."
98
99 help:
100 @echo -e "Relax-and-Recover make targets:\n\
101 \n\
102 version - Show ReaR version used\n\
103 validate - Check source code\n\
104 install - Install Relax-and-Recover (may replace files)\n\
105 uninstall - Uninstall Relax-and-Recover (may remove files)\n\
106 dist - Create tar file in dist/\n\
107 dist-install - Create tar file in dist and use that to install via make install\n\
108 We use this to install from checkout with correct version\n\
109 package - Create DEB/PM/Pacman package in dist/\n\
110 deb - Create DEB package in dist/\n\
111 rpm - Create RPM package in dist/\n\
112 pacman - Create Pacman package\n\
113 obs - Initiate OBS builds\n\
114 dump - Dump Makefile variables\n\
115 \n\
116 Relax-and-Recover make variables (optional):\n\
117 \n\
118 DESTDIR= - Location to install/uninstall\n\
119 OFFICIAL=1 - Build an official release\n\
120 \n\
121 "
122
123 version:
124 @echo $(distversion)
125
126 dump:
127 # found at https://www.cmcrossroads.com/article/dumping-every-makefile-variable
128 $(foreach V, $(sort $(.VARIABLES)), $(if $(filter-out environment% default automatic, $(origin $V)),$(info $V=$($V) defined as >$(value $V)<)))
129
130 clean:
131 rm -Rf dist etc/os.conf etc/site.conf var build-stamp
132 $(MAKE) -C doc clean
133
134 clean-all: clean
135 rm -Rf $(BUILD_DIR)
136
137 ### You can call 'make validate' directly from your .git/hooks/pre-commit script
138 validate:
139 @echo -e "\033[1m== Validating scripts and configuration ==\033[0;0m"
140 find etc/ usr/share/rear/conf/ -name '*.conf' | xargs -n 1 $(SHELL) -n
141 $(SHELL) -n $(rearbin)
142 find . -name '*.sh' | xargs -n 1 $(SHELL) -O extglob -O nullglob -n
143 find usr/share/rear -name '*.sh' | grep -v -E '(lib|skel|conf)' | while read FILE ; do \
144 num=$$(echo $${FILE##*/} | cut -c1-3); \
145 if [[ "$$num" = "000" || "$$num" = "999" ]] ; then \
146 echo "ERROR: script $$FILE may not start with $$num"; \
147 exit 1; \
148 else \
149 if $$( grep '[_[:alpha:]]' <<< $$num >/dev/null 2>&1 ) ; then \
150 echo "ERROR: script $$FILE must start with 3 digits"; \
151 exit 1; \
152 fi; \
153 fi; \
154 done
155
156 man:
157 @echo -e "\033[1m== Prepare manual ==\033[0;0m"
158 $(MAKE) -C doc man
159
160 doc:
161 @echo -e "\033[1m== Prepare documentation ==\033[0;0m"
162 $(MAKE) -C doc docs
163
164 install-config:
165 @echo -e "\033[1m== Installing configuration ==\033[0;0m"
166 install -d -m0700 $(DESTDIR)$(sysconfdir)/rear/
167 install -d -m0700 $(DESTDIR)$(sysconfdir)/rear/cert/
168 -[[ ! -e $(DESTDIR)$(sysconfdir)/rear/local.conf ]] && \
169 install -Dp -m0600 etc/rear/local.conf $(DESTDIR)$(sysconfdir)/rear/local.conf
170 -[[ ! -e $(DESTDIR)$(sysconfdir)/rear/os.conf && -e etc/rear/os.conf ]] && \
171 install -Dp -m0600 etc/rear/os.conf $(DESTDIR)$(sysconfdir)/rear/os.conf
172 -find $(DESTDIR)$(sysconfdir)/rear/ -name '.gitignore' -exec rm -rf {} \; &>/dev/null
173
174 install-bin:
175 @echo -e "\033[1m== Installing binary ==\033[0;0m"
176 install -Dp -m0755 $(rearbin) $(DESTDIR)$(sbindir)/rear
177 sed -i -e 's,^CONFIG_DIR=.*,CONFIG_DIR="$$REAR_DIR_PREFIX$(sysconfdir)/rear",' \
178 -e 's,^SHARE_DIR=.*,SHARE_DIR="$$REAR_DIR_PREFIX$(datadir)/rear",' \
179 -e 's,^VAR_DIR=.*,VAR_DIR="$$REAR_DIR_PREFIX$(localstatedir)/lib/rear",' \
180 -e 's,^LOG_DIR=.*,LOG_DIR="$$REAR_DIR_PREFIX$(localstatedir)/log/rear",' \
181 $(DESTDIR)$(sbindir)/rear
182
183 install-data:
184 @echo -e "\033[1m== Installing scripts ==\033[0;0m"
185 rm -Rf $(DESTDIR)$(datadir)/rear
186 install -d -m0755 $(DESTDIR)$(datadir)/rear/
187 cp -a usr/share/rear/. $(DESTDIR)$(datadir)/rear/
188 -find $(DESTDIR)$(datadir)/rear/ -name '.gitignore' -exec rm -rf {} \; &>/dev/null
189
190 install-var:
191 @echo -e "\033[1m== Installing working directory ==\033[0;0m"
192 install -d -m0755 $(DESTDIR)$(localstatedir)/lib/rear/
193 install -d -m0755 $(DESTDIR)$(localstatedir)/log/rear/
194
195 install-doc:
196 @echo -e "\033[1m== Installing documentation ==\033[0;0m"
197 $(MAKE) -C doc install
198 sed -i -e 's,/etc,$(sysconfdir),' \
199 -e 's,/usr/sbin,$(sbindir),' \
200 -e 's,/usr/share,$(datadir),' \
201 -e 's,/usr/share/doc/packages,$(datadir)/doc,' \
202 $(DESTDIR)$(mandir)/man8/rear.8
203
204 install: validate man install-config install-bin install-data install-var install-doc
205
206 uninstall:
207 @echo -e "\033[1m== Uninstalling Relax-and-Recover ==\033[0;0m"
208 -rm -v $(DESTDIR)$(sbindir)/rear
209 -rm -v $(DESTDIR)$(mandir)/man8/rear.8
210 -rm -rv $(DESTDIR)$(datadir)/rear/
211 # rm -rv $(DESTDIR)$(sysconfdir)/rear/
212 # rm -rv $(DESTDIR)$(localstatedir)/lib/rear/
213
214 dist: clean validate man dist/$(name)-$(distversion).tar.gz
215
216 # most of the sed stuff should be skipped if $(distversion) == $(version)
217 # except RELEASE_DATE= and perhaps the Version in $(dscfile)
218 dist/$(name)-$(distversion).tar.gz: $(DIST_FILES)
219 @echo -e "\033[1m== Building archive $(name)-$(distversion) ==\033[0;0m"
220 rm -Rf $(BUILD_DIR)/$(name)-$(distversion)
221 mkdir -p dist $(BUILD_DIR)/$(name)-$(distversion)
222 tar -c $(tarparams) | tar -C $(BUILD_DIR)/$(name)-$(distversion) -x
223 @echo -e "\033[1m== Rewriting $(BUILD_DIR)/$(name)-$(distversion)/{$(specfile),$(dscfile),$(rearbin)} ==\033[0;0m"
224 sed -i \
225 -e 's#^\(Source0\?\):.*#\1: $(name)-${distversion}.tar.gz#' \
226 -e 's#^Version:.*#Version: $(version)#' \
227 -e 's#^%define rpmrelease.*#%define rpmrelease $(rpmrelease)#' \
228 -e 's#^%setup.*#%setup -q -n $(name)-$(distversion)#' \
229 -e 's#^%\(autosetup.*\)#%\1 -n $(name)-$(distversion)#' \
230 $(BUILD_DIR)/$(effectivespecfile)
231 sed -i \
232 -e 's#^Version:.*#Version: $(version)-$(debrelease)#' \
233 $(BUILD_DIR)/$(name)-$(distversion)/$(dscfile)
234 sed -i \
235 -e 's#^readonly VERSION=.*#readonly VERSION=$(distversion)#' \
236 -e 's#^readonly RELEASE_DATE=.*#readonly RELEASE_DATE="$(release_date)"#' \
237 $(BUILD_DIR)/$(name)-$(distversion)/$(rearbin)
238 tar -czf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR) $(name)-$(distversion)
239
240 # make install from dist tarball, to get a clean install without any build artifacts
241 dist-install: dist/$(name)-$(distversion).tar.gz
242 mkdir -p $(BUILD_DIR)/dist-install
243 tar -C $(BUILD_DIR)/dist-install -xvzf dist/$(name)-$(distversion).tar.gz --strip-components 1
244 $(MAKE) -C $(BUILD_DIR)/dist-install install
245
246 package-clean:
247 rm -f dist/*.rpm dist/*.deb dist/*.pkg.*
248
249 # TODO: It might be better to set BUILD_DIR=/tmp/rear-<packagetype>-$(distversion) to separate
250 # outer build dir from the package build dir, thereby enabling the make clean to also delete
251 # the BUILD_DIR correctly.
252
253 ifneq ($(shell type -p pacman),)
254 package: package-clean pacman
255 else ifneq ($(shell type -p dpkg),)
256 package: package-clean deb
257 else ifneq ($(shell type -p rpm),)
258 package: package-clean rpm
259 else
260 package:
261 $(error Cannot determine package manager)
262 endif
263
264 # Note, older rpm checks file ownership, so we copy dist tarball to build dir first for Docker builds
265 # and we also copy the extracted files to build dir
266 # (tar -x preserves file ownership and with Docker the ownership is wrong, cp resets it)
267 srpm: dist/$(name)-$(distversion).tar.gz
268 @echo -e "\033[1m== Building SRPM package $(name)-$(distversion) ==\033[0;0m"
269 rm -rf $(BUILD_DIR)
270 mkdir -p $(BUILD_DIR)
271 cp dist/$(name)-$(distversion).tar.gz $(BUILD_DIR)/
272 tar -xz -C $(BUILD_DIR)/ -f dist/$(name)-$(distversion).tar.gz $(dir $(effectivespecfile))
273 cp $(BUILD_DIR)/$(dir $(effectivespecfile))/* $(BUILD_DIR)/
274 if test "$(savedspecfile)"; then cp $(BUILD_DIR)/$(notdir $(effectivespecfile)) "$(savedspecfile)"; fi
275 rpmbuild -bs --clean --nodeps \
276 --define="_sourcedir $(BUILD_DIR)/" \
277 --define="_srcrpmdir $(CURDIR)/dist" \
278 $(rpmdefines) \
279 $(BUILD_DIR)/$(notdir $(effectivespecfile))
280
281 # Temporary file passed to 'srpm', where the spec file will be available
282 # even after removing BUILD_DIR
283 rpm: savedspecfile := $(shell mktemp --suffix .spec)
284 # uniq because if we ever use subpackages, there will be multiple identical lines, one per each subpackage
285 # the rpmspec tool with --srpm would be preferable - it queries the source RPM information,
286 # but unfortunately it does not exist yet on EL6.
287 rpm: NEVR = $(name)-$(shell rpm -q $(rpmdefines) --queryformat '%{EVR}' --specfile "$(savedspecfile)" | uniq)
288 rpm: srpm
289 @echo -e "\033[1m== Building RPM package $(NEVR) ==\033[0;0m"
290 rpmbuild --rebuild --clean \
291 --define="_rpmdir $(CURDIR)/dist" \
292 --define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
293 $(rpmdefines) \
294 dist/$(NEVR).src.rpm
295 rm -f $(savedspecfile)
296
297 deb: dist/$(name)-$(distversion).tar.gz
298 @echo -e "\033[1m== Building DEB package $(name)-$(distversion) ==\033[0;0m"
299 rm -rf $(BUILD_DIR)
300 mkdir -p $(BUILD_DIR)
301 tar -C $(BUILD_DIR) -xzf dist/$(name)-$(distversion).tar.gz
302 cd $(BUILD_DIR)/$(name)-$(distversion) ; mv packaging/debian/ .
303 cd $(BUILD_DIR)/$(name)-$(distversion) ; dch -v $(distversion) -b -M $(BUILD_DIR) package
304 cd $(BUILD_DIR)/$(name)-$(distversion) ; debuild -us -uc -i -b --lintian-opts --profile debian
305 mv $(BUILD_DIR)/$(name)_*.deb dist/
306
307 pacman: BUILD_DIR = /tmp/rear-$(distversion)
308 pacman: dist/$(name)-$(distversion).tar.gz
309 @echo -e "\033[1m== Building Pacman package $(name)-$(distversion) ==\033[0;0m"
310 rm -rf $(BUILD_DIR)
311 mkdir -p $(BUILD_DIR)
312 cp packaging/arch/PKGBUILD.local $(BUILD_DIR)/PKGBUILD
313 cp dist/$(name)-$(distversion).tar.gz $(BUILD_DIR)/
314 cd $(BUILD_DIR) ; \
315 sed -i -e 's/VERSION/$(date)/' \
316 -e 's/SOURCE/$(name)-$(distversion).tar.gz/' \
317 -e 's/MD5SUM/$(shell md5sum dist/$(name)-$(distversion).tar.gz | cut -d' ' -f1)/' \
318 PKGBUILD ; \
319 chmod -R o+rwX . ; ls -l ; \
320 $(RUNASUSER) makepkg -c
321 cp $(BUILD_DIR)/*.pkg.* dist/
322 rm -rf $(BUILD_DIR)
323
324 obs: BUILD_DIR = /tmp/rear-$(distversion)
325 obs: obsname = $(shell osc ls $(obsproject) $(obspackage) | awk '/.tar.gz$$/ { gsub(".tar.gz$$","",$$1); print }')
326 obs: dist/$(name)-$(distversion).tar.gz
327 @echo -e "\033[1m== Updating OBS from $(obsname) to $(name)-$(distversion)== \033[0;0m"
328 ifneq ($(obsname),$(name)-$(distversion))
329 -rm -rf $(BUILD_DIR)
330 mkdir -p $(BUILD_DIR)
331 ifneq ($(OFFICIAL),)
332 # osc rdelete -m 'Recreating branch $(obspackage)' $(obsproject) $(obspackage)
333 -osc branch Archiving:Backup:Rear:Snapshot rear $(obsproject) $(obspackage)
334 -osc detachbranch $(obsproject) $(obspackage)
335 endif
336 (cd $(BUILD_DIR) ; osc co -c $(obsproject) $(obspackage) )
337 -(cd $(BUILD_DIR)/$(obspackage) ; osc del *.tar.gz )
338 cp dist/$(name)-$(distversion).tar.gz $(BUILD_DIR)/$(obspackage)
339 tar -xOzf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/$(specfile) >$(BUILD_DIR)/$(obspackage)/$(name).spec
340 tar -xOzf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/$(dscfile) >$(BUILD_DIR)/$(obspackage)/$(name).dsc
341 tar -xOzf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/control >$(BUILD_DIR)/$(obspackage)/debian.control
342 tar -xOzf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/rules >$(BUILD_DIR)/$(obspackage)/debian.rules
343 echo -e "rear ($(version)-$(debrelease)) stable; urgency=low\n\n * new snapshot build\n\n -- openSUSE Build Service <[email protected]> $$(date -R)" >$(BUILD_DIR)/$(obspackage)/debian.changelog
344 tar -xOzf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/changelog >>$(BUILD_DIR)/$(obspackage)/debian.changelog
345 tar -xOzf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/compat >>$(BUILD_DIR)/$(obspackage)/debian.compat
346 tar -xOzf dist/$(name)-$(distversion).tar.gz -C $(BUILD_DIR)/$(obspackage) $(name)-$(distversion)/packaging/debian/copyright >>$(BUILD_DIR)/$(obspackage)/debian.copyright
347 cd $(BUILD_DIR)/$(obspackage); osc addremove
348 cd $(BUILD_DIR)/$(obspackage); osc ci -m "Update to $(name)-$(distversion)" $(BUILD_DIR)/$(obspackage)
349 rm -rf $(BUILD_DIR)
350 @echo -e "\033[1mNow visit https://build.opensuse.org/package/show?package=rear&project=$(obsproject)"
351 @echo -e "or inspect the queue at: https://build.opensuse.org/monitor\033[0;0m"
352 else
353 @echo -e "OBS already updated to this release."
354 endif