X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=Rules.mk;h=462d208c055c1711dfa322183fb40cc24369a286;hb=e8798f0877bba53fa1edb7522bcd966915314d21;hp=33593f4b644021f028202a0801e08acdd18a586e;hpb=6f3d4166dd65984a044e282045815ff3675f62ca;p=build.git diff --git a/Rules.mk b/Rules.mk index 33593f4b..462d208c 100644 --- a/Rules.mk +++ b/Rules.mk @@ -1,196 +1,161 @@ # # 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 +# Copyright (C) 2003-2006 The Trustees of Princeton University # -# $Id: Makerules,v 1.7 2004/04/14 18:05:30 mlh-pl_rpm Exp $ +# $Id: Rules.mk,v 1.33 2007/03/19 16:25:04 thierry 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/%\([[: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)) -SPECS/$(notdir $(SPEC)).in: +$(SPECFILE): mkdir -p SPECS - cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) > $@ + 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)-SVNPATH),\ + svn cat $($(package)-SVNPATH)/$(SPEC) >> $@,\ + cvs -d $(CVSROOT) checkout -r $(TAG) -p $(SPEC) >> $@) -include $(MK) # -# 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) - -.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) +$(MK): $(SPECFILE) parseSpec .rpmmacros + mkdir -p tmp + ./parseSpec $(RPMFLAGS) $(SPECFILE) > $@ -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)))): +# 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 +MULTI_MODULE := $(word 2,$(MODULE)) +ifeq "$(MULTI_MODULE)" "" +# single module: do as before +SOURCES/$(package): mkdir -p SOURCES - cvsps --cvs-direct --root $$(CVSROOT) -g -s $(1) $$(MODULE) > $$@ + $(if $($(package)-SVNPATH),\ + cd SOURCES && svn export $($(package)-SVNPATH) $(package),\ + cd SOURCES && cvs -d $(CVSROOT) export -r $(TAG) -d $(package) $(MODULE)) +else +# multiple modules : iterate +SOURCES/$(package): + mkdir -p SOURCES/$(package) && cd SOURCES/$(package) && (\ + $(foreach module,$(MODULE),\ + $(if $($(module)-SVNPATH), \ + svn export $($(module)-SVNPATH) $(module);, \ + cvs -d $(if $($(module)-CVSROOT),$($(module)-CVSROOT),$(CVSROOT)) export -r $(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 # -RPMFLAGS += $(if $(DATE),--define "date $(DATE)") -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 $< + $(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))