Setting tag linux-2.6-22-50
[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.spec
9
10 # Thierry - when called from within the build, PWD is /build
11 PWD=$(shell pwd)
12
13 # get nevr from specfile.
14 ifndef NAME
15 NAME := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{NAME}\n" --specfile $(SPECFILE) | head -1)
16 endif
17 ifndef EPOCH
18 EPOCH := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{EPOCH}\n" --specfile $(SPECFILE) | head -1 | sed 's/(none)//')
19 endif
20 ifeq ($(EPOCH),(none))
21 override EPOCH := ""
22 endif
23 ifndef VERSION
24 VERSION := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
25 endif
26 ifndef RELEASE
27 RELEASE := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
28 endif
29
30 define get_sources_md5
31 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$1; exit; }')
32 endef
33 define get_sources_url
34 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$2; exit; }')
35 endef
36 SOURCEFILES := $(shell cat sources 2>/dev/null | awk '{ print gensub("^.*/", "", 1, $$2) }')
37
38 sources: $(SOURCEFILES) $(TARGETS)
39
40 $(SOURCEFILES): #FORCE
41         @if [ ! -e "$@" ] ; then echo "$(CLIENT) $(get_sources_url)" ; $(CLIENT) $(get_sources_url) ; fi
42         @if [ ! -e "$@" ] ; then echo "Could not download source file: $@ does not exist" ; exit 1 ; fi
43         @if test "$$(md5sum $@ | awk '{print $$1}')" != "$(get_sources_md5)" ; then \
44             echo "md5sum of the downloaded $@ does not match the one from 'sources' file" ; \
45             echo "Local copy: $$(md5sum $@)" ; \
46             echo "In sources: $$(grep $@ sources)" ; \
47             exit 1 ; \
48         else \
49             ls -l $@ ; \
50         fi
51
52 download-sources:
53         @for i in $(SOURCES); do \
54                 if [ ! -e "$${i##*/}" ]; then \
55                         echo "$(CLIENT) $$i"; \
56                         $(CLIENT) $$i; \
57                 fi; \
58         done
59
60 replace-sources:
61         rm -f sources
62         @$(MAKE) new-sources
63
64 new-sources: download-sources
65         @for i in $(SOURCES); do \
66                 echo "$(MD5SUM) $$i >> sources"; \
67                 $(MD5SUM) $${i##*/} | $(AWK) '{ printf "%s  %s\n", $$1, "'"$$i"'" }' >> sources; \
68         done
69
70 PREPARCH ?= noarch
71 RPMDIRDEFS = --define "_sourcedir $(PWD)" --define "_builddir $(PWD)" --define "_srcrpmdir $(PWD)" --define "_rpmdir $(PWD)"
72 trees: sources
73         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bp --target $(PREPARCH) $(SPECFILE)
74
75 srpm: sources
76         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bs $(SPECFILE)
77
78 TARGET ?= $(shell uname -m)
79 rpm: sources
80         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps --target $(TARGET) -bb $(SPECFILE)
81
82 clean:
83         rm -f *.rpm