Skip to contentSkip to conversation

./configure script prototype

DISCUSSION Andreas Ericsson 7 participants 13 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I've started writing up a configuration script to move some of the logic out of the Makefile and make it a bit easier to enable/disable certain stuff.

I'm not exactly fluent in what sh flavours accept what syntax and the uname -m output is a bit of a mystery for some architectures (PowerPC, notably) so the SHA1 method selection stuff might not work.

Thoughts? Comments? Patches?

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#1 lore raw
Quoted 6 lines · Andreas Ericsson

I've started writing up a configuration script to move some of the logic out of the Makefile and make it a bit easier to enable/disable certain stuff.

I'm not exactly fluent in what sh flavours accept what syntax and the uname -m output is a bit of a mystery for some architectures (PowerPC, notably) so the SHA1 method selection stuff might not work.

Thoughts? Comments? Patches?

Attachments? ;)

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

#!/bin/sh

# VERSION must be here so we know where to put the git_libexec_dir later on VERSION=0.99.9.GIT

# some default values
default_prefix=$HOME
enable_http=Yes
enable_expat=Yes
without_openssl=0

tar=$(which gtar 2>/dev/null || which tar 2>/dev/null) install=$(which ginstall 2>/dev/null || which install 2>/dev/null)

function usage ()
{
cat << EOF
Usage: $0 [VAR=VALUE]...

Installation directories:

 --prefix=PREFIX         files go in directories under PREFIX [$default_prefix]
 --exec-prefix=EPREFIX   executables go in directories under EPREFIX [PREFIX]
 --bindir=DIR            user executables [EPREFIX/bin]
 --datadir=DIR           read-only architecture-independent data [PREFIX/share]
 --mandir=DIR            man-page base directory [\$datadir/man]

git specific stuff and where to install it:

 --git-exec-path=DIR     git executables path [*currently* \$bindir]
 --git-python-dir=DIR    git python scripts [\$datadir/git/python]
 --git-template-dir=DIR  git templates [\$datadir/git/templates]

Other compilation options:

 --disable-http          disable http transport support [enable]
 --without-expat         build without expat (disables http-push) [enable]
 --with-curl=DIR         path to curl installation [/usr]
 --with-expat=DIR        path to libexpat installation [/usr]
 --with-sha1=METHOD      possible options are MOZILLA_SHA1, PPC_SHA1, ARM_SHA1
                         and OPENSSL_SHA1 [autodetect / OPENSSL_SHA1]
 --with-shell=PATH       path to bourne-like shell [/bin/sh]
 --with-perl=PATH        path to perl [/usr/bin/perl]
 --with-python=PATH      path to python [/usr/bin/python]

EOF
exit 0
}

# for debugging, really
: ${outfile=config.mak}

# Try to keep these in the same order as the help output above. while [ $# -gt 0 ]; do

	case "$1" in
		--help*)
			usage
		;;
		--prefix=*)
			prefix=${1##*=}
		;;
		--exec-prefix=*)
			exec_prefix=${1##*=}
		;;
		--bindir=*)
			bindir=${1##*=}
		;;
		--datadir=*)
			datadir=${1##*=}
		;;
		--mandir=*)
			mandir=${1##*=}
		;;
		--git-exec-path=*)
			git_exec_path=${1##*=}
		;;
		--git-python-dir=*)
			git_python_dir=${1##*=}
		;;
		--git-template-dir=*)
			git_template_dir=${1##*=}
		;;
		--disable-http*)
			enable_http=No
			enable_expat=No
		;;
		--without-expat*)
			enable_expat=No
		;;
		--with-curl=*)
			curl_dir=${1##*=}
		;;
		--with-expat=*)
			expat_dir=${1##*=}
		;;
		--with-sha1=*)
			sha1=${1##*=}
		;;
		--with-shell=*)
			shell=${1##*=}
		;;
		--with-perl=*)
			perl=${1##*=}
		;;
		--with-python=*)
			python=${1##*=}
		;;
	esac
	shift

done

[ "$prefix" ] || prefix="$HOME"
[ "$libdir" ] || libdir="$prefix/lib"
[ "$bindir" ] || bindir="$prefix/bin"
[ "$datadir" ] || datadir="$prefix/share"
[ "$mandir" ] || mandir="$datadir/man"
[ "$git_exec_path" ] || git_exec_path="$bindir"
[ "$git_python_dir"] || git_python_dir=$datadir/git/python

[ "$git_template_dir" ] || git_template_dir=$datadir/git/templates

[ "$shell" ] || shell=/bin/sh
if [ -z "$perl" ]; then

	perl=$(which perl 2>/dev/null || perl=/usr/bin/perl)
fi
if [ -z "$python" ]; then
	python=$(which python 2>/dev/null || python=/usr/bin/python)

fi

function need () {
	echo "Need $@"
	for n in "$@"; do
		echo "NEEDS_$n = YesPlease" >> $outfile
	done
}

function no () {
echo "Working around missing $@"
for n in "$@"; do
echo "NO_$n = YesPlease" >> $outfile
done
}

function cflag () {
	echo "ALL_CFLAGS += $@" >> $outfile
}
# for now this is just an alias
alias ldflag=cflag

#function ldflag () {
# echo "ALL_LDFLAGS += $@" >> $outfile
#}

sys=$(uname -s)
case $sys in

	Darwin)
		need SSL_WITH_CRYPTO LIBICONV
		## fink
		cflag -I/sw/include
		ldflag -L/sw/lib
		## darwinports
		cflag -I/opt/local/include
		ldflag -L/opt/local/lib
	;;
	SunOS)
		need SOCKET NSL LIBICONV
		no STRCASESTR
		cflag -D__EXTENSIONS__
		[ "$shell" = /bin/sh -a -x /bin/bash ] && shell=/bin/bash
	;;
	OpenBSD)
		need LIBICONV
		no STRCASESTR
		cflag -I/usr/local/include
		ldflag -L/usr/local/lib
	;;

