forked from collectd/collectd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·173 lines (149 loc) · 4.35 KB
/
build.sh
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
#!/bin/sh
GLOBAL_ERROR_INDICATOR=0
check_for_application()
{
for PROG in "$@"
do
which "$PROG" >/dev/null 2>&1
if test $? -ne 0; then
cat >&2 <<EOF
WARNING: \`$PROG' not found!
Please make sure that \`$PROG' is installed and is in one of the
directories listed in the PATH environment variable.
EOF
GLOBAL_ERROR_INDICATOR=1
fi
done
}
setup_libtool()
{
libtoolize=""
libtoolize --version >/dev/null 2>/dev/null
if test $? -eq 0; then
libtoolize=libtoolize
else
glibtoolize --version >/dev/null 2>/dev/null
if test $? -eq 0; then
libtoolize=glibtoolize
else
cat >&2 <<EOF
WARNING: Neither \`libtoolize' nor \`glibtoolize' have been found!
Please make sure that one of them is installed and is in one of the
directories listed in the PATH environment variable.
EOF
GLOBAL_ERROR_INDICATOR=1
fi
fi
if test "$GLOBAL_ERROR_INDICATOR" != "0"; then
exit 1
fi
}
build()
{
echo "Building..."
check_for_application lex bison autoheader aclocal automake autoconf pkg-config
setup_libtool
set -x
autoheader \
&& aclocal -I m4 \
&& $libtoolize --copy --force \
&& automake --add-missing --copy \
&& autoconf
}
build_cygwin()
{
echo "Building for Cygwin..."
check_for_application aclocal autoconf autoheader automake bison flex git make pkg-config x86_64-w64-mingw32-gcc
setup_libtool
set -e
: ${INSTALL_DIR:="C:/PROGRA~1/collectd"}
: ${LIBDIR:="${INSTALL_DIR}"}
: ${BINDIR:="${INSTALL_DIR}"}
: ${SBINDIR:="${INSTALL_DIR}"}
: ${SYSCONFDIR:="${INSTALL_DIR}"}
: ${LOCALSTATEDIR:="${INSTALL_DIR}"}
: ${DATAROOTDIR:="${INSTALL_DIR}"}
: ${DATADIR:="${INSTALL_DIR}"}
echo "Installing collectd to ${INSTALL_DIR}."
TOP_SRCDIR="$(pwd)"
MINGW_ROOT="$(x86_64-w64-mingw32-gcc -print-sysroot)/mingw"
export GNULIB_DIR="${TOP_SRCDIR}/gnulib/build/gllib"
export CC="x86_64-w64-mingw32-gcc"
if [ -d "${TOP_SRCDIR}/gnulib/build" ]; then
echo "Assuming that gnulib is already built, because gnulib/build exists."
else
git submodule init
git submodule update
cd gnulib
./gnulib-tool \
--create-testdir \
--source-base=lib \
--dir=${TOP_SRCDIR}/gnulib/build \
canonicalize-lgpl \
fcntl-h \
fnmatch \
getsockopt \
gettimeofday \
nanosleep \
netdb \
net_if \
poll \
recv \
regex \
sendto \
setlocale \
strtok_r \
sys_resource \
sys_socket \
sys_stat \
sys_wait \
time_r
cd ${TOP_SRCDIR}/gnulib/build
./configure --host="mingw32" LIBS="-lws2_32 -lpthread"
make
cd gllib
# We have to rebuild libgnu.a to get the list of *.o files to build a dll later
rm libgnu.a
OBJECT_LIST=`make V=1 | grep "ar" | cut -d' ' -f4-`
$CC -shared -o libgnu.dll $OBJECT_LIST -lws2_32 -lpthread
rm libgnu.a # get rid of it, to use libgnu.dll
fi
cd "${TOP_SRCDIR}"
set -x
autoreconf --install
export LDFLAGS="-L${GNULIB_DIR}"
export LIBS="-lgnu"
export CFLAGS="-Drestrict=__restrict -I${GNULIB_DIR}"
./configure \
--prefix="${INSTALL_DIR}" \
--libdir="${LIBDIR}" \
--bindir="${BINDIR}" \
--sbindir="${SBINDIR}" \
--sysconfdir="${SYSCONFDIR}" \
--localstatedir="${LOCALSTATEDIR}" \
--datarootdir="${DATAROOTDIR}" \
--datarootdir="${DATADIR}" \
--disable-all-plugins \
--host="mingw32" \
--enable-logfile \
--enable-match_regex \
--enable-target_replace \
--enable-target_set
cp ${GNULIB_DIR}/../config.h src/gnulib_config.h
echo "#include <config.h.in>" >> src/gnulib_config.h
cp libtool libtool_bak
sed -i "s%\$LTCC \$LTCFLAGS\(.*cwrapper.*\)%\$LTCC \1%" libtool
make
make install
cp "${GNULIB_DIR}/libgnu.dll" "${INSTALL_DIR}"
cp "${MINGW_ROOT}/bin/zlib1.dll" "${INSTALL_DIR}"
cp "${MINGW_ROOT}/bin/libwinpthread-1.dll" "${INSTALL_DIR}"
cp "${MINGW_ROOT}/bin/libdl.dll" "${INSTALL_DIR}"
echo "Done."
}
os_name="$(uname)"
if test "${os_name#CYGWIN}" != "$os_name"; then
build_cygwin
else
build
fi