core-lightning/configure
Rusty Russell 6b32b72dee configure: use "-Og" for non-developer builds, add COPTFLAGS variable.
Unfortuntely we get spurious uninitialized variable warnings with
anything but -O3 or no optimization, so set default CWARNFLAGS
appropriately.

MCP bench results without optimization:
   store_load_msec:28509-31001(29206.6+/-9.4e+02)
   vsz_kb:580004-580016(580006+/-4.8)
   store_rewrite_sec:11.640000-12.730000(11.908+/-0.41)
   listnodes_sec:1.790000-1.880000(1.83+/-0.032)
   listchannels_sec:21.180000-21.950000(21.476+/-0.27)
   routing_sec:2.210000-11.160000(7.126+/-3.1)
   peer_write_all_sec:36.270000-41.200000(38.168+/-1.9)

MCP bench with -Og: 22% speedup vs no optimization
   store_load_msec:21963-23645(22841+/-6.6e+02)
   vsz_kb:579916
   store_rewrite_sec:10.080000-10.960000(10.456+/-0.3)
   listnodes_sec:1.280000-1.390000(1.338+/-0.047)
   listchannels_sec:14.770000-16.080000(15.518+/-0.46)
   routing_sec:0.990000-6.660000(3.958+/-2.2)
   peer_write_all_sec:29.950000-32.950000(31.138+/-1)

MCP bench with -O2: 31% speedup vs no optimization
   store_load_msec:20713-22088(21505.6+/-4.8e+02)
   vsz_kb:579928
   store_rewrite_sec:9.570000-11.200000(10.192+/-0.54)
   listnodes_sec:0.960000-1.090000(1.028+/-0.045)
   listchannels_sec:10.400000-11.770000(11.012+/-0.48)
   routing_sec:0.300000-3.140000(1.978+/-1.1)
   peer_write_all_sec:28.980000-30.310000(29.572+/-0.44)

MCP bench with -O3 -flto: 36% speedup vs no optimization
   store_load_msec:19616-20191(19862.6+/-1.9e+02)
   vsz_kb:578452
   store_rewrite_sec:8.980000-9.960000(9.55+/-0.32)
   listnodes_sec:0.920000-1.910000(1.18+/-0.38)
   listchannels_sec:8.960000-9.450000(9.206+/-0.16)
   routing_sec:0.730000-1.850000(1.438+/-0.42)
   peer_write_all_sec:28.090000-29.410000(28.772+/-0.42)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-16 15:39:56 -04:00

228 lines
6.5 KiB
Bash
Executable File