esac

os=$(uname -o)
case $os in

	Cygwin)
		need LIBICONV
		no STRCASESTR IPV6
		cflag -DUSE_SYMLINK_HEAD=0
		echo "X = .exe" >> $outfile
	;;

esac

if [ -z "$sha1" ]; then

	mach=$(uname -m)
	case $mach in
		*arm*)
			sha1=ARM_SHA1
		;;
		i*86)
			sha1=OPENSSL_SHA1
		;;
		# Is this uname -m output for PPC??
		PPC|PowerPC)
			sha1=PPC_SHA1
		;;
		*)
			sha1=MOZILLA_SHA1
		;;
	esac

fi

cat << EOF > $outfile
GIT_VERSION := $VERSION

# Installation destinations
prefix = $prefix
bindir = $bindir
template_dir = $git_template_dir
GIT_EXEC_PATH = $git_exec_path
CFG_GIT_EXEC_PATH := $git_exec_path
GIT_PYTHON_DIR = $git_python_dir

# SHA1 method
$sha1 = YesPlease

# paths to system tools
SHELL_PATH = $shell
PERL_PATH = $perl
PYTHON_PATH = $python
TAR = $tar
INSTALL = $install

# Compilation options, library paths etc. etc.
EOF

# http transport support
if [ "$enable_http" = Yes ]; then
	echo "# HTTP transport is enabled" >> $outfile
	echo 'PROGRAMS += git-http-fetch$X' >> $outfile
	if [ "$curl_dir" ]; then
		cflag -I$curl_dir/include
		echo "CURL_LIBCURL = -L$curl_dir/lib"
	fi
	echo "CURL_LIBCURL += -lcurl" >> $outfile
	if [ "$enable_expat" = Yes ]; then
		echo "# expat (push over http) is enabled" >> $outfile
		echo 'PROGRAMS += git-http-push$X' >> $outfile

		if [ "$expat_dir" ]; then
			cflag -I$expat_dir/include
			echo "EXPAT_LIBEXPAT = -L$expat_dir/lib" >> $outfile
		fi
		echo "EXPAT_LIBEXPAT += -lexpat" >> $outfile
	fi

fi

cat << EOF

Configuration summary:
----------------------

Compilation options:
SHA1 method : $sha1
HTTP transport : $enable_http
HTTP push support : $enable_expat

System tools locations:

    shell   : $shell
    Perl    : $perl
    Python  : $python
    tar     : $tar

install : $install

Installation paths:
bindir utilities : $bindir
templates : $git_template_dir
python scripts : $git_python_dir
Everything else : $git_exec_path

Please see config.mak and top of Makefile for ways to tweak the build further. EOF

#2 lore raw

Dear diary, on Mon, Nov 14, 2005 at 01:18:52PM CET, I got a letter where Andreas Ericsson <[email protected]> said that...

