forked from verificarlo/verificarlo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathax_llvm.m4
130 lines (115 loc) · 4.34 KB
/
ax_llvm.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- mode: m4 -*-
#
# Copyright (c) 2014-2020 Verificarlo Contributors
# Copyright (c) 2012, 2013 The University of Utah
# Copyright (c) 2008 Andy Kitchen <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
###############################################################################
# SYNOPSIS
#
# AX_LLVM([min_version],[max_version],[llvm-libs])
#
# DESCRIPTION
#
# Test for the existence of LLVM, test that LLVM is at least the specified
# version, and test that a simple test program can be linked with the
# libraries described in the llvm-libs argument, i.e.:
#
# llvm --libs <llvm-libs>
#
# If the <version> argument is the empty string, then the version check is
# bypassed.
#
# This file was derived from the LLVM Autoconf macro found in the Autoconf
# Macro Archive: <http://www.gnu.org/software/autoconf-archive/ax_llvm.html>.
# The definition of AX_LLVM in this file is almost completely rewritten from
# the version (serial #12) found in the Archive.
#
# The current file has been updated for modern LLVM (3.3).
AC_DEFUN([AX_LLVM],
[
AC_ARG_WITH([llvm],
AS_HELP_STRING([--with-llvm@<:@=DIR@:>@],
[use LLVM located in DIR]),
[with_llvm="$withval"],
[with_llvm=yes])
if test "x$with_llvm" = "xno"; then
AC_MSG_ERROR(
[--with-llvm=no was given but this package requires LLVM])
elif test "x$with_llvm" = "xyes"; then
with_llvm_path="$PATH"
else
with_llvm_path="$with_llvm/bin$PATH_SEPARATOR$with_llvm"
fi
AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [], [$with_llvm_path])
if test -z "$LLVM_CONFIG"; then
AC_MSG_ERROR(
[LLVM is required but program `llvm-config` cannot be found in $with_llvm_path])
fi
LLVM_VERSION=`$LLVM_CONFIG --version`
AC_DEFINE_UNQUOTED([LLVM_VERSION], ["$LLVM_VERSION"], [The llvm version])
LLVM_VERSION_MAJOR=`echo $LLVM_VERSION | cut -d'.' -f1`
AC_DEFINE_UNQUOTED([LLVM_VERSION_MAJOR], [$LLVM_VERSION_MAJOR], [The llvm major version])
LLVM_VERSION_MINOR=`echo $LLVM_VERSION | cut -d'.' -f2 | cut -c 1`
AC_DEFINE_UNQUOTED([LLVM_VERSION_MINOR], [$LLVM_VERSION_MINOR], [The llvm minor version])
AC_MSG_CHECKING([for LLVM version])
AC_MSG_RESULT([$LLVM_VERSION])
AX_COMPARE_VERSION([$LLVM_VERSION],[ge],[$1],
[],
[
AC_MSG_ERROR(
[At least LLVM version $1 is required])
])
AX_COMPARE_VERSION([$LLVM_VERSION],[le],[$2],
[],
[
AC_MSG_ERROR(
[LLVM version up to $2 is supported])
])
LLVM_BINDIR=`$LLVM_CONFIG --bindir`
AC_DEFINE_UNQUOTED([LLVM_BINDIR], ["$LLVM_BINDIR"], [The llvm bin dir])
LLVM_CPPFLAGS=`$LLVM_CONFIG --cxxflags | sed s/-Wcovered-switch-default// | sed s/-Werror=date-time// | sed s/-Wl,--no-keep-files-mapped// | sed s/-Wstring-conversion//`
AC_DEFINE_UNQUOTED([LLVM_CPPFLAGS], ["$LLVM_CPPFLAGS"], [The llvm CPPFLAGS])
LLVM_LDFLAGS="`$LLVM_CONFIG --ldflags` `$LLVM_CONFIG --system-libs`"
LLVM_LIBS=`$LLVM_CONFIG --libs $3`
LLVM_LIBDIR=`$LLVM_CONFIG --libdir`
# The output of `llvm-config --system-libs/--ldflags' often contains library directives
# that must come *after* all the LLVM libraries on the link line: e.g.,
# "-lpthread -lffi -ldl -lm". To ensure this, we insert LLVM_LDFLAGS into
# LIBS, *not* into LDFLAGS.
AC_REQUIRE([AC_PROG_CXX])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS"
# LDFLAGS="$LDFLAGS $LLVM_LDFLAGS" --- see comment above.
LIBS_SAVED="$LIBS"
LIBS="-L$LLVM_LIBDIR $LIBS $LLVM_LIBS $LLVM_LDFLAGS"
# LIBS="$LIBS $LLVM_LIBS" --- see comment above.
AC_CACHE_CHECK(can compile with and link with LLVM([$3]),
ax_cv_llvm,
[
AC_LANG_PUSH([C++])
AC_LINK_IFELSE([
AC_LANG_PROGRAM(
[[@%:@include <llvm/IR/LLVMContext.h>
@%:@include <llvm/IR/Module.h>]],
[[llvm::LLVMContext context;
llvm::Module *M = new llvm::Module("test", context);]])],
ax_cv_llvm=yes,
ax_cv_llvm=no)
AC_LANG_POP([C++])
])
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
LIBS="$LIBS_SAVED"
if test "$ax_cv_llvm" != "yes"; then
AC_MSG_FAILURE(
[cannot compile and link test program with selected LLVM])
fi
AC_SUBST(LLVM_BINDIR)
])