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)))
9 # TD 21.03.2014: Using "--with baseonly" to avoid building all the special variants.
10 RPMBUILDOPT = --with baseonly --without tools --without debug --without debuginfo
11 # this is passed on the command line as the full path to <build>/SPECS/kernel.spec
13 SPECFILE = kernel.spec
15 # Thierry - when called from within the build, PWD is /build
18 # get nevr from specfile.
20 NAME := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{NAME}\n" --specfile $(SPECFILE) | head -1)
23 EPOCH := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{EPOCH}\n" --specfile $(SPECFILE) | head -1 | sed 's/(none)//')
25 ifeq ($(EPOCH),(none))
29 VERSION := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{VERSION}\n" --specfile $(SPECFILE)| head -1)
32 RELEASE := $(shell rpm $(RPMDEFS) $(DISTDEFS) -q --qf "%{RELEASE}\n" --specfile $(SPECFILE)| head -1)
35 define get_sources_sha1
36 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$1; exit; }')
38 define get_sources_url1
39 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$2; exit; }')
41 define get_sources_url2
42 $(shell cat sources 2>/dev/null | awk 'gensub("^.*/", "", 1, $$2) == "$@" { print $$3; exit; }')
44 SOURCEFILES := $(shell cat sources 2>/dev/null | awk '{ print gensub("^.*/", "", 1, $$2) }')
45 SOURCE_RPM := $(firstword $(SOURCEFILES))
47 sources: $(SOURCEFILES) $(TARGETS)
49 $(SOURCEFILES): #FORCE
50 @if [ ! -e "$@" ] ; then \
51 { echo Using primary; echo "$(CLIENT) $(get_sources_url1)" ; $(CLIENT) $(get_sources_url1) ; } || \
52 { echo Using secondary; echo "$(CLIENT) $(get_sources_url2)" ; $(CLIENT) $(get_sources_url2) ; } ; fi
53 @if [ ! -e "$@" ] ; then echo "Could not download source file: $@ does not exist" ; exit 1 ; fi
54 @if test "$$(sha1sum $@ | awk '{print $$1}')" != "$(get_sources_sha1)" ; then \
55 echo "sha1sum of the downloaded $@ does not match the one from 'sources' file" ; \
56 echo "Local copy: $$(sha1sum $@)" ; \
57 echo "In sources: $$(grep $@ sources)" ; \
64 @for i in $(SOURCES); do \
65 if [ ! -e "$${i##*/}" ]; then \
66 echo "$(CLIENT) $$i"; \
75 new-sources: download-sources
76 @for i in $(SOURCES); do \
77 echo "$(SHA1SUM) $$i >> sources"; \
78 $(SHA1SUM) $${i##*/} | $(AWK) '{ printf "%s %s\n", $$1, "'"$$i"'" }' >> sources; \
81 # TD 21.03.2014: Needs to define _specdir. Otherwise, the spec file is not found.
82 # This triggers "patch xxxxx not listed as a source patch in specfile",
83 # since the specfile cannot be opened by "grep".
84 # TD 21.03.2014: The spec file relies on "bash" for regexp and "[[". Set it by _buildshell.
87 --define "_specdir $(PWD)" \
88 --define "_sourcedir $(PWD)/SOURCES" \
89 --define "_builddir $(PWD)" \
90 --define "_srcrpmdir $(PWD)" \
91 --define "_rpmdir $(PWD)" \
92 --define "_buildshell /bin/bash"
94 rpmbuild $(RPMDIRDEFS) $(RPMDEFS) $(RPMBUILDOPT) --nodeps -bp --target $(PREPARCH) $(SPECFILE)
96 # use the stock source rpm, unwrap it,
97 # copy the downloaded material
98 # install our own specfile and patched patches
99 # and patch configs for IPV6
100 # then rewrap with rpm
102 mkdir -p SOURCES SRPMS
103 (cd SOURCES; rpm2cpio ../$(SOURCE_RPM) | cpio -diu; \
104 cp ../$(notdir $(SPECFILE)) . ; cp ../*.patch .; cp ../config-planetlab .; \
105 for downloaded in $(SOURCEFILES) ; do cp ../$$downloaded . ; done ; \
106 cat config-planetlab >> config-generic)
108 export HOME=$(shell pwd) ; rpmbuild $(RPMDIRDEFS) $(RPMDEFS) --nodeps -bs $(SPECFILE)
110 TARGET ?= $(shell uname -m)
112 rpmbuild $(RPMDIRDEFS) $(RPMDEFS) $(RPMBUILDOPT) --nodeps --target $(TARGET) -bb $(SPECFILE)
122 rm -f kernel-*.src.rpm
123 rm -rf BUILDROOT SOURCES SPECS SRPMS tmp