Quoted 2 lines
		--prefix=*)
			prefix=${1##*=}

Aren't those heavy bashisms?

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#3 lore raw

On Mon, Nov 14, 2005 at 02:29:56PM +0100, Petr Baudis wrote:

| Dear diary, on Mon, Nov 14, 2005 at 01:18:52PM CET, I got a letter
| where Andreas Ericsson <[email protected]> said that...
| > 		--prefix=*)
| > 			prefix=${1##*=}
| 
| Aren't those heavy bashisms?

As far as I know, it should be supported by a POSIX 'sh'[1]:

---8<---
${parameter##word}

Remove Largest Prefix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the largest portion of the prefix matched by the pattern deleted. ---8<---

Whether other shells support it or not... I don't know.

Cheers,
Ferdy

[1] http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html

Signature · 3 lines
Fernando J. Pereda Garcimartin
Gentoo Developer (Alpha,net-mail,mutt,git)
20BB BDC3 761A 4781 E6ED  ED0B 0A48 5B0C 60BD 28D4
#4 lore raw
In reply to Petr Baudis
Quoted 4 lines · Petr Baudis

Dear diary, on Mon, Nov 14, 2005 at 01:18:52PM CET, I got a letter where Andreas Ericsson <[email protected]> said that...

Quoted 2 lines
		--prefix=*)
			prefix=${1##*=}
	${i# and ${i% are POSIX, iirc.

Joel

Signature · 10 lines
Life's Little Instruction Book #197

	"Don't forget, a person's greatest emotional need is to 
	 feel appreciated."

Joel Becker
Principal Software Developer
Oracle
E-mail: [email protected]
Phone: (650) 506-8127
#5 lore raw
Quoted 7 lines · Joel Becker
Quoted 4 lines · Petr Baudis

Dear diary, on Mon, Nov 14, 2005 at 01:18:52PM CET, I got a letter where Andreas Ericsson <[email protected]> said that...

Quoted 2 lines
		--prefix=*)
			prefix=${1##*=}
	${i# and ${i% are POSIX, iirc.

They may be in POSIX, but they sure as h*ll aren't portable.

There's a _lot_ of machines out there that don't do POSIX, just because those "newfangled" things are so complicated.

Also, even in POSIX, there's tons of different substandards, and you might follow one but not the other.

Finally, even if somebody is certified, they can very well be certified with "exceptions", so if they claim POSIX it doesn't necessarily mean that they follow all of it.

If you want to do a "configure" script (and I'm not sure it's worth it), you should cater to the lowest common denominator for it to be meaningful. What the hell that would be, I have no idea, since if you ever want to run on native Windows, it won't even be traditional shell. But traditional shell is at least a lot closer to that lowest common denominator than POSIX shell is.

That said, most of those ${var...} sequences definitely _are_ very traditional, and for all I know, ## may be too.

Linus

#6 lore raw
Quoted 3 lines · Linus Torvalds
Quoted 1 line
	${i# and ${i% are POSIX, iirc.

They may be in POSIX, but they sure as h*ll aren't portable.

By POSIX I meant POSIX shell, which is ksh. That's available on
just about all modern non-free Unices, and we all know bash and zsh are compatible with it.
But I had no intention of arguing how portable POSIX is, I was
just trying to describe the minimum breadth of support. My personal experience is that these particular variable forms have worked on Linux, Solaris, AIX, Ultrix, IRIX, and the BSDs for, I dunno, eight to ten years or so.

	That said, $(echo | sed), or `echo | sed` for even more

backwards portability (I bet $() is about as portable as ${i%}), can be used to replace the ${i%} forms.

Joel

Signature · 9 lines
"I always thought the hardest questions were those I could not answer.
 Now I know they are the ones I can never ask."
			- Charlie Watkins

Joel Becker
Principal Software Developer
Oracle
E-mail: [email protected]
Phone: (650) 506-8127
#7 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 5 lines · Joel Becker
Quoted 3 lines · Petr Baudis

Dear diary, on Mon, Nov 14, 2005 at 01:18:52PM CET, I got a letter where Andreas Ericsson <[email protected]> said that...

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
		--prefix=*)
			prefix=${1##*=}
	${i# and ${i% are POSIX, iirc.

They may be in POSIX, but they sure as h*ll aren't portable.

A bit funny really. I've already said I'll change them to some sed thing, so the last 16 emails on this thread have been purely academic. I guess more people than me are bored by mondays.

Quoted 1 line

If you want to do a "configure" script (and I'm not sure it's worth it),

Perhaps not. I was under the impression that Junio was for it to simplify the possible move of binaries to GIT_EXEC_PATH.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#8 lore raw
Quoted 7 lines · Andreas Ericsson
Quoted 2 lines · Linus Torvalds

If you want to do a "configure" script (and I'm not sure it's worth it),

Perhaps not. I was under the impression that Junio was for it to simplify the possible move of binaries to GIT_EXEC_PATH.

I do not see how that is related to it.

Offtopic, but if you really want to do ${var##} and friends portably, expr(1) is the tool traditionalists prefer; not echo piped to sed, please.

#9 lore raw
In reply to Petr Baudis
Quoted 9 lines · Petr Baudis

Dear diary, on Mon, Nov 14, 2005 at 01:18:52PM CET, I got a letter where Andreas Ericsson <[email protected]> said that...

Quoted 2 lines
		--prefix=*)
			prefix=${1##*=}

Aren't those heavy bashisms?

Dunno. I only know bash-scripting, really. I'll replace them with some sed thing instead.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#10 lore raw
Quoted 2 lines · Andreas Ericsson

Dunno. I only know bash-scripting, really. I'll replace them with some sed thing instead.

For some people /bin/sh != /bin/bash so you probably want "!/bin/bash" instead.

#11 lore raw
Quoted 9 lines · Chris Wedgwood
Quoted 2 lines · Andreas Ericsson

Dunno. I only know bash-scripting, really. I'll replace them with some sed thing instead.

For some people /bin/sh != /bin/bash so you probably want "!/bin/bash" instead.

Ach no. The configure script really needs to be portable. POSIX (or SUS or some such) define a minimum syntax that any shell must support when invoked as /bin/sh.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#12 lore raw
Quoted 3 lines · Andreas Ericsson

Ach no. The configure script really needs to be portable. POSIX (or SUS or some such) define a minimum syntax that any shell must support when invoked as /bin/sh.

Then bashism need to go away and it should be test with dash/ash/whatever.