A hack to get ApplyPatch working.
[linux-3.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 RPMBUILDOPT = --without tools --without debug --without debuginfo
9 # this is passed on the command line as the full path to <build>/SPECS/kernel.spec
10 SPECFILE = kernel-3.1.spec
11
12 # Thierry - when called from within the build, PWD is /build
13 PWD=$(shell pwd)
14
15 # get nevr from specfile.
16 ifndef NAME
17 NAME := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{NAME}\n" --specfile $(SPECFILE) | head -1)
18 endif
19 ifndef EPOCH
20 EPOCH := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{EPOCH}\n" --specfile $(SPECFILE) | head -1 | sed 's/(none)//')
21 endif
22 ifeq ($(EPOCH),(none))
23 override EPOCH := ""
24 endif
25 ifndef VERSION
26 VERSION := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
27 endif
28 ifndef RELEASE
29 RELEASE := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
30 endif
31
32 define get_sources_sha1
33 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$1; exit; }')
34 endef
35 define get_sources_url1
36 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$2; exit; }')
37 endef
38 define get_sources_url2
39 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$3; exit; }')
40 endef
41 SOURCEFILES := $(shell cat sources 2>/dev/null | awk '{ print gensub("^.*/", "", 1, $$2) }')
42 SOURCE_RPM := $(firstword $(SOURCEFILES))
43
44 sources: $(SOURCEFILES) $(TARGETS)
45
46 $(SOURCEFILES): #FORCE
47         @if [ ! -e "$@" ] ; then \
48          { echo Using primary; echo "$(CLIENT) $(get_sources_url1)" ; $(CLIENT) $(get_sources_url1) ; } || \
49          { echo Using secondary; echo "$(CLIENT) $(get_sources_url2)" ; $(CLIENT) $(get_sources_url2) ; } ; fi
50         @if [ ! -e "$@" ] ; then echo "Could not download source file: $@ does not exist" ; exit 1 ; fi
51         @if test "$$(sha1sum $@ | awk '{print $$1}')" != "$(get_sources_sha1)" ; then \
52             echo "sha1sum of the downloaded $@ does not match the one from 'sources' file" ; \
53             echo "Local copy: $$(sha1sum $@)" ; \
54             echo "In sources: $$(grep $@ sources)" ; \
55             exit 1 ; \
56         else \
57             ls -l $@ ; \
58         fi
59
60 download-sources:
61         @for i in $(SOURCES); do \
62                 if [ ! -e "$${i##*/}" ]; then \
63                         echo "$(CLIENT) $$i"; \
64                         $(CLIENT) $$i; \
65                 fi; \
66         done
67
68 replace-sources:
69         rm -f sources
70         @$(MAKE) new-sources
71
72 new-sources: download-sources
73         @for i in $(SOURCES); do \
74                 echo "$(SHA1SUM) $$i >> sources"; \
75                 $(SHA1SUM) $${i##*/} | $(AWK) '{ printf "%s  %s\n", $$1, "'"$$i"'" }' >> sources; \
76         done
77
78 PREPARCH ?= noarch
79 RPMDIRDEFS = --define "_sourcedir $(PWD)/SOURCES" --define "_builddir $(PWD)" --define "_srcrpmdir $(PWD)" --define "_rpmdir $(PWD)"
80 trees: sources
81         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) $(RPMBUILDOPT) --nodeps -bp --target $(PREPARCH) $(SPECFILE)
82
83 # use the stock source rpm, unwrap it,
84 # copy the downloaded material
85 # install our own specfile and patched patches
86 # and patch configs for IPV6
87 # then rewrap with rpm
88 srpm: sources
89         mkdir -p SOURCES SRPMS
90         (cd SOURCES; rpm2cpio ../$(SOURCE_RPM) | cpio -diu; \
91          cp ../$(notdir $(SPECFILE)) . ; cp ../linux-*.patch .; cp ../config-planetlab .; \
92          for downloaded in $(SOURCEFILES) ; do cp ../$$downloaded . ; done ; \
93          cat config-planetlab >> config-generic)
94         ./rpmmacros.sh
95         export HOME=$(shell pwd) ; rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bs $(SPECFILE)
96
97 TARGET ?= $(shell uname -m)
98 rpm: sources
99         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) $(RPMBUILDOPT) --nodeps --target $(TARGET) -bb $(SPECFILE)
100
101 whipe: clean
102         rm -f *.rpm
103         rm -rf kernel-3.1.fc14
104         rm -rf x86_64
105
106 clean:
107         rm -f kernel-3.1.0-8.planetlab.fc14.src.rpm
108         rm -rf BUILDROOT SOURCES SPECS SRPMS tmp