Last-minute updates for release notes.
[pgsql.git] / config / llvm.m4
blob21d8cd4f90f97a120820f9008daf8cd1eaa0a598
1 # config/llvm.m4
3 # PGAC_LLVM_SUPPORT
4 # -----------------
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
9 # into bitcode.
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=])
21   fi
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])
26   fi
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])
30   fi
31   AC_MSG_NOTICE([using llvm $pgac_llvm_version])
33   # need clang to create some bitcode files
34   AC_ARG_VAR(CLANG, [path to clang compiler to generate bitcode])
35   PGAC_PATH_PROGS(CLANG, clang clang-7 clang-6.0 clang-5.0 clang-4.0 clang-3.9)
36   if test -z "$CLANG"; then
37     AC_MSG_ERROR([clang not found, but required when compiling --with-llvm, specify with CLANG=])
38   fi
39   # make sure clang is executable
40   if test "x$($CLANG --version 2> /dev/null || echo no)" = "xno"; then
41     AC_MSG_ERROR([$CLANG does not work])
42   fi
43   # Could check clang version, but it doesn't seem that
44   # important. Systems with a new enough LLVM version are usually
45   # going to have a decent clang version too. It's also not entirely
46   # clear what the minimum version is.
48   # Collect compiler flags necessary to build the LLVM dependent
49   # shared library.
50   for pgac_option in `$LLVM_CONFIG --cppflags`; do
51     case $pgac_option in
52       -I*|-D*) LLVM_CPPFLAGS="$pgac_option $LLVM_CPPFLAGS";;
53     esac
54   done
56   for pgac_option in `$LLVM_CONFIG --ldflags`; do
57     case $pgac_option in
58       -L*) LDFLAGS="$LDFLAGS $pgac_option";;
59     esac
60   done
62   # ABI influencing options, standard influencing options
63   for pgac_option in `$LLVM_CONFIG --cxxflags`; do
64     case $pgac_option in
65       -fno-rtti*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
66       -std=*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
67     esac
68   done
70   # Look for components we're interested in, collect necessary
71   # libs. As some components are optional, we can't just list all of
72   # them as it'd raise an error.
73   pgac_components='';
74   for pgac_component in `$LLVM_CONFIG --components`; do
75     case $pgac_component in
76       engine) pgac_components="$pgac_components $pgac_component";;
77       debuginfodwarf) pgac_components="$pgac_components $pgac_component";;
78       orcjit) pgac_components="$pgac_components $pgac_component";;
79       passes) pgac_components="$pgac_components $pgac_component";;
80       native) pgac_components="$pgac_components $pgac_component";;
81       perfjitevents) pgac_components="$pgac_components $pgac_component";;
82     esac
83   done;
85   # And then get the libraries that need to be linked in for the
86   # selected components.  They're large libraries, we only want to
87   # link them into the LLVM using shared library.
88   for pgac_option in `$LLVM_CONFIG --libs --system-libs $pgac_components`; do
89     case $pgac_option in
90       -l*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
91     esac
92   done
94   LLVM_BINPATH=`$LLVM_CONFIG --bindir`
96 dnl LLVM_CONFIG, CLANG are already output via AC_ARG_VAR
97   AC_SUBST(LLVM_LIBS)
98   AC_SUBST(LLVM_CPPFLAGS)
99   AC_SUBST(LLVM_CFLAGS)
100   AC_SUBST(LLVM_CXXFLAGS)
101   AC_SUBST(LLVM_BINPATH)
103 ])# PGAC_LLVM_SUPPORT
106 # PGAC_CHECK_LLVM_FUNCTIONS
107 # -------------------------
109 # Check presence of some optional LLVM functions.
110 # (This shouldn't happen until we're ready to run AC_CHECK_DECLS tests;
111 # because PGAC_LLVM_SUPPORT runs very early, it's not an appropriate place.)
113 AC_DEFUN([PGAC_CHECK_LLVM_FUNCTIONS],
115   # Check which functionality is present
116   SAVE_CPPFLAGS="$CPPFLAGS"
117   CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
118   AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn], [], [], [[#include <llvm-c/OrcBindings.h>]])
119   AC_CHECK_DECLS([LLVMGetHostCPUName, LLVMGetHostCPUFeatures], [], [], [[#include <llvm-c/TargetMachine.h>]])
120   AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include <llvm-c/ExecutionEngine.h>]])
121   CPPFLAGS="$SAVE_CPPFLAGS"
122 ])# PGAC_CHECK_LLVM_FUNCTIONS