# [PATCH 1/4] configure: Add test for Perl

6 messages from 2006-07-07 to 2006-07-07. Participants: Dennis Stosberg, Junio C Hamano.
Thread: https://gitlist.dev/t/4798

## Dennis Stosberg, 2006-07-07 16:25

Subject: [PATCH 0/4] More tests for hand-written configure (resend)
Message-ID: <20060707162513.25746.57374.stgit@leonov.stosberg.net>
URL: https://gitlist.dev/e/20060707162513.25746.57374.stgit%40leonov.stosberg.net

```
Second version of the additional tests.  Changes relative to
yesterdays's patches:

  -  Calls to the "which" command have been replaced by a shell
     function that Timo Hirvonen has written
  -  Paths to Perl and Python binaries can be given in an
     environment variable to prevent auto-detection.
  -  NO_PYTHON is set, if no suitable python can be found
  -  Fixes to make it run on Solaris.

Tested on Linux (bash, dash), Solaris 9 (sh) and NetBSD (sh/ash).

I noticed that the autoconf-based solution has replaced Pasky's
scripts in the pu branch.  Has a final decision been made?

I must admit that I'm less convinced today that a hand-written
configuration script is better than I was yesterday when I started
to write the tests.

Regards,
Dennis

```

## Dennis Stosberg, 2006-07-07 16:26

Subject: [PATCH 1/4] configure: Add test for Perl
Message-ID: <20060707162637.25746.84757.stgit@leonov.stosberg.net>
URL: https://gitlist.dev/e/20060707162637.25746.84757.stgit%40leonov.stosberg.net
In-Reply-To: <20060707162513.25746.57374.stgit@leonov.stosberg.net>

```
From: Dennis Stosberg <dennis@stosberg.net>

This patch adds two tests to the configuration script. The first
one tries to find a perl binary in the path.  The second one checks
whether the found perl is of a sufficient version.

The user can override the auto-detection with the --perl parameter
or with the PERL environment variable.

The path_find() function was written by Timo Hirvonen as a replacement
for "which", which cannot be used portably.

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---

 config-lib.sh |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/config-lib.sh b/config-lib.sh
index 68fecc5..34dfc05 100755
--- a/config-lib.sh
+++ b/config-lib.sh
@@ -117,6 +117,22 @@ alpha() {
 	esac
 }
 
+# replacement for "which", which cannot be used portably
+path_find()
+{
+        _ifs="$IFS"
+        IFS=:
+        for i in $PATH; do
+                if test -x "$i/$1"; then
+                        IFS="$_ifs"
+                        echo "$i/$1"
+                        return 0
+                fi
+        done
+        IFS="$_ifs"
+        return 1
+}
+
 # not boolean test: implement the posix shell "!" operator for a
 # non-posix /bin/sh.
 #   usage:  not {command}
@@ -240,6 +256,9 @@ process_params() {
 	_cc=cc
 	test "$CC" && _cc="$CC"
 
+	_perl=
+	test "$PERL" && _perl="$PERL"
+
 	for ac_option do
 		case "$ac_option" in
 		--help|-help|-h)
@@ -262,6 +281,7 @@ Installation directories:
 
 Miscellaneous options:
   --cc=COMPILER          use this C compiler to build MPlayer [gcc]
+  --perl=PATH            path to perl binary [autodetect]
   --target=PLATFORM      target platform (i386-linux, arm-linux, etc)
   --with-install=PATH    use a custom install program (useful if your OS uses
                          a GNU-incompatible install utility by default and
@@ -296,6 +316,8 @@ EOF
 
 		--cc=*)
 			_cc=`echo $ac_option | cut -d '=' -f 2` ;;
+		--perl=*)
+			_perl=`echo $ac_option | cut -d '=' -f 2` ;;
 		--target=*)
 			_target=`echo $ac_option | cut -d '=' -f 2` ;;
 		--with-install=*)
@@ -409,8 +431,21 @@ int main(void) { return 0; }
 EOF
 	{ cc_check && tmp_run; } || die "unusable compiler or produced binary"
 	echores yes
-}
 
+	echocheck "for perl"
+	if test -z "$_perl" ; then
+		_perl=`path_find perl`
+		test "$_perl" || die "cannot find path to perl"
+	fi
+	echores "$_perl"
+
+	echocheck "perl version"
+	_perl_version=`"$_perl" -e 'eval{require 5.6.0; printf "%vd", $^V}'`
+	if test -z "$_perl_version" ; then
+		die "your perl is too old. Perl 5.6.0 or newer is required."
+	fi
+	echores "$_perl_version"
+}
 
 write_config() {
 	echo "Creating config.mak.autogen"
@@ -420,6 +455,7 @@ write_config() {
 # -------- Generated by configure -----------
 
 CC = $_cc
+PERL_PATH = $_perl
 INSTALL = $_install
 
 EOF

```

