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