Optionally run autoconf
[folly.git] / folly / build / buck_run_autoconf.sh
1 #!/bin/sh
2
3 get_ldflags() {
4   # Convert paths to .so/.dylib/.dll into directories that can be used with
5   # -L/path and -Wl,-rpath,/path compiler args. Also strip out -l flags,
6   # as autoconf will add them for us for feature detection.
7   for i in "$@"; do
8     if [ "$i" = "-Wl,-rpath" ]; then continue; fi
9     echo "$i" | perl -p -e "s/'/\\\\'/g;" \
10       -e 's/-l[\w-]*//g;' \
11       -e 's;(.*)[/\\].*\.(so|dylib|dll)$;-L\1 -Wl,-rpath,\1;g;'
12   done
13 }
14
15 get_boost_libdirs() {
16   # autoconf's boost detection seems to require a path to boost libs
17   # if they're not in the system directories
18   for i in "$@"; do
19     echo "$i" | perl -n -e 'print if s,(.*)/libboost_.*\.(so|dylib|dll).*,\1,'
20   done
21 }
22
23 # This is an extra linker flag that buck appends on OSX that's not valid
24 # This probably requires a patch to buck
25 LDFLAGS=$(get_ldflags "$@" | uniq | tr '\n' ' ' | perl -pe 's;-Xlinker \@executable_path\S*;;g')
26
27 boost_libdir=$(get_boost_libdirs "$@"| head -n 1)
28 if [ ! -z "$boost_libdir" ]; then
29   BOOST_FLAG="--with-boost-libdir=$boost_libdir"
30 fi
31
32 export LDFLAGS
33 export BOOST_LDFLAGS="$LDFLAGS"
34 export BOOST_CPPFLAGS="$CPPFLAGS"
35
36 SRCROOT=$(dirname "$(readlink "$SRCDIR"/configure.ac)")
37 # Temp dir because autoconf doesn't like '#' in the working directory
38 conf_dir=$(mktemp -d)
39 trap 'rm -rf "$conf_dir"' EXIT
40 cd "$conf_dir" && \
41 autoreconf -iv "$SRCROOT" && \
42 "$SRCROOT/configure" "$BOOST_FLAG" && \
43 cp -pvf folly-config.h "$OUT"