#
# PlanetLab RPM generation
#
-# Copyright (c) 2003 The Trustees of Princeton University (Trustees).
-# All Rights Reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided
-# with the distribution.
-#
-# * Neither the name of the copyright holder nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# Mark Huang <mlhuang@cs.princeton.edu>
+# Copyright (C) 2003-2006 The Trustees of Princeton University
#
-# $Id: Makerules,v 1.10 2004/08/12 21:21:31 mlh-pl_rpm Exp $
+# $Id: Rules.mk,v 1.37 2007/09/10 22:24:20 mef Exp $
#
-# Base cvsps and rpmbuild in the current directory
+# Base rpmbuild in the current directory
export HOME := $(shell pwd)
export CVSROOT CVS_RSH
#
-# Parse spec file template
+# Create spec file
#
-MK := SPECS/$(patsubst %.spec,%.mk,$(notdir $(SPEC)))
-
-$(MK): SPECS/$(notdir $(SPEC)).in
- # Substitute '$' for '%' and 'name := value' for '%define name value' or 'name: value'
- sed -n \
- -e 's/%{/$${/g' \
- -e 's/%\([[:alnum:]]\+\)/$${\1}/g' \
- -e 's/^$${define}[ ]*\([^ ]*\)[ ]*\([^ ]*\)/\1 := \2/p' \
- -e 's/^\([^ ]*\):[ ]*\([^ ]*\)/\1 := \2/p' \
- $< > $@
-ifneq ($(INITIAL),$(TAG))
- # Get list of PatchSets
- cvsps --cvs-direct --root $(CVSROOT) -r $(INITIAL) $(if $(TAG:HEAD=),-r $(TAG)) $(MODULE) | \
- sed -ne 's|^PatchSet[ ]*\([0-9]*\)|PATCHES += \1|p' >> $@
-ifeq ($(shell echo $(MAKE_VERSION) | awk '{ print ($$1 < 3.80) }'),1)
- # make-3.80 can use $(eval) instead (see below)
- cvsps --cvs-direct --root $(CVSROOT) -r $(INITIAL) $(if $(TAG:HEAD=),-r $(TAG)) $(MODULE) | \
- sh Patchrules >> $@
-endif
-endif
+SPECFILE := SPECS/$(notdir $(SPEC))
+MULTI_MODULE := $(word 2,$(MODULE))
+# is there a single module ? to mimick cvs export -d behaviour
+ifeq "$(MULTI_MODULE)" ""
+ _MAINMODULE := $(MODULE)
+else
+ _MAINMODULE := $(firstword $(MODULE))
+endif
-SPECS/$(notdir $(SPEC)).in:
+$(SPECFILE):
mkdir -p SPECS
- cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) > $@
-
-include $(MK)
+ echo "%define pldistro $(PLDISTRO)" > $@
+ifeq ($(TAG),HEAD)
+ # Define date for untagged builds
+ echo "%define date $(shell date +%Y.%m.%d)" >> $@
+else
+ # Define cvstag for tagged builds
+ echo "%define cvstag $(TAG)" >> $@
+endif
+ $(if $($(package)-CVSROOT), cvs -d $($(package)-CVSROOT) checkout -r $(TAG) -p $(_MAINMODULE)/$(SPEC) >> $@; ,\
+ $(if $($(package)-SVNPATH), svn cat $($(package)-SVNPATH)/$(_MAINMODULE)/$(TAG)/$(SPEC) >> $@; ,\
+ $(if $(CVSROOT), cvs -d $(CVSROOT) checkout -r $(TAG) -p $(_MAINMODULE)/$(SPEC) >> $@; ,\
+ $(if $(SVNPATH), svn cat $(SVNPATH)/$(_MAINMODULE)/$(TAG)/$(SPEC) >> $@; ) \
+ )\
+ )\
+ )
#
-# Generate tarball
+# Parse spec file into Makefile fragment
#
-# Get rid of URL
-Source0 := $(notdir $(if $(Source),$(Source),$(Source0)))
+MK := tmp/$(package).mk
-# Add tarball to the list of sources
-SOURCES += SOURCES/$(Source0)
+parseSpec: CFLAGS := -g -Wall -D_GNU_SOURCE
-# Get rid of .tar.bz2 or .tar.gz or .tgz
-Base0 := $(basename $(basename $(Source0)))
+parseSpec: LDFLAGS := -lrpm -lrpmbuild
-# Export module
-SOURCES/$(Base0):
- mkdir -p SOURCES
- cd SOURCES && cvs -d $(CVSROOT) export -r $(INITIAL) -d $(Base0) $(MODULE)
+$(MK): $(SPECFILE) parseSpec .rpmmacros
+ mkdir -p tmp
+ ./parseSpec $(RPMFLAGS) $(SPECFILE) > $@
-.SECONDARY: $(SOURCES)/$(Base0)
-
-# Generate tarball
-SOURCES/$(Base0).tar.bz2: SOURCES/$(Base0)
- tar cpjf $@ -C SOURCES $(Base0)
-
-SOURCES/$(Base0).tar.gz SOURCES/$(Base0).tgz: SOURCES/$(Base0)
- tar cpzf $@ -C SOURCES $(Base0)
-
-SOURCES/$(Base0).tar: SOURCES/$(Base0)
- tar cpf $@ -C SOURCES $(Base0)
+# Defines SOURCES, SRPM, RPMS
+include $(MK)
#
-# Generate patches
+# Generate tarball(s)
#
-define PATCH_template
-
-# In case the spec file did not explicitly list the PatchSet
-ifeq ($$(origin Patch$(1)),undefined)
-Patch$(1) := $$(package)-$(1).patch.bz2
-endif
-
-# Get rid of URL
-Patch$(1) := $$(notdir $$(Patch$(1)))
+# Get rid of any extensions
+stripext = \
+$(patsubst %.tar.bz2,%, \
+$(patsubst %.tar.gz,%, \
+$(patsubst %.tgz,%, \
+$(patsubst %.zip,%, \
+$(patsubst %.tar,%,$(1))))))
-# Add patch to the list of sources
-SOURCES += SOURCES/$$(Patch$(1))
+SOURCEDIRS := $(call stripext,$(SOURCES))
-# Generate uncompressed patch
-SOURCES/$$(patsubst %.gz,%,$$(patsubst %.bz2,%,$$(Patch$(1)))):
- mkdir -p SOURCES
- cvsps --cvs-direct --root $$(CVSROOT) -g -s $(1) $$(MODULE) > $$@
+# Thierry - Jan 29 2007
+# Allow different modules to have different CVSROOT
+# and/or to be extracted from their SVNPATH
+#
+# is there a single module ? to mimick cvs export -d behaviour
+ifeq "$(MULTI_MODULE)" ""
+# single module: do as before
+SOURCES/$(package):
+ mkdir -p SOURCES && cd SOURCES && \
+ (\
+ $(if $($(package)-CVSROOT), cvs -d $($(package)-CVSROOT) export -r $(TAG) -d $(package) $(MODULE); ,\
+ $(if $($(package)-SVNPATH), svn export $($(package)-SVNPATH)/$(MODULE)/$(TAG) $(package) ; ,\
+ $(if $(CVSROOT), cvs -d $(CVSROOT) export -r $(TAG) -d $(package) $(MODULE); ,\
+ $(if $(SVNPATH), svn export $(SVNPATH)/$(MODULE)/$(TAG) $(package) ;) \
+ )\
+ )\
+ )\
+ )
+else
+# multiple modules : iterate
+SOURCES/$(package):
+ mkdir -p SOURCES/$(package) && cd SOURCES/$(package) && \
+ $(foreach module,$(MODULE),\
+ $(if $($(module)-CVSROOT), cvs -d $($(module)-CVSROOT) export -r $(TAG) -d $(module) $(module); ,\
+ $(if $($(module)-SVNPATH), svn export $($(module)-SVNPATH)/$(module)/$(TAG) $(module) ; ,\
+ $(if $(CVSROOT), cvs -d $(CVSROOT) export -r $(TAG) -d $(module) $(module); ,\
+ $(if $(SVNPATH), svn export $(SVNPATH)/$(module)/$(TAG) $(module) ;) \
+ )\
+ )\
+ )\
+ )
+endif
-endef
+# Make a hard-linked copy of the exported directory for each Source
+# defined in the spec file. However, our convention is that there
+# should be only one Source file and one CVS module per RPM. It's okay
+# if the CVS module consists of multiple directories, as long as the
+# spec file knows what's going on.
+$(SOURCEDIRS): SOURCES/$(package)
+ cp -rl $< $@
-# bzip2
-%.bz2: %
- bzip2 -c $< > $@
+.SECONDARY: SOURCES/$(package) $(SOURCEDIRS)
-# gzip
-%.gz: %
- gzip -c $< > $@
+# Generate tarballs
+SOURCES/%.tar.bz2: SOURCES/%
+ tar cpjf $@ -C SOURCES $*
-# Generate rules to generate patches (make-3.80 and above expands this)
-$(foreach n,$(PATCHES),$(eval $(call PATCH_template,$(n))))
+SOURCES/%.tar.gz: SOURCES/%
+ tar cpzf $@ -C SOURCES $*
-#
-# Generate spec file
-#
+SOURCES/%.tgz: SOURCES/%
+ tar cpzf $@ -C SOURCES $*
-ifeq ($(TAG),HEAD)
-# Define date for untagged builds
-DATE := $(shell date +%Y.%m.%d)
-endif
+SOURCES/%.zip: SOURCES/%
+ cd SOURCES && zip -r ../$@ $*
-# Generate spec file
-SPECS/$(notdir $(SPEC)): SPECS/$(notdir $(SPEC)).in
- rm -f $@
-ifeq ($(TAG),HEAD)
- # Define date for untagged builds
- echo "%define date $(DATE)" >> $@
-endif
- # Rewrite patch sections of spec file
- perl -n -e ' \
- next if /^Patch.*/; \
- next if /^%patch.*/; \
- print; \
- if (/^Source.*/) { $(foreach n,$(PATCHES),print "Patch$(n): $(Patch$(n))\n";) } \
- if (/^%setup.*/) { $(foreach n,$(PATCHES),print "%patch$(n) -p1\n";) } \
- ' $< >> $@
+SOURCES/%.tar: SOURCES/%
+ tar cpf $@ -C SOURCES $*
#
# Build
#
-ifeq ($(TAG),HEAD)
-RPMFLAGS += --define "date $(DATE)"
-endif
-NVR := $(shell rpmquery $(RPMFLAGS) --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null | head -1)
-ARCH := $(shell rpmquery $(RPMFLAGS) --queryformat '%{ARCH}\n' --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null | head -1)
-
-all: RPMS/$(ARCH)/$(NVR).$(ARCH).rpm SRPMS/$(NVR).src.rpm
+all: $(RPMS) $(SRPM)
-# Build RPM
-RPMS/$(ARCH)/$(NVR).$(ARCH).rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
+# Build RPMS
+$(RPMS): $(SPECFILE) $(SOURCES)
mkdir -p BUILD RPMS
$(RPMBUILD) $(RPMFLAGS) -bb $<
+# Make the rest of the RPMS depend on the first one since building one
+# builds them all.
+ifneq ($(words $(RPMS)),1)
+$(wordlist 2,$(words $(RPMS)),$(RPMS)): $(firstword $(RPMS))
+endif
+
# Build SRPM
-SRPMS/$(NVR).src.rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
+$(SRPM): $(SPECFILE) $(SOURCES)
mkdir -p SRPMS
$(RPMBUILD) $(RPMFLAGS) -bs $<
# Base rpmbuild in the current directory
.rpmmacros:
echo "%_topdir $(HOME)" > $@
+ echo "%_tmppath $(HOME)/tmp" >> $@
# Remove files generated by this package
clean:
rm -rf \
- BUILD/$(Base0) \
- RPMS/$(ARCH)/$(NVR).$(ARCH).rpm \
- SOURCES/$(Base0)* SOURCES/$(package)* \
- SPECS/$(notdir $(SPEC)).in SPECS/$(notdir $(SPEC)) $(MK) \
- SRPMS/$(NVR).src.rpm \
- .cvsps/$(subst /,#,$(CVSROOT)/$(MODULE))
+ $(RPMS) $(SRPM) \
+ $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
+ $(SOURCES) $(SOURCEDIRS) SOURCES/$(package) \
+ $(MK) $(SPECFILE)
.PHONY: all clean
+
+#################### convenience, for debugging only
+# make +foo : prints the value of $(foo)
+# make ++foo : idem but verbose, i.e. foo=$(foo)
+++%: varname=$(subst +,,$@)
+++%:
+ @echo $(varname)=$($(varname))
++%: varname=$(subst +,,$@)
++%:
+ @echo $($(varname))