first draft for a plain f12 kernel
[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 SHA1SUM = sha1sum
6 SED     = sed
7
8 SPECFILE = kernel.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_sha1
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 SOURCE_RPM := $(firstword $(SOURCEFILES))
38
39 sources: $(SOURCEFILES) $(TARGETS)
40
41 $(SOURCEFILES): #FORCE
42         @if [ ! -e "$@" ] ; then echo "$(CLIENT) $(get_sources_url)" ; $(CLIENT) $(get_sources_url) ; fi
43         @if [ ! -e "$@" ] ; then echo "Could not download source file: $@ does not exist" ; exit 1 ; fi
44         @if test "$$(sha1sum $@ | awk '{print $$1}')" != "$(get_sources_sha1)" ; then \
45             echo "sha1sum of the downloaded $@ does not match the one from 'sources' file" ; \
46             echo "Local copy: $$(sha1sum $@)" ; \
47             echo "In sources: $$(grep $@ sources)" ; \
48             exit 1 ; \
49         else \
50             ls -l $@ ; \
51         fi
52
53 download-sources:
54         @for i in $(SOURCES); do \
55                 if [ ! -e "$${i##*/}" ]; then \
56                         echo "$(CLIENT) $$i"; \
57                         $(CLIENT) $$i; \
58                 fi; \
59         done
60
61 replace-sources:
62         rm -f sources
63         @$(MAKE) new-sources
64
65 new-sources: download-sources
66         @for i in $(SOURCES); do \
67                 echo "$(SHA1SUM) $$i >> sources"; \
68                 $(SHA1SUM) $${i##*/} | $(AWK) '{ printf "%s  %s\n", $$1, "'"$$i"'" }' >> sources; \
69         done
70
71 PREPARCH ?= noarch
72 RPMDIRDEFS = --define "_sourcedir $(PWD)" --define "_builddir $(PWD)" --define "_srcrpmdir $(PWD)" --define "_rpmdir $(PWD)"
73 trees: sources
74         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bp --target $(PREPARCH) $(SPECFILE)
75
76 # use the stock source rpm, unwrap it,
77 # install our own specfile and patched patches
78 # and patch configs for IPV6
79 # then rewrap with rpm
80 srpm: sources
81         mkdir SOURCES SRPMS
82         (cd SOURCES; rpm2cpio ../$(SOURCE_RPM) | cpio -diu; \
83          cp ../$(SPECFILE) . ; cp ../linux*.patch . ; \
84          sed -i -e s,CONFIG_IPV6=m,CONFIG_IPV6=y, config-generic)
85         ./rpmmacros.sh
86         export HOME=$(shell pwd) ; rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bs SOURCES/$(SPECFILE)
87         cp $(SOURCE_RPM) $(EXPECTED_SRPM)
88
89 TARGET ?= $(shell uname -m)
90 rpm: sources
91         rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps --target $(TARGET) -bb $(SPECFILE)
92
93 clean:
94         rm -f *.rpm
95