changeset 13054:d149b2034cfc

6952783 Install: makefile rules aren't robust with respect to dirname
author Mike Kupfer <Mike.Kupfer@Oracle.COM>
date Sat, 07 Aug 2010 15:19:49 -0700
parents 16bccd6e1b08
children 8c712bbb18ea
files usr/src/tools/scripts/Install.sh usr/src/uts/Makefile.targ
diffstat 2 files changed, 94 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/tools/scripts/Install.sh	Sat Aug 07 02:11:24 2010 -0700
+++ b/usr/src/tools/scripts/Install.sh	Sat Aug 07 15:19:49 2010 -0700
@@ -20,8 +20,7 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
 #
 # Author:  Jeff Bonwick
 #
@@ -240,24 +239,24 @@
 	    -v glomname=$2 \
 	    -v karch=$KARCH ' 
 	$1 == "MOD" || $1 == "SYMLINK" {
-		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
-		sub(/^kernel/, "platform/" karch "/" glomname, $3)
-		sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
-		print
-	}
-	$1 == "LINK" {
-		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $2)
-		sub(/^kernel/, "platform/" karch "/" glomname, $2)
-		sub(/^usr.kernel/, "platform/" karch "/" glomname, $2)
 		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $4)
 		sub(/^kernel/, "platform/" karch "/" glomname, $4)
 		sub(/^usr.kernel/, "platform/" karch "/" glomname, $4)
 		print
 	}
+	$1 == "LINK" {
+		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
+		sub(/^kernel/, "platform/" karch "/" glomname, $3)
+		sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
+		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $5)
+		sub(/^kernel/, "platform/" karch "/" glomname, $5)
+		sub(/^usr.kernel/, "platform/" karch "/" glomname, $5)
+		print
+	}
 	$1 == "CONF" {
-		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $2)
-		sub(/^kernel/, "platform/" karch "/" glomname, $2)
-		sub(/^usr.kernel/, "platform/" karch "/" glomname, $2)
+		sub(/^platform.*kernel/, "platform/" karch "/" glomname, $3)
+		sub(/^kernel/, "platform/" karch "/" glomname, $3)
+		sub(/^usr.kernel/, "platform/" karch "/" glomname, $3)
 		print
 	}
 	' $1 > $1.new
@@ -265,7 +264,8 @@
 }
 
 #
-# Remove entries from 
+# Filter out implementation-specific modules, unless that
+# implementation was requested by the user.
 # usage: filtimpl listfile implname
 #
 
@@ -273,15 +273,15 @@
 	nawk \
 	    -v impl=$2 '
 	$1 == "MOD" || $1 == "SYMLINK" {
-		if ($5 == "all" || $5 == impl)
+		if ($6 == "all" || $6 == impl)
 			print
 	}
 	$1 == "CONF" {
-		if ($4 == "all" || $4 == impl)
+		if ($5 == "all" || $5 == impl)
 			print
 	}
 	$1 == "LINK" {
-		if ($6 == "all" || $6 == impl)
+		if ($7 == "all" || $7 == impl)
 			print
 	}
 	' $1 > $1.new
@@ -316,19 +316,19 @@
 			reqmods[tmpmods[i]] = 1
 	}
 	$1 == "MOD" {
-		if (modmatch($2))
+		if (modmatch($3))
 			print
 	}
 	$1 == "CONF" {
-		if (modmatch($5))
+		if (modmatch($6))
 			print
 	}
 	$1 == "SYMLINK" {
-		if (modmatch($6))
+		if (modmatch($7))
 			print
 	}
 	$1 == "LINK" {
-		if (modmatch($3))
+		if (modmatch($4))
 			print
 	}
 	' $1 > $1.new
@@ -386,7 +386,7 @@
 	[ "$OBJD" = obj ] && root=root_$MACH-nd
 
 	grep -v ^MOD $listfile > $listfile.no-mod
-	grep ^MOD $listfile | while read tag module targdir size impl srcdir; do
+	grep ^MOD $listfile | while read tag srcdir module targdir size impl; do
 		#
 		# We don't just grep for ${OBJD}$size/$module because
 		# there can be generic and platform-dependent versions
