make-rules/ips.mk
changeset 2054 5f403d9bcaad
parent 1948 2d1537e7942d
child 2060 a9ad5cd0ec29
--- a/make-rules/ips.mk	Tue Aug 19 09:43:46 2014 -0700
+++ b/make-rules/ips.mk	Tue Aug 19 19:21:53 2014 -0600
@@ -136,10 +136,28 @@
 NOPERL_MANIFESTS = $(UNVERSIONED_MANIFESTS)
 endif
 
+# Look for manifests which need to be duplicated for each version of ruby.
+# NOPERL_MANIFESTS represents the manifests that are not Python or
+# Perl manifests.  Extract the Ruby Manifests from NOPERL_MANIFESTS.
+# Any remaining manifests are stored in NONRUBY_MANIFESTS
+ifeq ($(findstring -RUBYVER,$(NOPERL_MANIFESTS)),-RUBYVER)
+NORUBY_MANIFESTS = $(filter-out %GENFRAG.p5m,\
+		   $(filter-out %-RUBYVER.p5m,$(NOPERL_MANIFESTS)))
+RUBY_MANIFESTS = $(filter %-RUBYVER.p5m,$(NOPERL_MANIFESTS))
+RUBYV_MANIFESTS = $(foreach v,$(shell echo $(RUBY_VERSIONS)),\
+                      $(shell echo $(RUBY_MANIFESTS) |\
+                      sed -e 's/-RUBYVER.p5m/-$(shell echo $(v) |\
+                      cut -d. -f1,2 | tr -d .).p5m/g'))
+RUBYNV_MANIFESTS = $(shell echo $(RUBY_MANIFESTS) | sed -e 's/-RUBYVER//')
+else
+NORUBY_MANIFESTS = $(NOPERL_MANIFESTS)
+endif
+
 VERSIONED_MANIFESTS = \
 	$(PYV_MANIFESTS) $(PYNV_MANIFESTS) \
 	$(PERLV_MANIFESTS) $(PERLNV_MANIFESTS) \
-	$(NOPERL_MANIFESTS)
+	$(RUBYV_MANIFESTS) $(RUBYNV_MANIFESTS) \
+	$(NORUBY_MANIFESTS)
 
 GENERATED =		$(MANIFEST_BASE)-generated
 COMBINED =		$(MANIFEST_BASE)-combined
@@ -237,6 +255,48 @@
 		$(WS_TOP)/transforms/mkgeneric $< > $@
 	if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
 
+# Define and execute a macro that generates a rule to create a manifest for a
+# ruby module specific to a particular version of the ruby runtime.
+# Creates build/manifest-*-modulename-##.p5m file where ## is replaced with
+# the version number.
+define ruby-manifest-rule
+$(MANIFEST_BASE)-%-$(shell echo $(1) | tr -d .).mogrified: \
+	PKG_MACROS += RUBY_VERSION=$(1) RUBY_LIB_VERSION=$(2) \
+	    RUBYV=$(subst .,,$(1))
+
+$(MANIFEST_BASE)-%-$(shell echo $(1) | tr -d .).p5m: %-RUBYVER.p5m
+	if [ -f $$*-$(shell echo $(1) | tr -d .)GENFRAG.p5m ]; then \
+		cat $$*-$(shell echo $(1) | tr -d .)GENFRAG.p5m >> $$@; \
+	fi
+	$(PKGMOGRIFY) -D RUBY_VERSION=$(1) -D RUBY_LIB_VERSION=$(2) \
+	    -D RUBYV=$(shell echo $(1) | tr -d .) $$< > $$@
+endef
+$(foreach ver,$(RUBY_VERSIONS),\
+	$(eval $(call ruby-manifest-rule,$(shell echo $(ver) | \
+	    cut -d. -f1,2),$(ver))))
+
+# A rule to create a helper transform package for ruby, that will insert the
+# appropriate conditional dependencies into a ruby library's
+# runtime-version-generic package to pull in the version-specific bits when the
+# corresponding version of ruby is on the system.
+$(BUILD_DIR)/mkgeneric-ruby: $(WS_TOP)/make-rules/shared-macros.mk
+	$(RM) $@
+	$(foreach ver,$(RUBY_VERSIONS),\
+		$(call mkgeneric,runtime/ruby,$(shell echo $(ver) | \
+		    cut -d. -f1,2 | tr -d .)))
+
+# Build Ruby version-wrapping manifests from the generic version.
+# Creates build/manifest-*-modulename.p5m file.
+#
+# ###PYV### is used here as the mkgeneric() call used to create 
+# mkgeneric-ruby uses this value version subsitute key.  We also
+# use the same key, ###PYV###, to pick up the required entry
+# in mkgeneric when pkgmogrify is invoked
+$(MANIFEST_BASE)-%.p5m: %-RUBYVER.p5m $(BUILD_DIR)/mkgeneric-ruby
+	$(PKGMOGRIFY) -D RUBYV=###PYV### $(BUILD_DIR)/mkgeneric-ruby \
+		$(WS_TOP)/transforms/mkgeneric $< > $@
+	if [ -f $*-GENFRAG.p5m ]; then cat $*-GENFRAG.p5m >> $@; fi
+
 # mogrify non-parameterized manifests
 $(MANIFEST_BASE)-%.mogrified:	%.p5m $(BUILD_DIR)
 	$(PKGMOGRIFY) $(PKG_OPTIONS) $< \