Browse Source
You can use environment variables or the commandline to set defaults. It looks very autoconf, but you don't need to learn m4. Doesn't cover all the obscure flags, but it's easy to extend. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
Rusty Russell
7 years ago
committed by
Christian Decker
2 changed files with 101 additions and 0 deletions
@ -0,0 +1,99 @@ |
|||
#! /bin/sh |
|||
# Simple configure script for c-lightning. |
|||
|
|||
set -e |
|||
|
|||
# Default values, loaded from environment or canned. |
|||
PREFIX=${PREFIX:-/usr/local} |
|||
CC=${CC:-cc} |
|||
CWARNFLAGS=${CWARNFLAGS:--Werror -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition} |
|||
CDEBUGFLAGS=${CDEBUGFLAGS:--std=gnu11 -g -fstack-protector} |
|||
DEVELOPER=${DEVELOPER:-0} |
|||
COMPAT=${COMPAT:-1} |
|||
CONFIGURATOR_CC=${CONFIGURATOR_CC:-$CC} |
|||
|
|||
CONFIGURATOR=ccan/tools/configurator/configurator |
|||
CONFIG_VAR_FILE=config.vars |
|||
CONFIG_HEADER=ccan/config.h |
|||
|
|||
usage_with_default() |
|||
{ |
|||
if [ $# = 4 ]; then |
|||
if [ $2 ]; then |
|||
DEF=$4 |
|||
else |
|||
DEF=$3 |
|||
fi |
|||
else |
|||
DEF=$2 |
|||
fi |
|||
echo " $1 (default $DEF)" |
|||
} |
|||
|
|||
usage() |
|||
{ |
|||
echo "Usage: ./configure [--reconfigure] [setting=value] [options]" |
|||
echo "If --reconfigure is specified, $CONFIG_VAR_FILE will set defaults if it exists." |
|||
echo "Default settings:" |
|||
usage_with_default "CC" "$CC" |
|||
usage_with_default "CWARNFLAGS" "$CWARNFLAGS" |
|||
usage_with_default "CDEBUGFLAGS" "$CDEBUGFLAGS" |
|||
usage_with_default "CONFIGURATOR_CC" "$CONFIGURATOR_CC" |
|||
echo " To override compile line for configurator itself" |
|||
|
|||
echo "Options include:" |
|||
usage_with_default "--prefix=" "$PREFIX" |
|||
echo " Prefix for make install" |
|||
usage_with_default "--enable/disable-developer" "$DEVELOPER" "enable" "disable" |
|||
echo " Developer mode, good for testing" |
|||
usage_with_default "--enable/disable-compat" "$COMPAT" "enable" "disable" |
|||
echo " Compatibility mode, good to disable to see if your software breaks" |
|||
exit 1 |
|||
} |
|||
|
|||
add_var() |
|||
{ |
|||
echo "Setting $1... $2" |
|||
echo "$1=$2" >> $CONFIG_VAR_FILE |
|||
[ -z "$3" ] || echo "#define $1 $2" >> "$3" |
|||
} |
|||
|
|||
for opt in "$@"; do |
|||
case "$opt" in |
|||
--reconfigure) |
|||
# Escape spaces for things like CWARNFLAGS. |
|||
sed 's/=\(.*\)$/="\1"/' $CONFIG_VAR_FILE > $CONFIG_VAR_FILE.$$ |
|||
. ./$CONFIG_VAR_FILE.$$ |
|||
;; |
|||
CC=*) CC="${opt#CC=}";; |
|||
CONFIGURATOR_CC=*) CONFIGURATOR_CC="${opt#CONFIGURATOR_CC=}";; |
|||
CWARNFLAGS=*) CWARNFLAGS="${opt#CWARNFLAGS=}";; |
|||
CDEBUGFLAGS=*) CDEBUGFLAGS="${opt#CDEBUGFLAGS=}";; |
|||
--prefix=*) PREFIX="${opt#--prefix=}";; |
|||
--enable-developer) DEVELOPER=1;; |
|||
--disable-developer) DEVELOPER=0;; |
|||
--enable-compat) COMPAT=1;; |
|||
--disable-compat) COMPAT=0;; |
|||
--help|-h) usage;; |
|||
*) |
|||
echo "Unknown option '$opt'" >&2 |
|||
usage |
|||
;; |
|||
esac |
|||
done |
|||
|
|||
echo -n "Compiling $CONFIGURATOR..." |
|||
$CC $CWARNFLAGS $CDEBUGFLAGS -o $CONFIGURATOR $CONFIGURATOR.c |
|||
echo "done" |
|||
|
|||
rm -f $CONFIG_VAR_FILE.$$ |
|||
$CONFIGURATOR --autotools-style --var-file=$CONFIG_VAR_FILE.$$ --header-file=$CONFIG_HEADER --configurator-cc="$CONFIGURATOR_CC" "$CC" $CWARNFLAGS $CDEBUGFLAGS |
|||
mv $CONFIG_VAR_FILE.$$ $CONFIG_VAR_FILE |
|||
|
|||
add_var PREFIX "$PREFIX" |
|||
add_var CC "$CC" |
|||
add_var CONFIGURATOR_CC "$CONFIGURATOR_CC" |
|||
add_var CWARNFLAGS "$CWARNFLAGS" |
|||
add_var CDEBUGFLAGS "$CDEBUGFLAGS" |
|||
add_var DEVELOPER "$DEVELOPER" $CONFIG_HEADER |
|||
add_var COMPAT "$COMPAT" $CONFIG_HEADER |
Loading…
Reference in new issue