-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (70 loc) · 2.63 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
CURL ?= $(shell if test -f /usr/bin/curl ; then echo "curl -H Pragma: -O -R -S --fail --show-error" ; fi)
WGET ?= $(shell if test -f /usr/bin/wget ; then echo "wget -nd -m" ; fi)
CLIENT ?= $(if $(CURL),$(CURL),$(if $(WGET),$(WGET)))
AWK = awk
MD5SUM = md5sum
SED = sed
SPECFILE = kernel-2.6.spec
# Thierry - when called from within the build, PWD is /build
PWD=$(shell pwd)
# get nevr from specfile.
ifndef NAME
NAME := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{NAME}\n" --specfile $(SPECFILE) | head -1)
endif
ifndef EPOCH
EPOCH := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{EPOCH}\n" --specfile $(SPECFILE) | head -1 | sed 's/(none)//')
endif
ifeq ($(EPOCH),(none))
override EPOCH := ""
endif
ifndef VERSION
VERSION := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
endif
ifndef RELEASE
RELEASE := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
endif
define get_sources_md5
$(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$1; exit; }')
endef
define get_sources_url
$(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$2; exit; }')
endef
SOURCEFILES := $(shell cat sources 2>/dev/null | awk '{ print gensub("^.*/", "", 1, $$2) }')
sources: $(SOURCEFILES) $(TARGETS)
$(SOURCEFILES): #FORCE
@if [ ! -e "$@" ] ; then echo "$(CLIENT) $(get_sources_url)" ; $(CLIENT) $(get_sources_url) ; fi
@if [ ! -e "$@" ] ; then echo "Could not download source file: $@ does not exist" ; exit 1 ; fi
@if test "$$(md5sum $@ | awk '{print $$1}')" != "$(get_sources_md5)" ; then \
echo "md5sum of the downloaded $@ does not match the one from 'sources' file" ; \
echo "Local copy: $$(md5sum $@)" ; \
echo "In sources: $$(grep $@ sources)" ; \
exit 1 ; \
else \
ls -l $@ ; \
fi
download-sources:
@for i in $(SOURCES); do \
if [ ! -e "$${i##*/}" ]; then \
echo "$(CLIENT) $$i"; \
$(CLIENT) $$i; \
fi; \
done
replace-sources:
rm -f sources
@$(MAKE) new-sources
new-sources: download-sources
@for i in $(SOURCES); do \
echo "$(MD5SUM) $$i >> sources"; \
$(MD5SUM) $${i##*/} | $(AWK) '{ printf "%s %s\n", $$1, "'"$$i"'" }' >> sources; \
done
PREPARCH ?= noarch
RPMDIRDEFS = --define "_sourcedir $(PWD)" --define "_builddir $(PWD)" --define "_srcrpmdir $(PWD)" --define "_rpmdir $(PWD)"
trees: sources
rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bp --target $(PREPARCH) $(SPECFILE)
srpm: sources
rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bs $(SPECFILE)
TARGET ?= $(shell uname -m)
rpm: sources
rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps --target $(TARGET) -bb $(SPECFILE)
clean:
rm -f *.rpm