view configure @ 53:62d82881799f

Update python versions to probe.
author David A. Holland
date Sat, 02 Apr 2022 21:15:27 -0400
parents 923ea629c29f
children
line wrap: on
line source

#!/bin/sh
# configure - configure swallowtail
# usage: see configure --help
# note: this is not an autoconf-generated script

help() {
	cat <<EOF
Usage: $0 [args]
where args can be:
	--help			Print usage
	--destdir=DIR		Set install chroot [none]
	--prefix=DIR		Set install prefix [/usr/local]
	--python=FILE		Set path to Python interpreter [probed]
	--sh=FILE		Set path to Bourne shell [/bin/sh]
EOF
}

usage() {
	echo "Usage: $0 [args}" 1>&2
	echo "Try --help" 1>&2
}

############################################################
# args

DESTDIR=
PREFIX=/usr/local
PYTHON=probed
SH=/bin/sh

for ARG in "$@"; do
	case "$ARG" in
		--help) help; exit;;
		--destdir=*) DESTDIR=`echo "$ARG" | sed 's/^[^=]*=//'`;;
		--prefix=*) PREFIX=`echo "$ARG" | sed 's/^[^=]*=//'`;;
		--python=*) PYTHON=`echo "$ARG" | sed 's/^[^=]*=//'`;;
		--sh=*) SHELL=`echo "$ARG" | sed 's/^[^=]*=//'`;;
		*) usage; exit 1;;
	esac
done

############################################################
# check for python

echo -n 'Checking for python... '

nopython() {
	echo "failed"
	echo "$0: $1" 1>&2
	echo "$0: Install python or use --python=PATH option" 1>&2
	exit 1
}

testpython() {
	if [ ! -x "$1" ]; then
		return 1
	fi
	VER=$("$1" -V 2>&1)
	case "$VER" in
		"Python "*.*.*) return 0;;
		"Python "*.*) return 0;;
		*) ;;
	esac
	return 1
}

FOUND=0
case "$PYTHON" in
	probed)
		for D in \
		    /usr/local/bin \
		    /usr/pkg/bin \
		    /usr/contrib/bin \
		    /usr/bin \
		    /opt/bin \
		; do
			for PY in \
				python \
				python3.10 python310 \
				python3.9 python39 \
				python3.8 python38 \
				python3.7 python37 \
			; do
				if testpython $D/$PY; then
					PYTHON="$D/$PY"
					FOUND=1
					break
				fi
			done
			if [ $FOUND = 1 ]; then
				break
			fi
		done
		if [ $FOUND = 0 ]; then
			nopython "Cannot find python"
		fi
	;;
	/*)
		if testpython "$PYTHON"; then
			:
		else
			nopython "$PYTHON does not appear to be python"
		fi
	;;
	*)
		nopython "$PYTHON is not an absolute path"
	;;
esac
echo "$PYTHON"

############################################################
# Generate config.*

echo 'Generating config.sed'

cat > config.sed.new <<EOF
s,@PYTHON@,$PYTHON,
s,@SH@,$SH,
EOF

mv -f config.sed.new config.sed

echo 'Generating config.mk'

cat > config.mk.new <<EOF
DESTDIR=$DESTDIR
PREFIX=$PREFIX
EOF

mv -f config.mk.new config.mk

############################################################
# done

exit 0