1 SPECFILE := $(PACKAGE).spec
2 SPECFILE_FILELIST := /^%files/,/^%pre/s,^%attr.*/\([^/]*\),\1,p
3 FILES := $(shell sed -ne '$(SPECFILE_FILELIST)' $(SPECFILE))
4 VERSION := $(shell sed -ne 's/^Version: \(.*\)/\1/p' $(SPECFILE))
5 RELEASE := $(shell sed -ne 's/^Release: \(.*\)/\1/p' $(SPECFILE))
6 NAME := $(PACKAGE)-$(VERSION)
7 FULLNAME := $(NAME)-$(RELEASE)
8 TARBALL := $(FULLNAME).tar.gz
9 RPM_BUILDDIR := .rpmbuild
13 # we have to jump through hoops to make RPM work nicely
15 RPM_RC_SYS := /usr/lib/rpm/rpmrc:$(wildcard /usr/lib/rpm/redhat/rpmrc)
16 RPM_RC_USER := $(wildcard $(HOME)/.rpmrc)
17 RPM_RC_LOCAL := .rpmrc
18 RPM_RCFILES := $(subst ::,:,$(RPM_RC_SYS):$(RPM_RC_LOCAL):$(RPM_RC_USER))
20 # ask RPM what architecture it will build for
21 ARCH := $(shell rpm --showrc | sed -ne 's/^build arch.*: *\(.*\)/\1/p')
23 # find out what the standard list of macro files is
24 RPM_MACROS_SYS := $(shell rpm --showrc | \
25 sed -ne 's,^macrofiles[^:]*: \(.*\):~.*,\1,p')
26 RPM_MACROS_LOCAL := .rpmmacros
27 RPM_MACROS_USER := $(wildcard $(HOME)/.rpmmacros)
28 RPM_MACROFILES := $(RPM_MACROS_SYS):$(RPM_MACROS_LOCAL):$(RPM_MACROS_USER)
30 LOCALFILES := $(RPM_RC_LOCAL) $(RPM_MACROS_LOCAL) $(RPM_BUILDDIR)
32 RPMFILE := $(FULLNAME).$(ARCH).rpm
37 # the idiosyncracies of RPM building require that the tarball has files
38 # located in directory $(NAME), not $(FULLNAME)
42 @[ -d $(NAME) ] || ln -s . $(NAME)
43 @tar czvf $(TARBALL) $(addprefix $(NAME)/,$^)
48 $(RPMFILE): $(TARBALL) $(SPECFILE) $(LOCALFILES)
49 rpmbuild --buildroot=$(CWD)/$(RPM_BUILDDIR)/tmp \
50 --rcfile $(RPM_RCFILES) -bb $(SPECFILE)
53 @echo 'macrofiles: $(RPM_MACROFILES)' >$@
58 echo "%distribution PlanetLab"; \
59 echo "%_fullname %{name}-%{version}-%{release}"; \
60 echo "%_topdir $(CWD)"; \
61 echo "%_sourcedir %{_topdir}"; \
62 echo "%_builddir %{_topdir}/$(RPM_BUILDDIR)"; \
63 echo "%_rpmdir %{_builddir}"
67 mkdir -p $(RPM_BUILDDIR)/tmp
68 ln -s .. $(RPM_BUILDDIR)/$(ARCH)
70 rpm-config: $(LOCALFILES)
71 @echo RPM_RCFILES=$(RPM_RCFILES)
72 @echo RPM_MACROFILES=$(RPM_MACROFILES)
73 @echo RPM_ARCH=$(ARCH)
76 rm -f $(NAME) $(RPMFILE) $(TARBALL)