forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·144 lines (128 loc) · 4.15 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /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" = 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"
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"
usage_with_default "--enable/disable-valgrind" "(autodetect)"
echo " Valgrind binary to use for tests"
exit 1
}
add_var()
{
echo "Setting $1... $2"
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" ; 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=}";;
PYTEST=*) PYTEST="${opt#PYTEST=}";;
--prefix=*) PREFIX="${opt#--prefix=}";;
--enable-developer) DEVELOPER=1;;
--disable-developer) DEVELOPER=0;;
--enable-compat) COMPAT=1;;
--disable-compat) COMPAT=0;;
--enable-valgrind) VALGRIND=1;;
--disable-valgrind) VALGRIND=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"
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
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 VALGRIND "$VALGRIND"
add_var DEVELOPER "$DEVELOPER" $CONFIG_HEADER
add_var COMPAT "$COMPAT" $CONFIG_HEADER
add_var PYTEST "$PYTEST"
# 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