Use a separate dequeue thread to dispatch notifications
[collectd.git] / build.sh
1 #!/bin/sh
2
3 GLOBAL_ERROR_INDICATOR=0
4
5 check_for_application()
6 {
7     for PROG in "$@"
8     do
9         which "$PROG" >/dev/null 2>&1
10         if test $? -ne 0; then
11             cat >&2 <<EOF
12 WARNING: \`$PROG' not found!
13     Please make sure that \`$PROG' is installed and is in one of the
14     directories listed in the PATH environment variable.
15 EOF
16             GLOBAL_ERROR_INDICATOR=1
17         fi
18     done
19 }
20
21 setup_libtool()
22 {
23     libtoolize=""
24     libtoolize --version >/dev/null 2>/dev/null
25     if test $? -eq 0; then
26         libtoolize=libtoolize
27     else
28         glibtoolize --version >/dev/null 2>/dev/null
29         if test $? -eq 0; then
30             libtoolize=glibtoolize
31         else
32             cat >&2 <<EOF
33 WARNING: Neither \`libtoolize' nor \`glibtoolize' have been found!
34     Please make sure that one of them is installed and is in one of the
35     directories listed in the PATH environment variable.
36 EOF
37             GLOBAL_ERROR_INDICATOR=1
38         fi
39     fi
40
41     if test "$GLOBAL_ERROR_INDICATOR" != "0"; then
42         exit 1
43     fi
44 }
45
46 build()
47 {
48     echo "Building..."
49     check_for_application lex bison autoheader aclocal automake autoconf pkg-config
50     setup_libtool
51
52     set -x
53     autoheader \
54     && aclocal -I m4 \
55     && $libtoolize --copy --force \
56     && automake --add-missing --copy \
57     && autoconf
58 }
59
60 build_cygwin()
61 {
62     echo "Building for Cygwin..."
63     check_for_application aclocal autoconf autoheader automake bison flex git make pkg-config x86_64-w64-mingw32-gcc
64     setup_libtool
65
66     set -e
67
68     : ${INSTALL_DIR:="C:/PROGRA~1/collectd"}
69     : ${LIBDIR:="${INSTALL_DIR}"}
70     : ${BINDIR:="${INSTALL_DIR}"}
71     : ${SBINDIR:="${INSTALL_DIR}"}
72     : ${SYSCONFDIR:="${INSTALL_DIR}"}
73     : ${LOCALSTATEDIR:="${INSTALL_DIR}"}
74     : ${DATAROOTDIR:="${INSTALL_DIR}"}
75     : ${DATADIR:="${INSTALL_DIR}"}
76
77     echo "Installing collectd to ${INSTALL_DIR}."
78     TOP_SRCDIR="$(pwd)"
79     MINGW_ROOT="$(x86_64-w64-mingw32-gcc -print-sysroot)/mingw"
80     export GNULIB_DIR="${TOP_SRCDIR}/gnulib/build/gllib"
81
82     export CC="x86_64-w64-mingw32-gcc"
83
84     if [ -d "${TOP_SRCDIR}/gnulib/build" ]; then
85         echo "Assuming that gnulib is already built, because gnulib/build exists."
86     else
87         git submodule init
88         git submodule update
89         cd gnulib
90         ./gnulib-tool \
91           --create-testdir \
92           --source-base=lib \
93           --dir=${TOP_SRCDIR}/gnulib/build \
94           canonicalize-lgpl \
95           fcntl-h \
96           fnmatch \
97           getsockopt \
98           gettimeofday \
99           nanosleep \
100           netdb \
101           net_if \
102           poll \
103           recv \
104           regex \
105           sendto \
106           setlocale \
107           strtok_r \
108           sys_resource \
109           sys_socket \
110           sys_stat \
111           sys_wait \
112           time_r
113
114         cd ${TOP_SRCDIR}/gnulib/build
115         ./configure --host="mingw32" LIBS="-lws2_32 -lpthread"
116         make 
117         cd gllib
118
119         # We have to rebuild libgnu.a to get the list of *.o files to build a dll later
120         rm libgnu.a
121         OBJECT_LIST=`make V=1 | grep "ar" | cut -d' ' -f4-`
122         $CC -shared -o libgnu.dll $OBJECT_LIST -lws2_32 -lpthread
123         rm libgnu.a # get rid of it, to use libgnu.dll
124         fi
125     cd "${TOP_SRCDIR}"
126
127     set -x
128     autoreconf --install
129
130     export LDFLAGS="-L${GNULIB_DIR}"
131     export LIBS="-lgnu"
132     export CFLAGS="-Drestrict=__restrict -I${GNULIB_DIR}"
133
134     ./configure \
135       --prefix="${INSTALL_DIR}" \
136       --libdir="${LIBDIR}" \
137       --bindir="${BINDIR}" \
138       --sbindir="${SBINDIR}" \
139       --sysconfdir="${SYSCONFDIR}" \
140       --localstatedir="${LOCALSTATEDIR}" \
141       --datarootdir="${DATAROOTDIR}" \
142       --datarootdir="${DATADIR}" \
143       --disable-all-plugins \
144       --host="mingw32" \
145       --enable-logfile \
146       --enable-match_regex \
147       --enable-target_replace \
148       --enable-target_set
149
150     cp ${GNULIB_DIR}/../config.h src/gnulib_config.h
151     echo "#include <config.h.in>" >> src/gnulib_config.h
152
153     cp libtool libtool_bak
154     sed -i "s%\$LTCC \$LTCFLAGS\(.*cwrapper.*\)%\$LTCC \1%" libtool
155
156     make
157     make install
158
159     cp "${GNULIB_DIR}/libgnu.dll" "${INSTALL_DIR}"
160     cp "${MINGW_ROOT}/bin/zlib1.dll" "${INSTALL_DIR}"
161     cp "${MINGW_ROOT}/bin/libwinpthread-1.dll" "${INSTALL_DIR}"
162     cp "${MINGW_ROOT}/bin/libdl.dll" "${INSTALL_DIR}"
163
164     echo "Done."
165 }
166
167 os_name="$(uname)"
168 if test "${os_name#CYGWIN}" != "$os_name"; then
169     build_cygwin
170 else
171     build
172 fi
173