## Dennis Stosberg, 2006-07-07 16:26

Subject: [PATCH 2/4] configure: Add test for Python
Message-ID: <20060707162640.25746.45482.stgit@leonov.stosberg.net>
URL: https://gitlist.dev/e/20060707162640.25746.45482.stgit%40leonov.stosberg.net
In-Reply-To: <20060707162513.25746.57374.stgit@leonov.stosberg.net>

```
From: Dennis Stosberg <dennis@stosberg.net>

The test tries to find the path to a suitable Python binary.  The
user can override the auto-detection with the --python parameter
or with the PYTHON environment variable.

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---

 config-lib.sh |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/config-lib.sh b/config-lib.sh
index 34dfc05..3968245 100755
--- a/config-lib.sh
+++ b/config-lib.sh
@@ -259,6 +259,9 @@ process_params() {
 	_perl=
 	test "$PERL" && _perl="$PERL"
 
+	_python=
+	test "$PYTHON" && _python="$PYTHON"
+
 	for ac_option do
 		case "$ac_option" in
 		--help|-help|-h)
@@ -282,6 +285,7 @@ Installation directories:
 Miscellaneous options:
   --cc=COMPILER          use this C compiler to build MPlayer [gcc]
   --perl=PATH            path to perl binary [autodetect]
+  --python=PATH          path to python binary [autodetect]
   --target=PLATFORM      target platform (i386-linux, arm-linux, etc)
   --with-install=PATH    use a custom install program (useful if your OS uses
                          a GNU-incompatible install utility by default and
@@ -318,6 +322,8 @@ EOF
 			_cc=`echo $ac_option | cut -d '=' -f 2` ;;
 		--perl=*)
 			_perl=`echo $ac_option | cut -d '=' -f 2` ;;
+		--python=*)
+			_python=`echo $ac_option | cut -d '=' -f 2` ;;
 		--target=*)
 			_target=`echo $ac_option | cut -d '=' -f 2` ;;
 		--with-install=*)
@@ -445,6 +451,28 @@ EOF
 		die "your perl is too old. Perl 5.6.0 or newer is required."
 	fi
 	echores "$_perl_version"
+
+	echocheck "for python"
+	for _py_bin in python python2.4 python2.3; do
+		test "$_python" && continue
+
+		_candidate=`path_find $_py_bin`
+		test "$_candidate" || continue
+
+		$_candidate - <<EOF || continue
+import sys
+v = sys.version_info
+if v < (2, 3):
+    sys.exit(1)
+EOF
+		_python=$_candidate
+	done
+	if test "$_python"; then
+		echores "$_python"
+	else
+		_no_python="ConfigureYesPlease"
+		echores "not found"
+	fi
 }
 
 write_config() {
@@ -465,6 +493,10 @@ EOF
 		test -z $_mandir || ( echo "mandir = $_mandir" && echo "export mandir" )
 		test -z $_templatedir || echo "template_dir = $_templatedir"
 		test -z $_gitpythondir || echo "GIT_PYTHON_DIR = $_gitpythondir"
+
+		test -z $_python || echo "PYTHON_PATH = $_python"
+		test -z $_no_python || echo "NO_PYTHON = $_no_python"
+
 		echo
 		eval "$mkvars"
 	} > config.mak.autogen

```

## Dennis Stosberg, 2006-07-07 16:26

Subject: [PATCH 3/4] configure: Try to figure out compiler options
Message-ID: <20060707162642.25746.3676.stgit@leonov.stosberg.net>
URL: https://gitlist.dev/e/20060707162642.25746.3676.stgit%40leonov.stosberg.net
In-Reply-To: <20060707162513.25746.57374.stgit@leonov.stosberg.net>

