cake
/
p7utils
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
p7utils/configure

191 lines
6.0 KiB
Bash
Executable File

#!/bin/sh
cd "$(dirname "$0")"
#******************************************************************************#
# Defaults #
#******************************************************************************#
# Project variables
name="$(make -s getname)"
version="$(make -s getversion)"
maintainer="$(make -s getmaintainer)"
# Make options
make_full_log=
more_warnings=
# Build options
target=
windows=
default_zoom=8
default_storage=fls0
# Installation directories
root=''
prefix='${root}/opt/p7-project'
bindir='${prefix}/bin'
mandir='${prefix}/share/man'
# Installation options
install_manpages=yes
#******************************************************************************#
# Help message #
#******************************************************************************#
usage() {
cat <<EOF
\`configure\` configures ${name} to adapt to systems that aren't mine.
Usage: $0 [OPTIONS]
Defaults for the options are specified in brackets.
General options:
--help display this help and exit
--version display version information and quit
--make-full-log display full commands while making
--maintainer enable maintainer mode
Build options:
--target=TARGET the build target [$target]
--default-zoom=ZOOM the default zoom for \`p7screen\` [$default_zoom]
--default-storage=STOR the default storage device [$default_storage]
Installation options:
--no-manpages do not install manpages
Installation directories:
--root=ROOT installation root [$root]
--prefix=PREFIX main installation prefix [$prefix]
Fine tuning of the installation directories:
--bindir=DIR user executables, not "dustbin" [$bindir]
--mandir=DIR man root [$mandir]
Report bugs to ${maintainer}.
EOF
exit 0
}
#******************************************************************************#
# Version message #
#******************************************************************************#
version() {
cat <<EOF
${name} configure script v${version}
Hand-written by Thomas "Cakeisalie5" Touhey.
This configure script is free software.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit 0
}
#******************************************************************************#
# Check for help and version #
#******************************************************************************#
put_version=
put_help=
for arg ; do case "$arg" in
--help|-h) put_help=y ;;
--version|-v) put_version=y ;;
esac; done
[ $put_version ] && version
[ $put_help ] && usage
#******************************************************************************#
# Parse arguments #
#******************************************************************************#
for arg ; do case "$arg" in
--make-full-log) make_full_log=yes ;;
--target=*) target="${arg#*=}" ;;
--maintainer) install_manpages=; more_warnings=yes ;;
--default-zoom=*)
zoom="${arg#*=}"
if ! [ $zoom -eq $zoom 2>/dev/null ]; then
echo "--default-zoom: a number is expected (got \"$zoom\")" >&2
elif [ $zoom -lt 1 ]; then
echo "--default-zoom: should be 1 or more (got $zoom)" >&2
elif [ $zoom -gt 16 ]; then
echo "--default-zoom: should be 16 or less (got $zoom)" >&2
else default_zoom=$zoom; fi ;;
--default-storage=*)
storage="${arg#*=}"
# check if 4 chars long
if [ ! $(echo "$storage" | wc -c ) -eq 5 ]; then
echo "$0: --default-storage: must be 4 characters long"
continue
fi
# then set
default_storage="$storage" ;;
--no-manpages) install_manpages= ;;
--root=*) root="${arg#*=}" ;;
--prefix=*) prefix="${arg#*=}" ;;
--bindir=*) bindir="${arg#*=}" ;;
--mandir=*) mandir="${arg#*=}" ;;
*) echo "$arg: didn't read" ;;
esac; done
#******************************************************************************#
# Little things #
#******************************************************************************#
# Cross-compilation things
if [ ! $prefix_set ] && [ $target ]; then
prefix="$prefix"/"$target"
fi
# Check MS-Windows targets
case "$target" in *-mingw32) windows=y ;; esac
# Evaluate variables
for var in prefix bindir mandir; do
eval $var'='$(eval 'echo $'$var)
done
# Check if is on Cygwin
[ "$(expr substr "$(uname -s)" 1 10)" = "MINGW32_NT" ] && windows=y
# If on MS-Windows, do not make the manpages.
[ "$windows" ] && install_manpages=
#******************************************************************************#
# Create Makefile configuration #
#******************************************************************************#
# Clean before.
make mrproper MAKE_FULL_LOG=y 1>/dev/null 2>/dev/null
# Do it!
exec 3>&1 1>Makefile.cfg
cat <<EOF
#!/usr/bin/make -f
#******************************************************************************#
# Makefile configuration generated by ./configure #
#******************************************************************************#
# Configuration version and messages configuration
CONFIG_VERSION := $version
MAKE_FULL_LOG := $make_full_log
MORE_WARNINGS := $more_warnings
# Build options
TARGET := $target
FOR_WINDOWS := $windows
DEFAULT_ZOOM := $default_zoom
DEFAULT_STORAGE := $default_storage
# Installation directories
IBINDIR := $bindir
IMANDIR := $mandir
# Installation options
INSTALL_MANPAGES := $install_manpages
# End of file.
EOF
exec 1>&3 3>&-
chmod +x Makefile.cfg
#******************************************************************************#
# Finish #
#******************************************************************************#
echo "Configuration loaded, you can make now."
# End of file.