Subject: Check for "test ... == ..." in configure scripts
To: None <tech-pkg@NetBSD.org>
From: Roland Illig <rillig@NetBSD.org>
List: tech-pkg
Date: 09/23/2006 07:41:00
This is a multi-part message in MIME format.
--------------040308070405020904030801
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

there's a discussion on tech-userlevel about accepting the "==" operator 
in test(1). But even if NetBSD changes its implementation, others will 
not do that. So pkgsrc continues with having to deal with those 
non-portable shell scripts.

To solve this, I have written a _very_ simple change to 
mk/configure/configure.mk that just looks if any line of a configure 
script contains the regular expression "test.*==". I hope that this will 
catch a few of the problems.

By default, this check would be enabled (maybe on Linux it doesn't need 
to), but can be disabled by both the pkgsrc user and by each individual 
package.

I'm not satisfied with my current choice of variable names, since the 
other *_SKIP variables are lists of either shell globbing expressions or 
regular expressions. This one would add a third unique data type to this 
naming scheme.

Roland

--------------040308070405020904030801
Content-Type: text/plain;
 name="check-configure.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="check-configure.patch"

Index: configure.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/configure/configure.mk,v
retrieving revision 1.9
diff -u -p -r1.9 configure.mk
--- configure.mk	27 Jul 2006 13:47:29 -0000	1.9
+++ configure.mk	23 Sep 2006 05:29:51 -0000
@@ -1,5 +1,17 @@
 # $NetBSD: configure.mk,v 1.9 2006/07/27 13:47:29 jlam Exp $
 #
+# The following variables may be set by the pkgsrc user in mk.conf:
+#
+# CHECK_CONFIGURE: YesNo (default: yes)
+#	Whether to enable the check for usage of "==" together with
+#	the test(1) utility, which is unportable.
+#
+# The following variables may be set by the package:
+#
+# CHECK_CONFIGURE_SKIP: YesNo (default: no)
+#	Whether the check above should be skipped for the current
+#	package.
+#
 # CONFIGURE_SCRIPT is the path to the script to run in order to
 #	configure the software for building.  If the path is relative,
 #	then it is assumed to be relative to each directory listed in
@@ -14,6 +26,8 @@
 CONFIGURE_SCRIPT?=	./configure
 CONFIGURE_ENV+=		${ALL_ENV}
 CONFIGURE_ARGS?=	# empty
+CHECK_CONFIGURE?=	yes
+DO_CHECK_CONFIGURE?=	yes
 _BUILD_DEFS+=		CONFIGURE_ENV CONFIGURE_ARGS
 
 .if defined(GNU_CONFIGURE)
@@ -197,3 +211,24 @@ pre-configure:
 post-configure:
 	@${DO_NADA}
 .endif
+
+.if ${CHECK_CONFIGURE:M[Yy][Ee][Ss]} != "" \
+  && ${DO_CHECK_CONFIGURE:M[Yy][Ee][Ss]} != ""
+do-configure-pre-hook: _configure-check-for-test
+.endif
+.PHONY: _configure-check-for-test
+_configure-check-for-test:
+	@${STEP_MSG} "Checking for \"test ... == ...\" in configure scripts"
+.for d in ${CONFIGURE_DIRS}
+	${_PKG_SILENT}${_PKG_DEBUG}set -e;				\
+	cd ${WRKSRC}; cd ${d};						\
+	case `sed '1q' < ${CONFIGURE_SCRIPT}` in			\
+	"#! /bin/sh")							\
+		if grep "test.*==" < ${CONFIGURE_SCRIPT}; then		\
+			${ERROR_MSG} "[configure.mk] Found test ... == test in configure script."; \
+			exit 1;						\
+		fi;							\
+		;;							\
+	*)	;;							\
+	esac
+.endfor

--------------040308070405020904030801--