```
From: Dennis Stosberg <dennis@stosberg.net>

This patch adds tests to determine of what flavour the used
compiler is and sets CFLAGS and the PIC flag appropriately.

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---

 Makefile      |    3 ++-
 config-lib.sh |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 4dc5379..23c784e 100644
--- a/Makefile
+++ b/Makefile
@@ -96,6 +96,7 @@ ALL_CFLAGS = $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
 PERL_CFLAGS =
 PERL_LDFLAGS =
+PICFLAG = -fPIC
 STRIP ?= strip
 
 prefix = $(HOME)
@@ -483,7 +484,7 @@ endif
 endif
 endif
 ifdef USE_PIC
-	ALL_CFLAGS += -fPIC
+	ALL_CFLAGS += $(PICFLAG)
 endif
 ifdef NO_ACCURATE_DIFF
 	BASIC_CFLAGS += -DNO_ACCURATE_DIFF
diff --git a/config-lib.sh b/config-lib.sh
index 3968245..0bcd4c3 100755
--- a/config-lib.sh
+++ b/config-lib.sh
@@ -35,9 +35,9 @@ compile_check() {
 	echo
 	cat "$1"
 	echo
-	echo "$_cc $CFLAGS $_inc_extra $_ld_static $_ld_extra -o $TMPO $@"
+	echo "$_cc $_cflags $_inc_extra $_ld_static $_ld_extra -o $TMPO $@"
 	rm -f "$TMPO"
-	$_cc $CFLAGS $_inc_extra $_ld_static $_ld_extra -o "$TMPO" "$@" || return $?
+	$_cc $_cflags $_inc_extra $_ld_static $_ld_extra -o "$TMPO" "$@" || return $?
 	echo
 	echo "ldd $TMPO"
 	$_ldd "$TMPO" || return $?
@@ -283,7 +283,7 @@ Installation directories:
   --gitpythondir=DIR     use this prefix for python libraries [PREFIX/share/git-core/python]
 
 Miscellaneous options:
-  --cc=COMPILER          use this C compiler to build MPlayer [gcc]
+  --cc=COMPILER          use this C compiler to build Git [cc]
   --perl=PATH            path to perl binary [autodetect]
   --python=PATH          path to python binary [autodetect]
   --target=PLATFORM      target platform (i386-linux, arm-linux, etc)
@@ -373,8 +373,8 @@ EOF
 				i[3-9]86*|x86|x86pc|k5|k6|k6_2|k6_3|k6-2|k6-3|pentium*|athlon*|i586_i686|i586-i686|BePC) host_arch=i386 ;;
 				ia64) host_arch=ia64 ;;
 				x86_64|amd64)
-				if [ -n "`$_cc -dumpmachine | sed -n '/^x86_64-/p;/^amd64-/p'`" -a \
-					-z "`echo $CFLAGS | grep -- -m32`"  ]; then
+				if [ -n "`$_cc -dumpmachine 2>/dev/null | sed -n '/^x86_64-/p;/^amd64-/p'`" -a \
+					-z "`echo $_cflags | grep -- -m32`"  ]; then
 					host_arch=x86_64
 				else
 					host_arch=i386
@@ -430,7 +430,51 @@ test_setup() {
 	TMPS="$I/git-conf-$RANDOM-$$.S"
 }
 
+cc_flavour() {
+
+	echocheck "whether cc is GCC"
+	cat > $TMPC <<EOF
+#ifndef __GNUC__
+#error Not GCC
+#endif
+int main(void) { return 0; }
+EOF
+	if cc_check ; then
+		echores "yes"
+		_cc_flavour="gcc"
+		return
+	fi
+	echores "no"
+
+	echocheck "whether cc is Sun CC"
+	cat > $TMPC <<EOF
+#ifndef __SUNPRO_C
+#error Not SUN CC
+#endif
+int main(void) { return 0; }
+EOF
+	if cc_check ; then
+		echores "yes"
+		_cc_flavour="suncc"
+		return
+	fi
+	echores "no"
+}
+
 basic_tests() {
+	_cc_flavour=unknown
+	cc_flavour
+
+	if test "$_cc_flavour" = "gcc" ; then
+		_cflags="-g -O2 -Wall"
+		_picflag="-fPIC"
+	elif test "$_cc_flavour" = "suncc"; then
+		_cflags="-g -xO3"
+		_picflag="-KPIC"
+	fi
+	test "$CFLAGS" && _cflags="$CFLAGS"
+	test "$PICFLAG" && _picflag="$PICFLAG"
+
 	echocheck "if your build environment is sane"
 	cat > $TMPC <<EOF
 int main(void) { return 0; }
@@ -483,6 +527,8 @@ write_config() {
 # -------- Generated by configure -----------
 
 CC = $_cc
+CFLAGS = $_cflags
+PICFLAG = $_picflag
 PERL_PATH = $_perl
 INSTALL = $_install
 

```

## Dennis Stosberg, 2006-07-07 16:26

Subject: [PATCH 4/4] configure: Fixes for Solaris
Message-ID: <20060707162644.25746.78865.stgit@leonov.stosberg.net>
URL: https://gitlist.dev/e/20060707162644.25746.78865.stgit%40leonov.stosberg.net
In-Reply-To: <20060707162513.25746.57374.stgit@leonov.stosberg.net>

