emit.c: emit_named_unsigned: call emit_unsigned instead of emit_int
[pet.git] / m4 / ax_detect_clang.m4
blob3008a35b550ae4429e6502082279d89be13ffdb9
1 AC_DEFUN([AX_DETECT_CLANG], [
2 AC_SUBST(CLANG_CXXFLAGS)
3 AC_SUBST(CLANG_LDFLAGS)
4 AC_SUBST(CLANG_LIBS)
5 AC_SUBST(CLANG_RFLAG)
6 AX_SUBMODULE(clang,system,system)
7 llvm_config="llvm-config"
8 AC_CHECK_PROG([llvm_config_found], ["$llvm_config"], [yes])
9 if test "x$with_clang_prefix" != "x"; then
10         llvm_config="$with_clang_prefix/bin/llvm-config"
11         if test -x "$llvm_config"; then
12                 llvm_config_found=yes
13         fi
15 if test "$llvm_config_found" != yes; then
16         AC_MSG_ERROR([llvm-config not found])
18 CLANG_CXXFLAGS=`$llvm_config --cxxflags | \
19         $SED -e 's/-Wcovered-switch-default//'`
20 CLANG_LDFLAGS=`$llvm_config --ldflags`
21 CLANG_VERSION=`$llvm_config --version`
22 CLANG_LIB="LLVM-$CLANG_VERSION"
24 SAVE_LDFLAGS="$LDFLAGS"
25 LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"
26 AC_CHECK_LIB([$CLANG_LIB], [main], [have_lib_llvm=yes], [have_lib_llvm=no])
27 LDFLAGS="$SAVE_LDFLAGS"
29 # Use single libLLVM shared library when available.
30 # Otherwise, try and figure out all the required libraries
31 if test "$have_lib_llvm" = yes; then
32         # Construct a -R argument for libtool.
33         # This is apparently required to ensure that libpet.so
34         # keeps track of the location where libLLVM can be found.
35         CLANG_RFLAG=`echo "$CLANG_LDFLAGS" | $SED -e 's/-L/-R/g'`
36         CLANG_LIBS="-l$CLANG_LIB"
37 else
38         targets=`$llvm_config --targets-built`
39         components="$targets asmparser bitreader support mc"
40         $llvm_config --components | $GREP option > /dev/null 2> /dev/null
41         if test $? -eq 0; then
42                 components="$components option"
43         fi
44         CLANG_LIBS=`$llvm_config --libs $components`
46 systemlibs=`$llvm_config --system-libs 2> /dev/null | tail -1`
47 if test $? -eq 0; then
48         CLANG_LIBS="$CLANG_LIBS $systemlibs"
50 CLANG_PREFIX=`$llvm_config --prefix`
51 AC_DEFINE_UNQUOTED(CLANG_PREFIX, ["$CLANG_PREFIX"], [Clang installation prefix])
53 SAVE_CPPFLAGS="$CPPFLAGS"
54 CPPFLAGS="$CLANG_CXXFLAGS $CPPFLAGS"
55 AC_LANG_PUSH(C++)
56 AC_CHECK_HEADER([clang/Basic/SourceLocation.h], [],
57         [AC_ERROR([clang header file not found])])
58 AC_EGREP_HEADER([getDefaultTargetTriple], [llvm/Support/Host.h], [],
59         [AC_DEFINE([getDefaultTargetTriple], [getHostTriple],
60         [Define to getHostTriple for older versions of clang])])
61 AC_EGREP_HEADER([getExpansionLineNumber], [clang/Basic/SourceLocation.h], [],
62         [AC_DEFINE([getExpansionLineNumber], [getInstantiationLineNumber],
63         [Define to getInstantiationLineNumber for older versions of clang])])
64 AC_EGREP_HEADER([getExpansionColumnNumber], [clang/Basic/SourceLocation.h], [],
65         [AC_DEFINE([getExpansionColumnNumber], [getInstantiationColumnNumber],
66         [Define to getInstantiationColumnNumber for older versions of clang])])
67 AC_EGREP_HEADER([getExpansionLoc], [clang/Basic/SourceManager.h], [],
68         [AC_DEFINE([getExpansionLoc], [getInstantiationLoc],
69         [Define to getInstantiationLoc for older versions of clang])])
70 AC_EGREP_HEADER([DiagnosticConsumer], [clang/Basic/Diagnostic.h], [],
71         [AC_DEFINE([DiagnosticConsumer], [DiagnosticClient],
72         [Define to DiagnosticClient for older versions of clang])])
73 AC_EGREP_HEADER([DiagnosticsEngine], [clang/Basic/Diagnostic.h],
74         [AC_DEFINE([DiagnosticInfo], [Diagnostic],
75         [Define to Diagnostic for newer versions of clang])],
76         [AC_DEFINE([DiagnosticsEngine], [Diagnostic],
77         [Define to Diagnostic for older versions of clang])])
78 AC_EGREP_HEADER([ArrayRef], [clang/Driver/Driver.h],
79         [AC_DEFINE([USE_ARRAYREF], [],
80                 [Define if Driver::BuildCompilation takes ArrayRef])])
81 AC_EGREP_HEADER([CXXIsProduction], [clang/Driver/Driver.h],
82         [AC_DEFINE([HAVE_CXXISPRODUCTION], [],
83                 [Define if Driver constructor takes CXXIsProduction argument])])
84 AC_EGREP_HEADER([ IsProduction], [clang/Driver/Driver.h],
85         [AC_DEFINE([HAVE_ISPRODUCTION], [],
86                 [Define if Driver constructor takes IsProduction argument])])
87 AC_TRY_COMPILE([#include <clang/Driver/Driver.h>], [
88         using namespace clang;
89         DiagnosticsEngine *Diags;
90         new driver::Driver("", "", "", *Diags);
91 ], [AC_DEFINE([DRIVER_CTOR_TAKES_DEFAULTIMAGENAME], [],
92               [Define if Driver constructor takes default image name])])
93 AC_EGREP_HEADER([void HandleTopLevelDecl\(], [clang/AST/ASTConsumer.h],
94         [AC_DEFINE([HandleTopLevelDeclReturn], [void],
95                    [Return type of HandleTopLevelDeclReturn])
96          AC_DEFINE([HandleTopLevelDeclContinue], [],
97                    [Return type of HandleTopLevelDeclReturn])],
98         [AC_DEFINE([HandleTopLevelDeclReturn], [bool],
99                    [Return type of HandleTopLevelDeclReturn])
100          AC_DEFINE([HandleTopLevelDeclContinue], [true],
101                    [Return type of HandleTopLevelDeclReturn])])
102 AC_CHECK_HEADER([clang/Basic/DiagnosticOptions.h],
103         [AC_DEFINE([HAVE_BASIC_DIAGNOSTICOPTIONS_H], [],
104                    [Define if clang/Basic/DiagnosticOptions.h exists])])
105 AC_CHECK_HEADER([clang/Lex/HeaderSearchOptions.h],
106         [AC_DEFINE([HAVE_LEX_HEADERSEARCHOPTIONS_H], [],
107                    [Define if clang/Lex/HeaderSearchOptions.h exists])], [],
108         [#include <clang/Basic/LLVM.h>])
109 AC_CHECK_HEADER([clang/Lex/PreprocessorOptions.h],
110         [AC_DEFINE([HAVE_LEX_PREPROCESSOROPTIONS_H], [],
111                    [Define if clang/Lex/PreprocessorOptions.h exists])], [],
112         [#include <clang/Basic/LLVM.h>])
113 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
114         using namespace clang;
115         std::shared_ptr<TargetOptions> TO;
116         DiagnosticsEngine *Diags;
117         TargetInfo::CreateTargetInfo(*Diags, TO);
118 ], [AC_DEFINE([CREATETARGETINFO_TAKES_SHARED_PTR], [],
119               [Define if TargetInfo::CreateTargetInfo takes shared_ptr])])
120 AC_TRY_COMPILE([#include <clang/Basic/TargetInfo.h>], [
121         using namespace clang;
122         TargetOptions *TO;
123         DiagnosticsEngine *Diags;
124         TargetInfo::CreateTargetInfo(*Diags, TO);
125 ], [AC_DEFINE([CREATETARGETINFO_TAKES_POINTER], [],
126               [Define if TargetInfo::CreateTargetInfo takes pointer])])
127 AC_EGREP_HEADER([getLangOpts], [clang/Lex/Preprocessor.h], [],
128         [AC_DEFINE([getLangOpts], [getLangOptions],
129         [Define to getLangOptions for older versions of clang])])
130 AC_EGREP_HEADER([findLocationAfterToken], [clang/Lex/Lexer.h],
131         [AC_DEFINE([HAVE_FINDLOCATIONAFTERTOKEN], [],
132         [Define if SourceManager has findLocationAfterToken method])])
133 AC_EGREP_HEADER([translateLineCol], [clang/Basic/SourceManager.h],
134         [AC_DEFINE([HAVE_TRANSLATELINECOL], [],
135         [Define if SourceManager has translateLineCol method])])
136 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
137         using namespace clang;
138         DiagnosticConsumer *client;
139         CompilerInstance *Clang;
140         Clang->createDiagnostics(client);
141 ], [], [AC_DEFINE([CREATEDIAGNOSTICS_TAKES_ARG], [],
142         [Define if CompilerInstance::createDiagnostics takes argc and argv])])
143 AC_TRY_COMPILE([#include <clang/Lex/HeaderSearchOptions.h>], [
144         using namespace clang;
145         HeaderSearchOptions HSO;
146         HSO.AddPath("", frontend::Angled, false, false);
147 ], [AC_DEFINE([ADDPATH_TAKES_4_ARGUMENTS], [],
148         [Define if HeaderSearchOptions::AddPath takes 4 arguments])])
149 AC_EGREP_HEADER([getLocWithOffset], [clang/Basic/SourceLocation.h], [],
150         [AC_DEFINE([getLocWithOffset], [getFileLocWithOffset],
151         [Define to getFileLocWithOffset for older versions of clang])])
152 AC_TRY_COMPILE([#include <clang/Frontend/CompilerInstance.h>], [
153         using namespace clang;
154         CompilerInstance *Clang;
155         Clang->createPreprocessor(TU_Complete);
156 ], [AC_DEFINE([CREATEPREPROCESSOR_TAKES_TUKIND], [],
157 [Define if CompilerInstance::createPreprocessor takes TranslationUnitKind])])
158 AC_EGREP_HEADER([DecayedType], [clang/AST/Type.h],
159         [AC_DEFINE([HAVE_DECAYEDTYPE], [], [Define if DecayedType is defined])])
160 AC_EGREP_HEADER([setMainFileID], [clang/Basic/SourceManager.h],
161         [AC_DEFINE([HAVE_SETMAINFILEID], [],
162         [Define if SourceManager has a setMainFileID method])])
163 AC_CHECK_HEADER([llvm/ADT/OwningPtr.h],
164         [AC_DEFINE([HAVE_ADT_OWNINGPTR_H], [],
165                    [Define if llvm/ADT/OwningPtr.h exists])])
166 AC_EGREP_HEADER([TypeInfo getTypeInfo], [clang/AST/ASTContext.h],
167         [AC_DEFINE([GETTYPEINFORETURNSTYPEINFO], [],
168                 [Define if getTypeInfo returns TypeInfo object])])
169 AC_EGREP_HEADER([TypedefNameDecl], [clang/AST/Type.h], [],
170         [AC_DEFINE([TypedefNameDecl], [TypedefDecl],
171                 [Define to TypedefDecl for older versions of clang])
172          AC_DEFINE([getTypedefNameForAnonDecl], [getTypedefForAnonDecl],
173                 [Define to getTypedefForAnonDecl for older versions of clang])])
174 AC_EGREP_HEADER([StmtRange], [clang/AST/StmtIterator.h],
175         [AC_DEFINE([HAVE_STMTRANGE], [],
176         [Define if StmtRange class is available])])
177 AC_EGREP_HEADER([initializeBuiltins],
178         [clang/Basic/Builtins.h], [],
179         [AC_DEFINE([initializeBuiltins], [InitializeBuiltins],
180                 [Define to InitializeBuiltins for older versions of clang])])
181 AC_TRY_COMPILE([
182         #include <clang/Basic/TargetOptions.h>
183         #include <clang/Lex/PreprocessorOptions.h>
184         #include <clang/Frontend/CompilerInstance.h>
185 ], [
186         using namespace clang;
187         CompilerInstance *Clang;
188         TargetOptions TO;
189         llvm::Triple T(TO.Triple);
190         PreprocessorOptions PO;
191         CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C,
192                         T, PO, LangStandard::lang_unspecified);
193 ], [AC_DEFINE([SETLANGDEFAULTS_TAKES_5_ARGUMENTS], [],
194         [Define if CompilerInvocation::setLangDefaults takes 5 arguments])])
195 AC_LANG_POP
196 CPPFLAGS="$SAVE_CPPFLAGS"
198 SAVE_LDFLAGS="$LDFLAGS"
199 LDFLAGS="$CLANG_LDFLAGS $LDFLAGS"
200 AC_SUBST(LIB_CLANG_EDIT)
201 AC_CHECK_LIB([clangEdit], [main], [LIB_CLANG_EDIT=-lclangEdit], [])
202 LDFLAGS="$SAVE_LDFLAGS"