| 1 |
# -*- mode: m4 -*- |
| 2 |
# |
| 3 |
# Copyright (c) 2012, 2013, 2014, 2015, 2016 The University of Utah |
| 4 |
# Copyright (c) 2008 Andy Kitchen <[email protected]> |
| 5 |
# |
| 6 |
# Copying and distribution of this file, with or without modification, are |
| 7 |
# permitted in any medium without royalty provided the copyright notice |
| 8 |
# and this notice are preserved. This file is offered as-is, without any |
| 9 |
# warranty. |
| 10 |
|
| 11 |
############################################################################### |
| 12 |
|
| 13 |
# SYNOPSIS |
| 14 |
# |
| 15 |
# AX_LLVM([version],[llvm-libs]) |
| 16 |
# |
| 17 |
# DESCRIPTION |
| 18 |
# |
| 19 |
# Test for the existence of LLVM, test that LLVM is at least the specified |
| 20 |
# version, and test that a simple test program can be linked with the |
| 21 |
# libraries described in the llvm-libs argument, i.e.: |
| 22 |
# |
| 23 |
# llvm --libs <llvm-libs> |
| 24 |
# |
| 25 |
# If the <version> argument is the empty string, then the version check is |
| 26 |
# bypassed. |
| 27 |
# |
| 28 |
# This file was derived from the LLVM Autoconf macro found in the Autoconf |
| 29 |
# Macro Archive: <http://www.gnu.org/software/autoconf-archive/ax_llvm.html>. |
| 30 |
# The definition of AX_LLVM in this file is almost completely rewritten from |
| 31 |
# the version (serial #12) found in the Archive. |
| 32 |
# |
| 33 |
# The current file has been updated for modern LLVM (3.3+). |
| 34 |
|
| 35 |
AC_DEFUN([AX_LLVM], |
| 36 |
[ |
| 37 |
AC_ARG_WITH([llvm], |
| 38 |
AS_HELP_STRING([--with-llvm@<:@=DIR@:>@], |
| 39 |
[use LLVM located in DIR]), |
| 40 |
[with_llvm="$withval"], |
| 41 |
[with_llvm=yes]) |
| 42 |
|
| 43 |
if test "x$with_llvm" = "xno"; then |
| 44 |
AC_MSG_ERROR( |
| 45 |
[--with-llvm=no was given but this package requires LLVM]) |
| 46 |
elif test "x$with_llvm" = "xyes"; then |
| 47 |
with_llvm_path="$PATH" |
| 48 |
else |
| 49 |
with_llvm_path="$with_llvm/bin$PATH_SEPARATOR$with_llvm" |
| 50 |
fi |
| 51 |
|
| 52 |
AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [], [$with_llvm_path]) |
| 53 |
if test -z "$LLVM_CONFIG"; then |
| 54 |
AC_MSG_ERROR( |
| 55 |
[LLVM is required but program `llvm-config' cannot be found in $with_llvm_path]) |
| 56 |
fi |
| 57 |
|
| 58 |
if test -n "$1"; then |
| 59 |
AC_MSG_CHECKING([for LLVM version]) |
| 60 |
LLVM_VERSION=`$LLVM_CONFIG --version` |
| 61 |
AC_MSG_RESULT([$LLVM_VERSION]) |
| 62 |
AX_COMPARE_VERSION([$LLVM_VERSION],[ge],[$1], |
| 63 |
[], |
| 64 |
[ |
| 65 |
AC_MSG_ERROR( |
| 66 |
[LLVM version $1 or later is required]) |
| 67 |
]) |
| 68 |
fi |
| 69 |
|
| 70 |
# LLVM post-3.4 supports `llvm-config --system-libs'. |
| 71 |
LLVM_SYSLIBS=`$LLVM_CONFIG --system-libs 2>/dev/null` |
| 72 |
if test $? -ne 0; then |
| 73 |
LLVM_SYSLIBS="" |
| 74 |
fi |
| 75 |
|
| 76 |
# When setting `LLVM_CPPFLAGS', we weed out command-line options that might |
| 77 |
# be troublesome (e.g., -W/-f options that are not supported by `CXX', or -W |
| 78 |
# options that turn warnings into errors). We also weed out options that |
| 79 |
# might override choices that *we* want to control (e.g., debug and |
| 80 |
# optimization options). |
| 81 |
# |
| 82 |
# The subparts of the `grep' invocation below remove compiler command-line |
| 83 |
# options of the following forms: |
| 84 |
# -W... --- warning options |
| 85 |
# -w --- inhibits all warnings |
| 86 |
# -pedantic... --- pedantic warning options |
| 87 |
# -f...diagnostics... --- diagnostics reporting options (GCC, Clang) |
| 88 |
# -f...show... --- diagnostics reporting options (Clang) |
| 89 |
# -g... --- debugging options |
| 90 |
# -O... --- optimization options |
| 91 |
# [And for the llvm.org-provided build of Clang 3.8.0 for OS X, weed out:] |
| 92 |
# -isysroot |
| 93 |
# /Applications/Xcode.app/... |
| 94 |
# |
| 95 |
# The `tr/sed | grep | xargs' pipeline is intended to be portable. We use |
| 96 |
# `grep' for matching because writing fancy, portable `sed' expressions is |
| 97 |
# difficult. For example, some implementations use "\b" to match word |
| 98 |
# boundaries while others use "[[:<:]]" and "[[:>:]]". The Autoconf |
| 99 |
# documentation says that anchored matches in `sed' are not portable. Give |
| 100 |
# up; use `grep' instead. Bonus: better readability! |
| 101 |
|
| 102 |
LLVM_BINDIR=`$LLVM_CONFIG --bindir` |
| 103 |
changequote(<<, >>)dnl |
| 104 |
LLVM_CPPFLAGS=`$LLVM_CONFIG --cxxflags | dnl |
| 105 |
tr '\t' ' ' | sed -e 's/ */ /g' | tr ' ' '\n' | dnl |
| 106 |
grep -v -e '^-W' dnl |
| 107 |
-e '^-w$' dnl |
| 108 |
-e '^-pedantic' dnl |
| 109 |
-e '^-f[a-z-]*diagnostics' dnl |
| 110 |
-e '^-f[a-z-]*show' dnl |
| 111 |
-e '^-g' dnl |
| 112 |
-e '^-O$' dnl |
| 113 |
-e '^-O[0-9s]' dnl |
| 114 |
-e '^-isysroot$' dnl |
| 115 |
-e '^/Applications/Xcode\\.app/.*\\.sdk$' | dnl |
| 116 |
xargs` |
| 117 |
changequote([, ])dnl |
| 118 |
LLVM_LDFLAGS="`$LLVM_CONFIG --ldflags` $LLVM_SYSLIBS" |
| 119 |
LLVM_LIBS=`$LLVM_CONFIG --libs $2` |
| 120 |
|
| 121 |
# The output of `llvm-config --ldflags' often contains library directives |
| 122 |
# that must come *after* all the LLVM libraries on the link line: e.g., |
| 123 |
# "-lpthread -lffi -ldl -lm". To ensure this, we insert LLVM_LDFLAGS into |
| 124 |
# LIBS, *not* into LDFLAGS. |
| 125 |
# |
| 126 |
# Newer LLVM's (post-3.4) support `llvm-config --system-libs', which will |
| 127 |
# possibly help us to straighten this out in the future. |
| 128 |
|
| 129 |
AC_REQUIRE([AC_PROG_CXX]) |
| 130 |
CPPFLAGS_SAVED="$CPPFLAGS" |
| 131 |
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS" |
| 132 |
LDFLAGS_SAVED="$LDFLAGS" |
| 133 |
LDFLAGS="$LDFLAGS" |
| 134 |
# LDFLAGS="$LDFLAGS $LLVM_LDFLAGS" --- see comment above. |
| 135 |
LIBS_SAVED="$LIBS" |
| 136 |
LIBS="$LIBS $LLVM_LIBS $LLVM_LDFLAGS" |
| 137 |
# LIBS="$LIBS $LLVM_LIBS" --- see comment above. |
| 138 |
|
| 139 |
AC_CACHE_CHECK(can compile with and link with LLVM([$2]), |
| 140 |
ax_cv_llvm, |
| 141 |
[ |
| 142 |
AC_LANG_PUSH([C++]) |
| 143 |
AC_LINK_IFELSE([ |
| 144 |
AC_LANG_PROGRAM( |
| 145 |
[[@%:@include <llvm/IR/LLVMContext.h> |
| 146 |
@%:@include <llvm/IR/Module.h>]], |
| 147 |
[[llvm::LLVMContext context; |
| 148 |
llvm::Module *M = new llvm::Module("test", context);]])], |
| 149 |
ax_cv_llvm=yes, |
| 150 |
ax_cv_llvm=no) |
| 151 |
AC_LANG_POP([C++]) |
| 152 |
]) |
| 153 |
|
| 154 |
CPPFLAGS="$CPPFLAGS_SAVED" |
| 155 |
LDFLAGS="$LDFLAGS_SAVED" |
| 156 |
LIBS="$LIBS_SAVED" |
| 157 |
|
| 158 |
if test "$ax_cv_llvm" != "yes"; then |
| 159 |
AC_MSG_FAILURE( |
| 160 |
[cannot compile and link test program with selected LLVM]) |
| 161 |
fi |
| 162 |
AC_SUBST(LLVM_BINDIR) |
| 163 |
]) |