-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
117 lines (96 loc) · 3.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
pkgname := bazel
spec ?= $(pkgname).spec
pwd := $(shell pwd)
NAME := $(shell rpmspec -q --qf "%{name}" $(spec) || grep '^Name:' ./bazel.spec | awk '{ print $$2 }')
VERSION := $(shell rpmspec -q --qf "%{version}" $(spec) || grep '^Version:' ./bazel.spec | awk '{ print $$2 }')
RELEASE := $(shell rpmspec -q --qf "%{release}" $(spec) || echo 0)
NVR := $(NAME)-$(VERSION)-$(RELEASE)
outdir ?= $(pwd)
FED_VER ?= latest
RELEASE_ID = $(shell grep '^ID=' /etc/*release | cut -d = -f 2 | tr -d \")
SUDO =
ifneq ($(shell id -u),0)
SUDO = sudo
endif
default: rpm
all: rpm srpm
version:
@echo "v$(VERSION)-$(RELEASE)"
name:
@echo $(NVR)
@echo " NAME: $(NAME)"
@echo " VERSION: $(VERSION)"
@echo " RELEASE: $(RELEASE)"
rpm: .deps.$(RELEASE_ID) .builddep.$(RELEASE_ID)
rpmbuild \
--define '_sourcedir $(pwd)' \
--define '_specdir $(pwd)' \
--define '_builddir $(pwd)' \
--define '_srcrpmdir $(outdir)' \
--define '_rpmdir $(outdir)' \
-bb ./$(spec)
srpm: $(NVR).src.rpm
new-version: $(spec)
sed -ie 's/^Version:.*$$/Version: $(VERSION)/g' $(spec)
# https://developer.fedoraproject.org/deployment/copr/copr-cli.html
copr: $(NVR).src.rpm
copr-cli build bazel $(NVR).src.rpm
$(NVR).src.rpm: .deps.$(RELEASE_ID) $(spec) $(wildcard *.diff)
rpmbuild \
--define '_sourcedir $(pwd)' \
--define '_specdir $(pwd)' \
--define '_builddir $(pwd)' \
--define '_srcrpmdir $(outdir)' \
--define '_rpmdir $(outdir)' \
--nodeps \
-bs ./$(spec)
rpmbuild:
mkdir -p $@
container.$(FED_VER): .container.$(FED_VER)
.container.$(FED_VER): bazel.spec Makefile Dockerfile
docker build -t bazel-build-v$(VERSION)-$(RELEASE) --build-arg fed_ver=$(FED_VER) . && touch $@
container.run: .container.run
PHONY: .container.run
.container.run: .container.$(FED_VER) rpmbuild
docker run -it --rm \
-v $(HOME)/.config/copr:/root/.config/copr:ro \
-v $(pwd)/rpmbuild:/root/rpmbuild \
bazel-build-v$(VERSION)-$(RELEASE) bash -l
container.rebuild: .container.rebuild
.container.rebuild: .container.$(FED_VER) rpmbuild
docker run -it --rm \
-v $(HOME)/.config/copr:/root/.config/copr:ro \
-v $(pwd)/rpmbuild:/root/rpmbuild \
bazel-build-v$(VERSION)-$(RELEASE) make rebuild && touch $@
container.copr: .container.copr
.container.copr: .container.$(FED_VER) rpmbuild
docker run -it --rm \
-v $(HOME)/.config/copr:/root/.config/copr:ro \
-v $(pwd)/rpmbuild:/root/rpmbuild \
bazel-build-v$(VERSION)-$(RELEASE) make copr && touch $@
.deps.$(RELEASE_ID):
ifeq ($(RELEASE_ID),centos)
$(SUDO) yum install -y yum-utils rpm-build && touch $@
endif
ifeq ($(RELEASE_ID),pop)
$(SUDO) dnf install -y 'dnf-command(builddep)' rpm-build && touch $@
endif
ifeq ($(RELEASE_ID),pop)
$(SUDO) apt install -y 'rpm' && touch $@
endif
ifeq ($(RELEASE_ID),debian)
$(SUDO) apt install -y 'rpm' && touch $@
endif
ifeq ($(RELEASE_ID),ubuntu)
$(SUDO) apt install -y 'rpm' && touch $@
endif
.builddep.$(RELEASE_ID): $(spec)
ifeq ($(RELEASE_ID),centos)
$(SUDO) yum-builddep -y $< && touch $@
else
$(SUDO) dnf builddep -y $< && touch $@
endif
rebuild: .deps.$(RELEASE_ID) .builddep.$(RELEASE_ID) $(NVR).src.rpm
rpmbuild --rebuild $(NVR).src.rpm
clean:
rm -rf *~ *.rpm noarch .builddep.$(RELEASE_ID) .deps.$(RELEASE_ID) $(shell uname -m)/ $(NAME)-$(VERSION)/ .container*