6 # Look for the LLVM installation, check that it's new enough, set the
7 # corresponding LLVM_{CFLAGS,CXXFLAGS,BINPATH} and LDFLAGS
8 # variables. Also verify that CLANG is available, to transform C
11 AC_DEFUN([PGAC_LLVM_SUPPORT],
13 AC_REQUIRE([AC_PROG_AWK])
15 AC_ARG_VAR(LLVM_CONFIG, [path to llvm-config command])
16 PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9)
18 # no point continuing if llvm wasn't found
19 if test -z "$LLVM_CONFIG"; then
20 AC_MSG_ERROR([llvm-config not found, but required when compiling --with-llvm, specify with LLVM_CONFIG=])
22 # check if detected $LLVM_CONFIG is executable
23 pgac_llvm_version="$($LLVM_CONFIG --version 2> /dev/null || echo no)"
24 if test "x$pgac_llvm_version" = "xno"; then
25 AC_MSG_ERROR([$LLVM_CONFIG does not work])
27 # and whether the version is supported
28 if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 4 || ([$]1 == 3 && [$]2 >= 9)) exit 1; else exit 0;}';then
29 AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required])
32 # need clang to create some bitcode files
33 AC_ARG_VAR(CLANG, [path to clang compiler to generate bitcode])
34 PGAC_PATH_PROGS(CLANG, clang clang-7 clang-6.0 clang-5.0 clang-4.0 clang-3.9)
35 if test -z "$CLANG"; then
36 AC_MSG_ERROR([clang not found, but required when compiling --with-llvm, specify with CLANG=])
38 # make sure clang is executable
39 if test "x$($CLANG --version 2> /dev/null || echo no)" = "xno"; then
40 AC_MSG_ERROR([$CLANG does not work])
42 # Could check clang version, but it doesn't seem that
43 # important. Systems with a new enough LLVM version are usually
44 # going to have a decent clang version too. It's also not entirely
45 # clear what the minimum version is.
47 # Collect compiler flags necessary to build the LLVM dependent
49 for pgac_option in `$LLVM_CONFIG --cppflags`; do
51 -I*|-D*) LLVM_CPPFLAGS="$pgac_option $LLVM_CPPFLAGS";;
55 for pgac_option in `$LLVM_CONFIG --ldflags`; do
57 -L*) LDFLAGS="$LDFLAGS $pgac_option";;
61 # ABI influencing options, standard influencing options
62 for pgac_option in `$LLVM_CONFIG --cxxflags`; do
64 -fno-rtti*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
65 -std=*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
69 # Look for components we're interested in, collect necessary
70 # libs. As some components are optional, we can't just list all of
71 # them as it'd raise an error.
73 for pgac_component in `$LLVM_CONFIG --components`; do
74 case $pgac_component in
75 engine) pgac_components="$pgac_components $pgac_component";;
76 debuginfodwarf) pgac_components="$pgac_components $pgac_component";;
77 orcjit) pgac_components="$pgac_components $pgac_component";;
78 passes) pgac_components="$pgac_components $pgac_component";;
79 native) pgac_components="$pgac_components $pgac_component";;
80 perfjitevents) pgac_components="$pgac_components $pgac_component";;
84 # And then get the libraries that need to be linked in for the
85 # selected components. They're large libraries, we only want to
86 # link them into the LLVM using shared library.
87 for pgac_option in `$LLVM_CONFIG --libs --system-libs $pgac_components`; do
89 -l*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
93 LLVM_BINPATH=`$LLVM_CONFIG --bindir`
95 dnl LLVM_CONFIG, CLANG are already output via AC_ARG_VAR
97 AC_SUBST(LLVM_CPPFLAGS)
99 AC_SUBST(LLVM_CXXFLAGS)
100 AC_SUBST(LLVM_BINPATH)
102 ])# PGAC_LLVM_SUPPORT
105 # PGAC_CHECK_LLVM_FUNCTIONS
106 # -------------------------
108 # Check presence of some optional LLVM functions.
109 # (This shouldn't happen until we're ready to run AC_CHECK_DECLS tests;
110 # because PGAC_LLVM_SUPPORT runs very early, it's not an appropriate place.)
112 AC_DEFUN([PGAC_CHECK_LLVM_FUNCTIONS],
114 # Check which functionality is present
115 SAVE_CPPFLAGS="$CPPFLAGS"
116 CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
117 AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn], [], [], [[#include <llvm-c/OrcBindings.h>]])
118 AC_CHECK_DECLS([LLVMGetHostCPUName, LLVMGetHostCPUFeatures], [], [], [[#include <llvm-c/TargetMachine.h>]])
119 AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include <llvm-c/ExecutionEngine.h>]])
120 CPPFLAGS="$SAVE_CPPFLAGS"
121 ])# PGAC_CHECK_LLVM_FUNCTIONS