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