-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
104 lines (88 loc) · 2.92 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
pkgname := BuildSourceImage
CTR_IMAGE := localhost/containers/buildsourceimage
CTR_ENGINE ?= podman
BATS_OPTS ?=
cleanfiles =
# these are packages whose src.rpms are very small
srpm_urls = \
https://archive.kernel.org/centos-vault/7.0.1406/os/Source/SPackages/basesystem-10.0-7.el7.centos.src.rpm \
https://archive.kernel.org/centos-vault/7.0.1406/os/Source/SPackages/rootfiles-8.1-11.el7.src.rpm \
https://archive.kernel.org/centos-vault/7.0.1406/os/Source/SPackages/centos-bookmarks-7-1.el7.src.rpm
srpms = $(addprefix ./.testprep/srpms/,$(notdir $(rpms)))
spec := $(pkgname).spec
cwd := $(shell dirname $(shell realpath $(spec)))
NAME = $(pkgname)
ifeq (,$(shell command -v git))
gitcommit := HEAD
gitdate := $(shell date +%s)
else
gitcommit := $(shell git rev-parse --verify HEAD)
gitdate := $(shell git log -1 --pretty=format:%ct $(gitcommit))
endif
VERSION := 0.2.0
RELEASE = $(shell rpmspec -q --qf "%{release}" $(spec) 2>/dev/null)
ARCH = $(shell rpmspec -q --qf "%{arch}" $(spec) 2>/dev/null)
NVR = $(NAME)-$(VERSION)-$(RELEASE)
outdir ?= $(cwd)
SHELL_SRC := ./BuildSourceImage.sh
DIST_FILES := \
$(SHELL_SRC) \
LICENSE \
layout.md \
README.md
export CTR_IMAGE
export CTR_ENGINE
all: validate
validate: .validate
cleanfiles += .validate
.validate: $(SHELL_SRC)
shellcheck $(SHELL_SRC) && touch $@
build-container: .build-container
cleanfiles += .build-container
.build-container: .validate Dockerfile $(SHELL_SRC)
@echo
@echo "==> Building BuildSourceImage Container"
$(CTR_ENGINE) build --quiet --file Dockerfile --tag $(CTR_IMAGE) . && touch $@
cleanfiles += .testprep $(srpms)
.testprep:
@echo "==> Fetching SRPMs for testing against"
mkdir -p $@/{srpms,tmp}
wget -P $@/srpms/ $(srpm_urls)
.PHONY: test-integration
test-integration: .build-container .testprep
@echo
@echo "==> Running integration tests"
TMPDIR=$(realpath .testprep/tmp) bats $(BATS_OPTS) test/
.PHONY: srpm
srpm: $(NVR).src.rpm
@echo $^
.PHONY: $(spec)
cleanfiles += $(spec)
$(spec): $(spec).in
sed \
's/MYVERSION/$(VERSION)/g; s/GITCOMMIT/$(gitcommit)/g; s/TIMESTAMP/$(gitdate)/g' \
$(spec).in > $(spec)
cleanfiles += $(NVR).src.rpm
$(NVR).src.rpm: $(spec) $(DIST_FILES)
rpmbuild \
--define '_sourcedir $(cwd)' \
--define '_specdir $(cwd)' \
--define '_builddir $(cwd)' \
--define '_srcrpmdir $(outdir)' \
--define '_rpmdir $(outdir)' \
--nodeps \
-bs $(spec)
.PHONY: rpm
rpm: $(ARCH)/$(NVR).$(ARCH).rpm
@echo $^
cleanfiles += $(ARCH)/$(NVR).$(ARCH).rpm
$(ARCH)/$(NVR).$(ARCH).rpm: $(spec) $(DIST_FILES)
rpmbuild \
--define '_sourcedir $(cwd)' \
--define '_specdir $(cwd)' \
--define '_builddir $(cwd)' \
--define '_srcrpmdir $(outdir)' \
--define '_rpmdir $(outdir)' \
-bb ./$(spec)
clean:
if [ -n "$(cleanfiles)" ] ; then rm -rf $(cleanfiles) ; fi