aboutsummaryrefslogtreecommitdiffstats
path: root/configure
blob: 6ad1804263a9883863a47f58d99ec198ec180d34 (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/sh

PACKAGE=pingu
PACKAGE_VERSION=1.4

TMPDIR=${TMPDIR:-${TEMPDIR:-/tmp}}
TMPC="$TMPDIR/$PACKAGE-conf-$$.c"
TMPO="$TMPDIR/$PACKAGE-conf-$$.o"
TMPE="$TMPDIR/$PACKAGE-conf-$$"

trap "rm -f $TMPC $TMPO $TMPE" EXIT INT QUIT TERM
rm -f config.log

echo "# $PACKAGE configure log $(date)" >> config.log
printf "# Configured with:" >> config.log
printf " '%s'" "$0" "$@" >> config.log
echo >> config.log
echo "#" >> config.log

die() { echo "$*" >&2; exit 1; }

do_cc() {
	echo $cc "$@" >> config.log
	$cc "$@" >> config.log 2>&1 || return $?
}

compile_prog() {
	do_cc $CFLAGS $1 -o $TMPE $TMPC $LDFLAGS
}

usage () {
cat <<EOF
Usage: $0 [OPTION]... [VAR=VALUE]... [TARGET]

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Installation directories:
  --prefix=PREFIX         main installation prefix [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --rundir=DIR            pidfile and unix sockets [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --mandir=DIR            man documentation [DATAROOTDIR/man]

Optional features:
  --enable-debug          build with debugging information [disabled]
  --enable-warnings       build with recommended warnings flags [enabled]
  --enable-werror         build with -Werror [disabled]
  --enable-lua            build Lua client binding [disabled]
  --disable-doc           do not build manual pages [enabled]
  --with-luapc=LUAPC      build Lua client binding, using LUAPC pkg-config
                          package [disabled]

Some influential environment variables:
  CC                      C compiler command [detected]
  CFLAGS                  C compiler flags [-Os -pipe ...]
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>

Use these variables to override the choices made by configure.

EOF
exit 0
}

prefix=/usr/local
exec_prefix='$(prefix)'
bindir='$(exec_prefix)/bin'
sbindir='$(exec_prefix)/sbin'
sysconfdir='$(prefix)/etc'
localstatedir='$(prefix)/var'
libdir='$(exec_prefix)/lib'
datarootdir='$(prefix)/share'
mandir='$(datarootdir)/man'

enable_debug=false
enable_warnings=true
enable_werror=false
enable_lua=false
enable_doc=true

for arg; do
case "$arg" in
--help) usage ;;
--prefix=*) prefix=${arg#*=} ;;
--exec-prefix=*) exec_prefix=${arg#*=} ;;
--bindir=*) bindir=${arg#*=} ;;
--sbindir=*) sbindir=${arg#*=} ;;
--sysconfdir=*) sysconfdir=${arg#*=} ;;
--localstatedir=*) localstatedir=${arg#*=} ;;
--libdir=*) libdir=${arg#*=} ;;
--datarootdir=*) datarootdir=${arg#*=} ;;
--mandir=*) mandir=${arg#*=} ;;
--enable-debug) enable_debug=true ;;
--disable-debug) enable_debug=false ;;
--enable-warnings) enable_warnings=true ;;
--disable-warnings) enable_warnings=false ;;
--enable-werror) enable_werror=true ;;
--disable-werror) enable_werror=false ;;
--enable-doc) enable_doc=true ;;
--disable-doc) enable_doc=false ;;
--with-luapc=*) with_luapc=${arg#*=};;
-* ) die "$0: unknown option $arg" ;;
CC=*) CC=${arg#*=} ;;
CFLAGS=*) CFLAGS=${arg#*=} ;;
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
*=*) ;;
*) target=$arg ;;
esac
done

if $enable_debug; then
	CFLAGS="$CFLAGS -g"
fi

echo -n "Checking for -Wall: "
if $enable_warnings; then
	CFLAGS="$CFLAGS -Wall"
	echo "yes"
else
	echo "no"
fi

echo -n "Checking for -Werror: "
if $enable_werror; then
	CFLAGS="$CFLAGS -Werror"
	echo "yes"
else
	echo "no"
fi

echo -n "Checking for Lua support: "
if [ -n "$with_luapc" ]; then
	LUAPC="$with_luapc"
	echo $with_luapc
else
	echo disabled
fi

cc=${CC:-gcc}

cat > $TMPC << EOF
#include <string.h>
int main(void) {
	char src[4] = "asdf";
	char dst[4];
	return strlcpy(dst, src, sizeof(dst));
}
EOF

echo -n "Checking for strlcpy: "
if compile_prog "" ""; then
	HAVE_STRLCPY=1
	echo yes
else
	echo no
fi

echo -n "Checking if documentation should be built: "
if $enable_doc; then
	echo "yes"
	ENABLE_DOC=1
else
	echo "no"
fi

# generate config.h
config_h_vars="
PACKAGE
PACKAGE_VERSION
HAVE_STRLCPY
"

cat >config.h <<EOF
/* this file is generated by $0 */
#ifndef CONFIG_H
#define CONFIG_H

EOF
for var in $config_h_vars; do
	eval "value=\$$var"
	case "$value" in
	[0-9]) echo "#define $var $value" >> config.h;;
	"") echo "/* $var is unset */" >> config.h;;
	*) echo "#define $var \"$value\"" >> config.h;;
	esac
done
echo "" >> config.h
echo '#endif /* CONFIG_H */' >> config.h

CFLAGS="$CFLAGS -DHAVE_CONFIG_H"

# generate config.mk
config_mk_vars="
prefix
exec_prefix
bindir
sbindir
sysconfdir
localstatedir
libdir
datarootdir
mandir
LUAPC
CC
CFLAGS
ENABLE_DOC
LDFLAGS
PACKAGE
PACKAGE_VERSION
"

echo "# this file is generated by $0" >config.mk
for var in $config_mk_vars; do
	eval "value=\$$var"
	if [ -n "$value" ]; then
		echo "$var = $value" >> config.mk
	fi
done

echo "$PACKAGE is configured. Please run 'make' to build"