tweaks for rebuilding pre3004
[util-vserver.git] / Makefile
1 #
2 CURL    ?= $(shell if test -f /usr/bin/curl ; then echo "curl -H Pragma: -O -R -S --fail --show-error" ; fi)
3 WGET    ?= $(shell if test -f /usr/bin/wget ; then echo "wget -nd -m" ; fi)
4 CLIENT  ?= $(if $(CURL),$(CURL),$(if $(WGET),$(WGET)))
5 AWK     = awk
6 SHA1SUM = sha1sum
7 SED     = sed
8
9 SPECFILE = kernel.spec
10
11 # Thierry - when called from within the build, PWD is /build
12 PWD=$(shell pwd)
13
14 # get nevr from specfile.
15 ifndef NAME
16 NAME := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{NAME}\n" --specfile $(SPECFILE) | head -1)
17 endif
18 ifndef EPOCH
19 EPOCH := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{EPOCH}\n" --specfile $(SPECFILE) | head -1 | sed 's/(none)//')
20 endif
21 ifeq ($(EPOCH),(none))
22 override EPOCH := ""
23 endif
24 ifndef VERSION
25 VERSION := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
26 endif
27 ifndef RELEASE
28 RELEASE := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
29 endif
30
31 define get_sources_sha1
32 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$1; exit; }')
33 endef
34 define get_sources_url
35 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$2; exit; }')
36 endef
37 SOURCEFILES := $(shell cat sources 2>/dev/null | awk '{ print gensub("^.*/", "", 1, $$2) }')
38 SOURCE_RPM := $(firstword $(SOURCEFILES))
39
40 sources: $(SOURCEFILES) $(TARGETS)
41
42 $(SOURCEFILES): #FORCE
43         @if [ ! -e "$@" ] ; then echo "$(CLIENT) $(get_sources_url)" ; $(CLIENT) $(get_sources_url) ; fi
44         @if [ ! -e "$@" ] ; then echo "Could not download source file: $@ does not exist" ; exit 1 ; fi
45         @if test "$$(sha1sum $@ | awk '{print $$1}')" != "$(get_sources_sha1)" ; then \
46             echo "sha1sum of the downloaded $@ does not match the one from 'sources' file" ; \
47             echo "Local copy: $$(sha1sum $@)" ; \
48             echo "In sources: $$(grep $@ sources)" ; \
49             exit 1 ; \
50         else \
51             ls -l $@ ; \
52         fi
53
54 download-sources:
55         @for i in $(SOURCES); do \
56                 if [ ! -e "$${i##*/}" ]; then \
57                         echo "$(CLIENT) $$i"; \
58                         $(CLIENT) $$i; \
59                 fi; \
60         done
61
62 replace-sources:
63         rm -f sources
64         @$(MAKE) new-sources
65
66 new-sources: download-sources
67         @for i in $(SOURCES); do \
68                 echo "$(SHA1SUM) $$i >> sources"; \
69                 $(SHA1SUM) $${i##*/} | $(AWK) '{ printf "%s  %s\n", $$1, "'"$$i"'" }' >> sources; \
70         done
71
72 PREPARCH ?= noarch
73 RPMDIRDEFS = --define "_sourcedir $(PWD)" --define "_builddir $(PWD)" --define "_srcrpmdir $(PWD)" --define "_rpmdir $(PWD)"
74 trees: sources
75         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bp --target $(PREPARCH) $(SPECFILE)
76
77 # use the stock source rpm, unwrap it,
78 # install our own specfile and patched patches
79 # and patch configs for IPV6
80 # then rewrap with rpm
81 srpm: sources
82         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bs $(SPECFILE)
83
84 TARGET ?= $(shell uname -m)
85 rpm: sources
86         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps --target $(TARGET) -bb $(SPECFILE)
87
88 clean:
89         rm -f *.rpm
90