+++ /dev/null
-#
-# PlanetLab RPM generation
-#
-# Mark Huang <mlhuang@cs.princeton.edu>
-# Copyright (C) 2003-2005 The Trustees of Princeton University
-#
-# $Id: Makerules,v 1.17 2005/12/02 18:55:14 mlhuang Exp $
-#
-
-# Base rpmbuild in the current directory
-export HOME := $(shell pwd)
-export CVSROOT CVS_RSH
-
-#
-# Parse spec file template
-#
-
-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' \
- $< > $@
-
-SPECS/$(notdir $(SPEC)).in:
- mkdir -p SPECS
- cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) > $@
-
-include $(MK)
-
-#
-# Generate tarball
-#
-
-# Get rid of URL
-Source0 := $(notdir $(if $(Source),$(Source),$(Source0)))
-
-# Add tarball to the list of sources
-SOURCES += SOURCES/$(Source0)
-
-# Get rid of .tar.bz2 or .tar.gz or .tgz
-Base0 := $(Source0:.tgz=)
-Base0 := $(Base0:.bz2=)
-Base0 := $(Base0:.gz=)
-Base0 := $(Base0:.tar=)
-
-# Export module
-SOURCES/$(Base0):
- mkdir -p SOURCES
- cd SOURCES && cvs -d $(CVSROOT) export -r $(INITIAL) -d $(Base0) $(MODULE)
-
-.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)
-
-# bzip2
-%.bz2: %
- bzip2 -c $< > $@
-
-# gzip
-%.gz: %
- gzip -c $< > $@
-
-#
-# Generate spec file
-#
-
-ifeq ($(TAG),HEAD)
-# Define date for untagged builds
-DATE := $(shell date +%Y.%m.%d)
-endif
-
-# 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
- echo "%define pldistro $(PLDISTRO)" >> $@
- cat $< >> $@
-
-#
-# Build
-#
-
-RPMFLAGS += --define "pldistro $(PLDISTRO)"
-ifeq ($(TAG),HEAD)
-RPMFLAGS += --define "date $(DATE)"
-endif
-PACKAGES := $(shell rpmquery $(RPMFLAGS) --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null)
-NVR := $(word 1,$(PACKAGES))
-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
-
-# Build RPM
-RPMS/$(ARCH)/$(NVR).$(ARCH).rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
- mkdir -p BUILD RPMS
- $(RPMBUILD) $(RPMFLAGS) -bb $<
-
-# Build SRPM
-SRPMS/$(NVR).src.rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
- 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) \
- $(foreach subpackage,$(PACKAGES),RPMS/*/$(subpackage)*) \
- SOURCES/$(Base0)* SOURCES/$(package)* \
- SPECS/$(notdir $(SPEC)).in SPECS/$(notdir $(SPEC)) $(MK) \
- SRPMS/$(NVR).src.rpm \
- tmp
-
-.PHONY: all clean
# PlanetLab RPM generation
#
# Mark Huang <mlhuang@cs.princeton.edu>
-# Copyright (C) 2003-2005 The Trustees of Princeton University
+# Copyright (C) 2003-2006 The Trustees of Princeton University
#
-# $Id: Makerules,v 1.17 2005/12/02 18:55:14 mlhuang Exp $
+# $Id: Makerules,v 1.18 2005/12/15 17:02:07 mlhuang Exp $
#
# Base rpmbuild in the current directory
export CVSROOT CVS_RSH
#
-# Parse spec file template
+# Create spec file
#
-MK := SPECS/$(patsubst %.spec,%.mk,$(notdir $(SPEC)))
+SPECFILE := SPECS/$(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' \
- $< > $@
-
-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)" >> $@
+endif
+ cvs -d $(CVSROOT) checkout -r $(TAG) -p $(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
-# Get rid of .tar.bz2 or .tar.gz or .tgz
-Base0 := $(Source0:.tgz=)
-Base0 := $(Base0:.bz2=)
-Base0 := $(Base0:.gz=)
-Base0 := $(Base0:.tar=)
+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 $(SPECFILE) > $@
-.SECONDARY: $(SOURCES)/$(Base0)
+# Defines SOURCES, SRPM, RPMS
+include $(MK)
-# Generate tarball
-SOURCES/$(Base0).tar.bz2: SOURCES/$(Base0)
- tar cpjf $@ -C SOURCES $(Base0)
+#
+# Generate tarball(s)
+#
-SOURCES/$(Base0).tar.gz SOURCES/$(Base0).tgz: SOURCES/$(Base0)
- tar cpzf $@ -C SOURCES $(Base0)
+# Get rid of any extensions
+stripext = \
+$(patsubst %.tar.bz2,%, \
+$(patsubst %.tar.gz,%, \
+$(patsubst %.tgz,%, \
+$(patsubst %.zip,%, \
+$(patsubst %.tar,%,$(1))))))
-SOURCES/$(Base0).tar: SOURCES/$(Base0)
- tar cpf $@ -C SOURCES $(Base0)
+SOURCEDIRS := $(call stripext,$(SOURCES))
-# bzip2
-%.bz2: %
- bzip2 -c $< > $@
+SOURCES/$(MODULE):
+ mkdir -p SOURCES
+ cd SOURCES && cvs -d $(CVSROOT) export -r $(TAG) $(MODULE)
-# gzip
-%.gz: %
- gzip -c $< > $@
+# 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/$(MODULE)
+ cp -rl $< $@
-#
-# Generate spec file
-#
+.SECONDARY: SOURCES/$(MODULE) $(SOURCEDIRS)
-ifeq ($(TAG),HEAD)
-# Define date for untagged builds
-DATE := $(shell date +%Y.%m.%d)
-endif
+# Generate tarballs
+SOURCES/%.tar.bz2: SOURCES/%
+ tar cpjf $@ -C SOURCES $*
-# 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
- echo "%define pldistro $(PLDISTRO)" >> $@
- cat $< >> $@
+SOURCES/%.tar.gz: SOURCES/%
+ tar cpzf $@ -C SOURCES $*
+
+SOURCES/%.tgz: SOURCES/%
+ tar cpzf $@ -C SOURCES $*
+
+SOURCES/%.zip: SOURCES/%
+ cd SOURCES && zip -r ../$@ $*
+
+SOURCES/%.tar: SOURCES/%
+ tar cpf $@ -C SOURCES $*
#
# Build
#
-RPMFLAGS += --define "pldistro $(PLDISTRO)"
-ifeq ($(TAG),HEAD)
-RPMFLAGS += --define "date $(DATE)"
-endif
-PACKAGES := $(shell rpmquery $(RPMFLAGS) --specfile SPECS/$(notdir $(SPEC)).in 2>/dev/null)
-NVR := $(word 1,$(PACKAGES))
-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
+$(RPMS): %.rpm: $(SPECFILE) $(SOURCES) .rpmmacros
mkdir -p BUILD RPMS
$(RPMBUILD) $(RPMFLAGS) -bb $<
# Build SRPM
-SRPMS/$(NVR).src.rpm: SPECS/$(notdir $(SPEC)) $(SOURCES) .rpmmacros
+$(SRPM): $(SPECFILE) $(SOURCES) .rpmmacros
mkdir -p SRPMS
rpmbuild $(RPMFLAGS) -bs $<
# Remove files generated by this package
clean:
rm -rf \
- BUILD/$(Base0) \
- $(foreach subpackage,$(PACKAGES),RPMS/*/$(subpackage)*) \
- SOURCES/$(Base0)* SOURCES/$(package)* \
- SPECS/$(notdir $(SPEC)).in SPECS/$(notdir $(SPEC)) $(MK) \
- SRPMS/$(NVR).src.rpm \
+ $(RPMS) $(SRPM) \
+ $(patsubst SOURCES/%,BUILD/%,$(SOURCEDIRS)) \
+ $(SOURCES) $(SOURCEDIRS) SOURCES/$(MODULE) \
+ $(MK) $(SPECFILE) \
tmp
.PHONY: all clean