@@ -410,42 +410,40 @@
 
 #
 # Copy a module, or create a link, as needed.
-# See $SRC/uts/Makefile.targ ($(MODLIST_DEPS) target) for the format
-# of the different input lines.
 #
 
 function copymod {
 	case $1 in
 	MOD)
-		targdir=$INSTALL_FILES/$3
+		targdir=$INSTALL_FILES/$4
 		tstmkdir $targdir
-		target=$targdir/$2
-		verbose "$INSTALL_CP $6/${OBJD}$4/$2 $target"
-		$INSTALL_CP $6/${OBJD}$4/$2 $target || \
+		target=$targdir/$3
+		verbose "$INSTALL_CP $2/${OBJD}$5/$3 $target"
+		$INSTALL_CP $2/${OBJD}$5/$3 $target || \
 		    fail "can't create $target"
 		;;
 	SYMLINK)
-		targdir=$INSTALL_FILES/$3
-		tstmkdir $targdir
-		target=$targdir/$4
-		rm -f $target
-		verbose "ln -s $2 $target"
-		ln -s $2 $target || fail "can't create $target"
-		;;
-	LINK)
 		targdir=$INSTALL_FILES/$4
 		tstmkdir $targdir
 		target=$targdir/$5
 		rm -f $target
-		verbose "ln $INSTALL_FILES/$2/$3 $target"
-		ln $INSTALL_FILES/$2/$3 $target || fail "can't create $target"
+		verbose "ln -s $3 $target"
+		ln -s $3 $target || fail "can't create $target"
+		;;
+	LINK)
+		targdir=$INSTALL_FILES/$5
+		tstmkdir $targdir
+		target=$targdir/$6
+		rm -f $target
+		verbose "ln $INSTALL_FILES/$3/$4 $target"
+		ln $INSTALL_FILES/$3/$4 $target || fail "can't create $target"
 		;;
 	CONF)
-		target=$INSTALL_FILES/$2
+		target=$INSTALL_FILES/$3
 		tstmkdir `dirname $target`
-		conffile=`basename $2`
-		verbose "$INSTALL_CP $3/$conffile $target"
-		$INSTALL_CP $3/$conffile $target
+		conffile=`basename $3`
+		verbose "$INSTALL_CP $4/$conffile $target"
+		$INSTALL_CP $4/$conffile $target
 		;;
 	*)
 		fail "unrecognized modlist entry: $*"
@@ -453,6 +451,30 @@
 	esac
 }
 
+# Sanity-check the given module list.
+function check_modlist {
+	nawk '
+	BEGIN {
+		nfields["MOD"] = 6
+		nfields["CONF"] = 6
+		nfields["LINK"] = 7
+		nfields["SYMLINK"] = 7
+	}
+	{
+		# This also catches unknown tags.
+		if (nfields[$1] != NF) {
+			print "error: invalid modlist record:"
+			print $0
+			print "expected", nfields[$1], "fields, found", NF
+			status=1
+		}
+	}
+	END {
+		exit status
+	}
+	' $1 || fail "Errors in kernel module list"
+}
+
 #
 # Copy kernel modules to $INSTALL_DIR
 #
@@ -519,6 +541,7 @@
 	(cd $KARCH; MAKEFLAGS=e $make -K $MODSTATE modlist.karch) | \
 	    egrep "^MOD|^CONF|^LINK|^SYMLINK" > $modlist
 	[ "$VERBOSE" = "V" ] && cat $modlist
+	check_modlist $modlist
 	if [ -n "$ON_CRYPTO_BINS" ]; then
 		cryptotar="$ON_CRYPTO_BINS"
 		if [ "$OBJD" = obj ]; then
--- a/usr/src/uts/Makefile.targ	Sat Aug 07 02:11:24 2010 -0700
+++ b/usr/src/uts/Makefile.targ	Sat Aug 07 15:19:49 2010 -0700
@@ -19,8 +19,7 @@
 # CDDL HEADER END
 #
 #
-# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
 #
 #	This Makefiles contains the common targets and definitions for
 #	all kernels. It is to be included in the Makefiles for specific
@@ -381,18 +380,31 @@
 MODSRC:sh=		pwd
 
 #
+# Generate module information for Install.sh, i.e., specify what files
+# Install.sh should include.  Each line looks like
+#   <tag> <srcdir> <arg1> <arg2> ...
+# where <tag> specifies the type of file, <srcdir> gives the source
+# path (useful if there is an error), and <argN> is one or more
+# additional bits of information that Install.sh needs (e.g., source
+# directory, install directory, filtering tags).  See Install.sh for
+# details on the arguments for each tag type, especially the functions
+# copymod, filtmod, and filtimpl.
+#
 # Changes to this target may require corresponding changes to
 # Install.sh.
+#
 # Don't issue a MOD entry if it's not in the install list.
 #
+
 $(MODLIST_DEPS): FRC
 	@case $@ in \
 	*32) \
 		class=32; \
-		relmodule=`dirname $(RELMODULE)`;; \
+		[ -n "$(RELMODULE)" ] && relmodule=`dirname $(RELMODULE)`;; \
 	*64) \
 		class=64; \
-		relmodule=`dirname $(RELMODULE)`/$(SUBDIR64);; \
+		[ -n "$(RELMODULE)" ] && \
+		    relmodule=`dirname $(RELMODULE)`/$(SUBDIR64);; \
 	esac; \
 	if [ -z "$(THISIMPL)" ]; then \
 		impl=all; \
@@ -408,8 +420,8 @@
 		tinstall="$(INSTALL_TARGET)"; \
 		for t in $$tinstall; do \
 			if [ "$(ROOTMODULE)" = $$t ]; then \
-				echo MOD $$module $$relmodule \
-				    $$class $$impl $(MODSRC); \
+				echo MOD $(MODSRC) $$module $$relmodule \
+				    $$class $$impl; \
 				break; \
 			fi \
 		done \
@@ -418,7 +430,7 @@
 		tinstall="$(INSTALL_TARGET)"; \
 		for t in $$tinstall; do \
 			if [ $(ROOT_CONFFILE) = $$t ]; then \
-				echo CONF $(RELCONF) \
+				echo CONF $(MODSRC) $(RELCONF) \
 				    $(MODSRC)/$(CONF_SRCDIR) $$impl $$module; \
 				break; \
 			fi \
@@ -427,17 +439,17 @@
 	if [ -n "$(ROOTLINK)" ]; then \
 		rellinks="$(RELLINK)"; \
 		for r in $$rellinks; do \
-		if [ $$class = 32 ]; then \
-			linkdir=`dirname $$r`; \
-		else \
-			linkdir=`dirname $$r`/$(SUBDIR64); \
-		fi; \
-		echo LINK $$relmodule $$module \
-			$$linkdir `basename $$r` $$impl; \
+			if [ $$class = 32 ]; then \
+				linkdir=`dirname $$r`; \
+			else \
+				linkdir=`dirname $$r`/$(SUBDIR64); \
+			fi; \
+			echo LINK $(MODSRC) $$relmodule $$module \
+				$$linkdir `basename $$r` $$impl; \
 		done \
 	fi; \
 	if [ -n "$(UNIX32_LINK)" ]; then \
-		echo SYMLINK $(SUBDIR64)/$(UNIX) \
+		echo SYMLINK $(MODSRC) $(SUBDIR64)/$(UNIX) \
 		    `dirname $(RELUNIX)` unix $$impl $$module; \
 	fi; \
 	trelsoftlinks="$(RELSOFTLINKS)"; \
@@ -448,7 +460,7 @@
 			linkdir=`dirname $$t`/$(SUBDIR64); \
 		fi; \
 		linkname=`basename $$t`; \
-		echo SYMLINK $(MODULE) $$linkdir $$linkname \
+		echo SYMLINK $(MODSRC) $(MODULE) $$linkdir $$linkname \
 		    $$impl $$module; \
 	done