libp7/configure

299 lines
9.1 KiB
Bash
Executable File

#!/bin/sh
cd "$(dirname "$0")"
#******************************************************************************#
# Defaults #
#******************************************************************************#
# Project variables
name="$(make -s getname)"
version="$(make -s getversion)"
maintainer="$(make -s getmaintainer)"
# Platform
platform="$(command -v gcc 1>/dev/null && gcc --print-multiarch)"
platform="$([ "$platform" ] && echo "/$platform")"
# Make options
make_full_log=
more_warnings=
# Build options
target=
static=
windows=
optimize_size=
gint=
libusb=y
no_file=
loglevel=none # none, info, warn, error, fatal
init_tries=5
# Installation directories
root=''
prefix='${root}/usr'
prefix_set=
bindir='${prefix}/bin'
libdir='${prefix}/lib'"$platform"
includedir='${prefix}/include'"$platform"
pkgdir='${libdir}/pkgconfig'
mandir='${prefix}/share/man'
sysconfdir='${root}/etc'
udevrulesdir='${sysconfdir}/udev/rules.d'
# Installation options
install_manpages=yes
install_devel=yes
install_udev=
# Tweaks
cflags=
ldflags=
#******************************************************************************#
# Help message #
#******************************************************************************#
usage() {
cat <<EOF
\`configure\` configures ${name} to adapt to systems that aren't mine.
Usage: $0 [OPTION]
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 target (if none, native)
--static build a static library (by default, dynamic)
--windows build DLLs and .libs instead of ELF and archives
--optimize-size optimize size instead of speed
--gint build for gint
--no-libusb do not use libusb
--no-file do not use the libc FILE interface
--no-manpages do not make and install manpages
--loglevel=LEVEL library log level [$loglevel]
--init-tries=TRIES default number of detection tries [$init_tries]
Installation options:
--no-devel should not install developement files
--udev install the udev rule
Installation directories:
--root=ROOT installation root [$root]
--prefix=PREFIX main installation prefix [$prefix]
Fine tuning of the installation directories:
--bindir=DIR executables [$bindir]
--pkgdir=DIR pkg-config configurations directory [$pkgdir]
--libdir=DIR library files of the linker [$libdir]
--includedir=DIR include files for the compiler [$includedir]
--mandir=DIR man root [$mandir]
--sysconfdir=DIR system configuration directory [$sysconfdir]
--udevrulesdir=DIR udev rules directory [$udevrulesdir]
Other tweaks:
CFLAGS=CFLAGS some more compilation flags
LDFLAGS=LDFLAGS some more linker flags
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=1 ;;
--version|-v) put_version=1 ;;
esac; done
[ $put_version ] && version
[ $put_help ] && usage
#******************************************************************************#
# Parse arguments #
#******************************************************************************#
for arg ; do case "$arg" in
--make-full-log) make_full_log=yes ;;
--maintainer) more_warnings=yes; loglevel=info ;;
--target=*) target="${arg#*=}" ;;
--static) static=y ;;
--windows) windows=y ;;
--optimize-size) optimize_size=y ;;
--gint) gint=y ;;
--no-libusb) libusb= ;;
--no-file) no_file=y ;;
--loglevel=*)
level="${arg#*=}"
if ! [ $level = "info" ] && ! [ $level = "warn" ] \
&& ! [ $level = "error" ] && ! [ $level = "fatal" ] \
&& ! [ $level = "none" ]; then
echo \
"$0 : --loglevel: expected one of [info, warn, error, fatal, none], \
got '$level'"
continue
fi
loglevel=$level ;;
--init-tries=*)
tries="${arg#*=}"
if ! [ "$tries" -eq "$tries" ] 2>/dev/null; then
echo "$0 : --tries: expected number, got '"$tries"'"
continue
elif [ $tries -le 0 ]; then
echo "$0 : --tries: should be greater than zero"
continue
fi
init_tries=$tries ;;
--no-manpages) install_manpages= ;;
--no-devel) install_devel= ;;
--udev) install_udev=yes ;;
--root=*) root="${arg#*=}" ;;
--prefix=*) prefix="${arg#*=}"; prefix_set=y ;;
--bindir=*) bindir="${arg#*=}" ;;
--pkgdir=*) pkgdir="${arg#*=}" ;;
--libdir=*) libdir="${arg#*=}" ;;
--includedir=*) includedir="${arg#*=}" ;;
--mandir=*) mandir="${arg#*=}" ;;
--sysconfdir=*) sysconfdir="${arg#*=}" ;;
--udevrulesdir=*) udevrulesdir="${arg#*=}" ;;
CFLAGS=*) cflags="${arg#*=}" ;;
LDFLAGS=*) ldflags="${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
win_target=
case "$target" in *-mingw32) if [ ! "$static" ]; then
windows=y; win_target=y
fi;; esac
# Evaluate variables
vars="prefix sysconfdir bindir libdir pkgdir includedir mandir udevrulesdir"
for var in $vars; do
eval $var'='$(eval 'echo $'$var)
done
# Check that static and MS-Windows are not asked.
if [ "$static" ] && [ "$windows" ]; then
cat >&2 <<EOF
Sadly, there is no equivalent of MSVC's LIB.EXE for GNU/Linux.
If you know one, contact the maintainer: see \`./configure --help\`.
EOF
exit 1
fi
# Check that MS-Windows has a target.
if [ "$windows" ] && [ ! "$target" ]; then
cat >&2 <<EOF
You have selected the --windows option, but have selected no target.
If you want to build for native use, use a mingw32/mingw64 target.
If you want to build for a cross-compiling use, specify an other target!
EOF
exit 1
fi
# Check if is on Cygwin
[ "$(expr substr "$(uname -s)" 1 10)" = "MINGW32_NT" ] && windows=y
# Check that MS-Windows has a mingw* target.
if [ "$windows" ] && [ ! "$win_target" ]; then
cat >&2 <<EOF
You have selected the --windows option, but have not selected a mingw32/mingw64
BFD target. We supposed that it is because you are compiling libp7 for a
cross-compiler compiled for MS-Windows (that's why configuration won't fail).
If it is not, please reconfigure to use a mingw32/mingw64 toolchain!
EOF
fi
# If gint, select no-file.
[ "$gint" ] && no_file=y && libusb=
#******************************************************************************#
# Create Makefile configuration #
#******************************************************************************#
# Clean before.
make mrproper MAKE_FULL_LOG=y 1>/dev/null 2>/dev/null
# Create the configuration header
opt="--version=${version} "
[ "$gint" ] && opt+="--gint "
[ "$no_file" ] && opt+="--no-file "
tools/write-header-config $opt >include/libp7/config.h
# 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
FOR_WINDOWS := $windows
# Build options
STATIC := $static
TARGET := $target
OPTIMIZE_SIZE := $optimize_size
USE_LIBUSB := $libusb
LOG_LEVEL := $loglevel
INIT_TRIES := $init_tries
# Installation directories
IBINDIR := $bindir
IPKGDIR := $pkgdir
ILIBDIR := $libdir
IINCDIR := $includedir
IMANDIR := $mandir
IUDEVDIR := $udevrulesdir
# Installation options
INSTALL_MANPAGES := $install_manpages
INSTALL_DEVEL := $install_devel
INSTALL_UDEV := $install_udev
# Other tweaks
CMOREFLAGS := $cflags
LDMOREFLAGS := $ldflags
# End of file.
EOF
exec 1>&3 3>&-
chmod +x Makefile.cfg
# Print the end message.
echo "Configuration loaded, you can make now."
# End of file.