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