Optionally run autoconf
authorPhilip Jameson <pjameson@fb.com>
Thu, 17 Aug 2017 00:46:52 +0000 (17:46 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 17 Aug 2017 00:50:20 +0000 (17:50 -0700)
Summary:
This makes it so that the //folly:config rule can run autoconf to create folly-config

- Uses cxx_genrule get compiler settings and paths to dependent libraries
- Goes around a couple of oddities in the way that buck exports some of its macros
- While it uses buck_cxx_library, that's okay to use outside of facebook's internal repos.

Reviewed By: meyering

Differential Revision: D5620729

fbshipit-source-id: 0d2d8e3bda92182dcdcd3e80cb12a3756b3816ac

folly/build/buck_run_autoconf.sh [new file with mode: 0644]

diff --git a/folly/build/buck_run_autoconf.sh b/folly/build/buck_run_autoconf.sh
new file mode 100644 (file)
index 0000000..c6a5776
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+get_ldflags() {
+  # Convert paths to .so/.dylib/.dll into directories that can be used with
+  # -L/path and -Wl,-rpath,/path compiler args. Also strip out -l flags,
+  # as autoconf will add them for us for feature detection.
+  for i in "$@"; do
+    if [ "$i" = "-Wl,-rpath" ]; then continue; fi
+    echo "$i" | perl -p -e "s/'/\\\\'/g;" \
+      -e 's/-l[\w-]*//g;' \
+      -e 's;(.*)[/\\].*\.(so|dylib|dll)$;-L\1 -Wl,-rpath,\1;g;'
+  done
+}
+
+get_boost_libdirs() {
+  # autoconf's boost detection seems to require a path to boost libs
+  # if they're not in the system directories
+  for i in "$@"; do
+    echo "$i" | perl -n -e 'print if s,(.*)/libboost_.*\.(so|dylib|dll).*,\1,'
+  done
+}
+
+# This is an extra linker flag that buck appends on OSX that's not valid
+# This probably requires a patch to buck
+LDFLAGS=$(get_ldflags "$@" | uniq | tr '\n' ' ' | perl -pe 's;-Xlinker \@executable_path\S*;;g')
+
+boost_libdir=$(get_boost_libdirs "$@"| head -n 1)
+if [ ! -z "$boost_libdir" ]; then
+  BOOST_FLAG="--with-boost-libdir=$boost_libdir"
+fi
+
+export LDFLAGS
+export BOOST_LDFLAGS="$LDFLAGS"
+export BOOST_CPPFLAGS="$CPPFLAGS"
+
+SRCROOT=$(dirname "$(readlink "$SRCDIR"/configure.ac)")
+# Temp dir because autoconf doesn't like '#' in the working directory
+conf_dir=$(mktemp -d)
+trap 'rm -rf "$conf_dir"' EXIT
+cd "$conf_dir" && \
+autoreconf -iv "$SRCROOT" && \
+"$SRCROOT/configure" "$BOOST_FLAG" && \
+cp -pvf folly-config.h "$OUT"