#! /bin/sh
# Simple configure script for c-lightning.
set -e
# Default values, loaded from environment or canned.
PREFIX=${PREFIX:-/usr/local}
CC=${CC:-cc}
CDEBUGFLAGS=${CDEBUGFLAGS:--std=gnu11 -g -fstack-protector}
DEVELOPER=${DEVELOPER:-0}
EXPERIMENTAL_FEATURES=${EXPERIMENTAL_FEATURES:-0}
COMPAT=${COMPAT:-1}
STATIC=${STATIC:-0}
CONFIGURATOR_CC=${CONFIGURATOR_CC:-$CC}
ASAN=${ASAN:-0}
CONFIGURATOR=ccan/tools/configurator/configurator
CONFIG_VAR_FILE=config.vars
CONFIG_HEADER=ccan/config.h
usage_with_default()
{
if [ $# = 4 ]; then
if [ "$2" = 1 ]; then
DEF=$3
else
DEF=$4
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"
usage_with_default "PYTEST" "$PYTEST"
usage_with_default "COPTFLAGS" "$COPTFLAGS"
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-experimental-features" "$EXPERIMENTAL_FEATURES" "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"
usage_with_default "--enable/disable-valgrind" "(autodetect)"
echo " Valgrind binary to use for tests"
usage_with_default "--enable/disable-static" "$STATIC" "enable" "disable"
echo " Static link binary"
usage_with_default "--enable/disable-address-sanitizer" "$ASAN" "enable" "disable"
echo " Compile with address-sanitizer"
exit 1
}
add_var()
{
if [ -n "$2" ]; then
echo "Setting $1... $2"
else
echo "$1 not found"
fi
echo "$1=$2" >> $CONFIG_VAR_FILE
[ -z "$3" ] || echo "#define $1 $2" >> "$3"
}
find_pytest()
{
PYTEST_BINS="pytest-3 pytest3 pytest py.test"
for p in $PYTEST_BINS; do
if [ "$(which $p)" != "" ] ; then
"$p" --version 2>&1 | grep -q "python3" || continue
echo "$p"
return
fi
done
PYTHON_BINS="python python3"
for p in $PYTHON_BINS; do
if [ "$(which $p)" != "" ] ; then
$p --version 2>&1 | grep -q "Python 3." || continue
if $p -c "import pytest" 2>/dev/null ; then
echo "$p -m pytest"
return
fi
fi
done
}
PYTEST=${PYTEST:-`find_pytest`}
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=}";;
COPTFLAGS=*) COPTFLAGS="${opt#COPTFLAGS=}";;
PYTEST=*) PYTEST="${opt#PYTEST=}";;
--prefix=*) PREFIX="${opt#--prefix=}";;
--enable-developer) DEVELOPER=1;;
--disable-developer) DEVELOPER=0;;
--enable-experimental-features) EXPERIMENTAL_FEATURES=1;;
--disable-experimental-features) EXPERIMENTAL_FEATURES=0;;
--enable-compat) COMPAT=1;;
--disable-compat) COMPAT=0;;
--enable-valgrind) VALGRIND=1;;
--disable-valgrind) VALGRIND=0;;
--enable-static) STATIC=1;;
--disable-static) STATIC=0;;
--enable-address-sanitizer) ASAN=1;;
--disable-address-sanitizer) ASAN=0;;
--help|-h) usage;;
*)
echo "Unknown option '$opt'" >&2
usage
;;
esac
done
# Default COPTFLAGS is only set if not developer
if [ -z ${COPTFLAGS+x} ]; then
if [ "$DEVELOPER" = 0 ]; then
COPTFLAGS="-Og"
else
COPTFLAGS=""
fi
fi
# We only enable Werror if we're -O3 or no-optimization. Otherwise gcc gives
# false positives.
if [ -z ${CWARNFLAGS+x} ]; then
CWARNFLAGS="-Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition"
if [ -x ${COPTFLAGS+x} ] || [ -z "${COPTFLAGS##*-O3*}" ]; then
CWARNFLAGS="$CWARNFLAGS -Werror"
fi
fi
echo -n "Compiling $CONFIGURATOR..."
$CC $CWARNFLAGS $CDEBUGFLAGS $COPTFLAGS -o $CONFIGURATOR $CONFIGURATOR.c
echo "done"
if [ -z "$VALGRIND" ]; then
if valgrind -q --error-exitcode=7 --track-origins=yes --leak-check=full --show-reachable=yes --errors-for-leak-kinds=all $CONFIGURATOR --help >/dev/null 2>&1; then
VALGRIND=1
else
VALGRIND=0
fi
fi
if [ "$ASAN" = "1" ]; then
if [ "$CC" = "clang" ]; then
echo "Address sanitizer (ASAN) is currently only supported with gcc"
exit 1
fi
if [ "$VALGRIND" = "1" ]; then
echo "Address sanitizer (ASAN) and valgrind cannot be enabled at the same time"
exit 1
fi
fi
rm -f $CONFIG_VAR_FILE.$$
$CONFIGURATOR --extra-tests --autotools-style --var-file=$CONFIG_VAR_FILE.$$ --header-file=$CONFIG_HEADER --configurator-cc="$CONFIGURATOR_CC" "$CC" $CWARNFLAGS $CDEBUGFLAGS $COPTFLAGS <<EOF
var=HAVE_GOOD_LIBSODIUM
desc=libsodium with IETF chacha20 variants
style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE
link=-lsodium
code=
#include <sodium.h>
#include <stdio.h>
int main(void)
{
printf("%p\n", crypto_aead_chacha20poly1305_ietf_encrypt);
printf("%d\n", crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
return 0;
}
/*END*/
var=HAVE_SQLITE3_EXPANDED_SQL
desc=sqlite3_expanded_sql
style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE
link=-lsqlite3
code=
#include <sqlite3.h>
#include <stdio.h>
int main(void)
{
printf("%p\n", sqlite3_expanded_sql);
return 0;
}
/*END*/
EOF
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 COPTFLAGS "$COPTFLAGS"
add_var VALGRIND "$VALGRIND"
add_var DEVELOPER "$DEVELOPER" $CONFIG_HEADER
add_var EXPERIMENTAL_FEATURES "$EXPERIMENTAL_FEATURES" $CONFIG_HEADER
add_var COMPAT "$COMPAT" $CONFIG_HEADER
add_var PYTEST "$PYTEST"
add_var STATIC "$STATIC"
add_var ASAN "$ASAN"
# Hack to avoid sha256 name clash with libwally: will be fixed when that
# becomes a standalone shared lib.
echo '#include "ccan_compat.h"' >> $CONFIG_HEADER