```
From: Dennis Stosberg <dennis@stosberg.net>

- Solaris' /bin/sh will not find a function if there is a variable 
  with the same name.
- 'test -z $var' fails if $var is empty.  Needs to be 'test -z "$var"' 

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---

 config-lib.sh |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/config-lib.sh b/config-lib.sh
index 0bcd4c3..4dd4d00 100755
--- a/config-lib.sh
+++ b/config-lib.sh
@@ -181,7 +181,7 @@ add_library() { # --with
 	lib_help="$lib_help
 $desc [$hdefault]"
 	switches="$switches switch_lib \"$name\" \"$switch\" \"\$ac_option\" || "
-	mkvars="$mkvars mkvar \"\$$name\" \"$mkvar\";"
+	mkvars="$mkvars print_mkvar \"\$$name\" \"$mkvar\";"
 	eval "$name=$default"
 }
 
@@ -196,7 +196,7 @@ add_feature() { # --enable
 	feature_help="$feature_help
 $desc [$hdefault]"
 	switches="$switches switch_feature \"$name\" \"$switch\" \"\$ac_option\" || "
-	mkvars="$mkvars mkvar \"\$$name\" \"$mkvar\";"
+	mkvars="$mkvars print_mkvar \"\$$name\" \"$mkvar\";"
 	eval "$name=$default"
 }
 
@@ -226,7 +226,7 @@ switch_feature() {
 	return 0
 }
 
-mkvar() {
+print_mkvar() {
 	value="$1"; shift; mkvar="$1"; shift
 	noval=""; yesval="ConfigureYesPlease"
 	case $mkvar in
@@ -533,15 +533,15 @@ PERL_PATH = $_perl
 INSTALL = $_install
 
 EOF
-		test -z $_prefix || echo "prefix = $_prefix"
-		test -z $_bindir || echo "bindir = $_bindir"
-		test -z $_gitexecdir || echo "gitexecdir = $_gitexecdir"
-		test -z $_mandir || ( echo "mandir = $_mandir" && echo "export mandir" )
-		test -z $_templatedir || echo "template_dir = $_templatedir"
-		test -z $_gitpythondir || echo "GIT_PYTHON_DIR = $_gitpythondir"
-
-		test -z $_python || echo "PYTHON_PATH = $_python"
-		test -z $_no_python || echo "NO_PYTHON = $_no_python"
+		test -z "$_prefix" || echo "prefix = $_prefix"
+		test -z "$_bindir" || echo "bindir = $_bindir"
+		test -z "$_gitexecdir" || echo "gitexecdir = $_gitexecdir"
+		test -z "$_mandir" || ( echo "mandir = $_mandir" && echo "export mandir" )
+		test -z "$_templatedir" || echo "template_dir = $_templatedir"
+		test -z "$_gitpythondir" || echo "GIT_PYTHON_DIR = $_gitpythondir"
+
+		test -z "$_python" || echo "PYTHON_PATH = $_python"
+		test -z "$_no_python" || echo "NO_PYTHON = $_no_python"
 
 		echo
 		eval "$mkvars"

```

## Junio C Hamano, 2006-07-07 19:40

Subject: Re: [PATCH 0/4] More tests for hand-written configure (resend)
Message-ID: <7vhd1tw6dd.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vhd1tw6dd.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20060707162513.25746.57374.stgit@leonov.stosberg.net>

```
Dennis Stosberg <dennis@stosberg.net> writes:

> I noticed that the autoconf-based solution has replaced Pasky's
> scripts in the pu branch.  Has a final decision been made?

My preference has been to see both sides battle it out without
forcing me to decide, but...

> I must admit that I'm less convinced today that a hand-written
> configuration script is better than I was yesterday when I started
> to write the tests.

... I started to share the same feeling after Pavel Roskin made
a good point in "git on HP-UX" thread,

    http://thread.gmane.org/gmane.comp.version-control.git/23380/focus=23393

and then after seeing the messages in response to your patch
that used `which` from yesterday.

Shell scripts generated by autoconf are almost unreadable, but
the way how they detect features have been polished in the field
for portability for a long time, and there is no point for us to
spend time reinventing the wheel.  The configure.ac files are
often quite readable even when generated configure scripts are
not.

So, I would not veto the use of autoconf, as long as configure
stays as an _optional_ mechanism to manage config.mak.gen that
is used by the main Makefile.  The users for whom the configure
script breaks for whatever reason can work it around by simply
not using it, instead of having to debug either the unreadable
configure or having to install autoconf and debug configure.ac
just to build git.

The _optional_ is really the key word here.  So "make clean" to
clean autoconf intermediate files is good, "make realclean" to
remove "configure" script generated from "configure.ac" is also
good, but if "make rpm" by default runs "configure", then that
is BAD and I would be very unhappy.

I could probably live with "make rpm-using-configure", though.

```
