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