1 dnl This Source Code Form is subject to the terms of the Mozilla Public
2 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
3 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 AC_DEFUN([MOZ_CONFIG_CLANG_PLUGIN], [
7 if test -n "$ENABLE_CLANG_PLUGIN"; then
8 dnl For some reason the llvm-config downloaded from clang.llvm.org for clang3_8
9 dnl produces a -isysroot flag for a sysroot which might not ship when passed
10 dnl --cxxflags. We use sed to remove this argument so that builds work on OSX
12 dnl For a similar reason, we remove any -gcc-toolchain arguments, since the
13 dnl directories specified by such arguments might not exist on the current
15 LLVM_CXXFLAGS=`$LLVM_CONFIG --cxxflags | sed -e 's/-isysroot [[^ ]]*//' -e 's/-gcc-toolchain [[^ ]]*//'`
17 LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags | tr '\n' ' '`
19 if test "${HOST_OS_ARCH}" = "Darwin"; then
20 dnl We need to make sure that we use the symbols coming from the clang
21 dnl binary. In order to do this, we need to pass -flat_namespace and
22 dnl -undefined suppress to the linker. This makes sure that we link the
23 dnl symbols into the flat namespace provided by clang, and thus get
24 dnl access to all of the symbols which are undefined in our dylib as we
25 dnl are building it right now, and also that we don't fail the build
26 dnl due to undefined symbols (which will be provided by clang).
27 CLANG_LDFLAGS="-Wl,-flat_namespace -Wl,-undefined,suppress"
28 dnl We are loaded into clang, so we don't need to link to very many things,
29 dnl we just need to link to clangASTMatchers because it is not used by clang
30 CLANG_LDFLAGS="$CLANG_LDFLAGS `$LLVM_CONFIG --prefix`/lib/libclangASTMatchers.a"
31 dnl We need to remove -L/path/to/clang/lib from LDFLAGS to ensure that we
32 dnl don't accidentally link against the libc++ there which is a newer
33 dnl version that what our build machines have installed.
34 LLVM_LDFLAGS=`echo "$LLVM_LDFLAGS" | sed -E 's/-L[[^ ]]+\/clang\/lib//'`
35 elif test "${HOST_OS_ARCH}" = "WINNT"; then
36 CLANG_LDFLAGS="clangASTMatchers.lib clang.lib"
38 CLANG_LDFLAGS="-lclangASTMatchers"
41 if test -n "$CLANG_CL"; then
42 dnl The llvm-config coming with clang-cl may give us arguments in the
43 dnl /ARG form, which in msys will be interpreted as a path name. So we
44 dnl need to split the args and convert the leading slashes that we find
46 LLVM_REPLACE_CXXFLAGS=''
47 for arg in $LLVM_CXXFLAGS; do
48 dnl The following expression replaces a leading slash with a dash.
49 dnl Also replace any backslashes with forward slash.
50 arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
51 LLVM_REPLACE_CXXFLAGS="$LLVM_REPLACE_CXXFLAGS $arg"
53 LLVM_CXXFLAGS="$LLVM_REPLACE_CXXFLAGS"
54 dnl We'll also want to replace `-std:` with `-Xclang -std=` so that
55 dnl LLVM_CXXFLAGS can correctly override the `-Xclang -std=` set by
56 dnl toolchain.configure.
57 LLVM_CXXFLAGS=`echo "$LLVM_CXXFLAGS"|sed -e 's/ \(-Xclang \|\)-std[[:=]]/ -Xclang -std=/'`
59 LLVM_REPLACE_LDFLAGS=''
60 for arg in $LLVM_LDFLAGS; do
61 dnl The following expression replaces a leading slash with a dash.
62 dnl Also replace any backslashes with forward slash.
63 arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
64 LLVM_REPLACE_LDFLAGS="$LLVM_REPLACE_LDFLAGS $arg"
66 LLVM_LDFLAGS="$LLVM_REPLACE_LDFLAGS"
68 CLANG_REPLACE_LDFLAGS=''
69 for arg in $CLANG_LDFLAGS; do
70 dnl The following expression replaces a leading slash with a dash.
71 dnl Also replace any backslashes with forward slash.
72 arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
73 CLANG_REPLACE_LDFLAGS="$CLANG_REPLACE_LDFLAGS $arg"
75 CLANG_LDFLAGS="$CLANG_REPLACE_LDFLAGS"
78 CLANG_PLUGIN_FLAGS="-Xclang -load -Xclang $CLANG_PLUGIN -Xclang -add-plugin -Xclang moz-check"
80 AC_DEFINE(MOZ_CLANG_PLUGIN)
83 if test -n "$ENABLE_MOZSEARCH_PLUGIN"; then
84 if test -z "${ENABLE_CLANG_PLUGIN}"; then
85 AC_MSG_ERROR([Can't use mozsearch plugin without --enable-clang-plugin.])
88 CLANG_PLUGIN_FLAGS="$CLANG_PLUGIN_FLAGS -Xclang -add-plugin -Xclang mozsearch-index"
90 dnl Parameters are: srcdir, outdir (path where output JSON is stored), objdir.
91 CLANG_PLUGIN_FLAGS="$CLANG_PLUGIN_FLAGS -Xclang -plugin-arg-mozsearch-index -Xclang $_topsrcdir"
92 CLANG_PLUGIN_FLAGS="$CLANG_PLUGIN_FLAGS -Xclang -plugin-arg-mozsearch-index -Xclang $_objdir/mozsearch_index"
93 CLANG_PLUGIN_FLAGS="$CLANG_PLUGIN_FLAGS -Xclang -plugin-arg-mozsearch-index -Xclang $_objdir"
95 AC_DEFINE(MOZ_MOZSEARCH_PLUGIN)
98 AC_SUBST_LIST(CLANG_PLUGIN_FLAGS)
99 AC_SUBST_LIST(LLVM_CXXFLAGS)
100 AC_SUBST_LIST(LLVM_LDFLAGS)
101 AC_SUBST_LIST(CLANG_LDFLAGS)
103 AC_SUBST(ENABLE_CLANG_PLUGIN)
104 AC_SUBST(ENABLE_CLANG_PLUGIN_ALPHA)
105 AC_SUBST(ENABLE_MOZSEARCH_PLUGIN)