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

171 lines
5.4 KiB
Bash
Executable File

#!/bin/sh
cd "$(dirname "$0")"
#******************************************************************************#
# Defaults #
#******************************************************************************#
# Project variables
name="$(make -s getname)"
version="$(make -s getversion)"
# Author
author="$(make -s getauthor)"
author_name="$(make -s getauthor_name)"
# Target
target=""
# Make options
make_full_log=
# Build options
default_zoom=8
default_storage=fls0
# Installation directories
root=''
prefix='${root}/usr'
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
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:
--noinstall-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 ${author}.
EOF
exit 0
}
#******************************************************************************#
# Version message #
#******************************************************************************#
version() {
cat <<EOF
${name} configure script v${version}
Hand-written by ${author_name}.
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#*=}" ;;
--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" ;;
--noinstall-manpages) install_manpages= ;;
--root=*) root="${arg#*=}" ;;
--prefix=*) prefix="${arg#*=}" ;;
--bindir=*) bindir="${arg#*=}" ;;
--mandir=*) mandir="${arg#*=}" ;;
*) echo "$arg: didn't read" ;;
esac; done
#******************************************************************************#
# Evaluate variables #
#******************************************************************************#
for var in prefix bindir mandir; do
eval $var'='$(eval 'echo $'$var)
done
#******************************************************************************#
# Create Makefile configuration #
#******************************************************************************#
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
# Build options
TARGET := $target
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.