Browse code

move llvm option flag handling to new m4 file

Kevin Lin authored on 2016/03/01 01:34:25
Showing 2 changed files
... ...
@@ -50,121 +50,12 @@ AC_CHECK_GNU_MAKE
50 50
 GMAKE="$llvm_cv_gnu_make_command"
51 51
 AC_SUBST([GMAKE])
52 52
 
53
-llvmconfig=
54
-AC_ARG_WITH([system-llvm], AC_HELP_STRING([--with-system-llvm],
55
-[Use system llvm instead of built-in, uses full path to llvm-config (default=
56
-    search /usr/local or /usr if not found in /usr/local)]),
57
-[case "$withval" in
58
-  yes)
59
-     llvmconfig="/usr/local/bin/llvm-config"
60
-     if test ! -x "$llvmconfig"; then
61
-     llvmconfig="/usr/bin/llvm-config"
62
-       if test ! -x "$llvmconfig"; then
63
-         AC_MSG_ERROR([llvm-config cannot be found within defaults])
64
-       fi
65
-     fi
66
-     ;;
67
-  no) ;;
68
-  *)
69
-     llvmconfig="$withval"
70
-     if test ! -x "$llvmconfig"; then
71
-       AC_MSG_ERROR([llvm-config does not exist at $llvmconfig])
72
-     fi
73
-     ;;
74
-  esac
53
+m4_include(m4/llvm-flags.m4)
75 54
 
76
- if test "x$llvmconfig" != "x"; then
77
-     llvmver=`$llvmconfig --version`
78
-
79
-     AC_MSG_NOTICE([Using external LLVM])
80
- fi
81
-])
82
-
83
-llvm_linking=
84
-AC_ARG_WITH([llvm-linking], [AC_HELP_STRING([--with-llvm-linking],
85
-[specifies method to linking llvm @<:@static|dynamic@:>@, only valid with --with-system-llvm])],
86
-[
87
-if test "x$llvmconfig" = "x"; then
88
-   AC_MSG_ERROR([Failed to configure LLVM, and LLVM linking was specified without valid llvm-config])  
89
-else
90
-case "$withval" in
91
-  static)
92
-    llvm_linking="static"
93
-    ;;
94
-  dynamic)
95
-    llvm_linking="dynamic"
96
-    ;;
97
-  *)
98
-    AC_MSG_ERROR([Invalid argument to --with-llvm-linking])
99
-esac
100
-fi
101
-], [])
102
-
103
-AC_MSG_CHECKING([for supported LLVM version])
104 55
 if test "x$llvmconfig" = "x"; then
105 56
     dnl macro not available in older autotools
106 57
     AC_CONFIG_SUBDIRS([llvm])
107
-    dnl llvmver=`$srcdir/llvm/configure --version | sed -n 1p | sed 's/llvm configure //'`
108
-    llvmver="2.8"
109
-    packaged_llvm="yes"
110
-fi
111
-
112
-llvmver_val=`echo "$llvmver" | sed -e 's/svn//g'`
113
-llvmver_major=`echo "$llvmver_val" | sed -e 's/\([[0-9]]\).*/\1/'`
114
-llvmver_minor=`echo "$llvmver_val" | sed -e 's/[[0-9]]//' | sed -e 's/^\.//' | sed -e 's/\([[0-9]]\).*/\1/'`
115
-llvmver_patch=`echo "$llvmver_val" | sed -e 's/[[0-9]]\.[[0-9]]//' | sed -e 's/^\.//' | sed -e 's/\([[0-9]]\).*/\1/'`
116
-dnl suffix unused as of LLVM 3.4.1
117
-llvmver_suffix=
118
-if test "x$llvmver_patch" = "x"; then
119
-    llvmver_patch=0
120
-fi
121
-
122
-llvmver_test=${llvmver_major}${llvmver_minor}${llvmver_patch}
123
-if test "x$packaged_llvm" = "xyes"; then
124
-    AC_MSG_RESULT([ok ($llvmver)])
125
-elif test $llvmver_test -lt 290; then
126
-    AC_MSG_RESULT([no ($llvmver)])
127
-    AC_MSG_ERROR([LLVM >= 2.9 required, but "$llvmver"($llvmver_test) found])
128
-elif test $llvmver_test -lt 360; then
129
-    llvmcomp="jit nativecodegen scalaropts ipo"
130
-    AC_MSG_RESULT([ok ($llvmver)])
131
-elif test $llvmver_test -lt 370; then
132
-    dnl LLVM 3.6.0 removed jit, so we have to use mcjit
133
-    dnl and we're using InitializeNativeTargetAsmParser, so we need the architecture specific parsers
134
-    llvmcomp="mcjit nativecodegen scalaropts ipo x86asmparser powerpcasmparser"
135
-    AC_MSG_RESULT([ok ($llvmver)])
136
-else
137
-    AC_MSG_RESULT([no ($llvmver)])
138
-    AC_MSG_ERROR([LLVM < 3.7 required, but "$llvmver"($llvmver_test) found])
139
-fi
140
-
141
-dnl aquire the required flags to properly link in external LLVM
142
-if test "x$llvmconfig" != "x"; then
143
-    AC_SUBST(LLVMCONFIG_CXXFLAGS, [`$llvmconfig --cxxflags`])
144
-
145
-    if test "x$llvm_linking" = "xdynamic"; then
146
-        AC_SUBST(LLVMCONFIG_LDFLAGS, [`$llvmconfig --ldflags`])
147
-        AC_SUBST(LLVMCONFIG_LIBS, [-lLLVM-$llvmver])
148
-        AC_SUBST(LLVMCONFIG_LIBFILES, [])
149
-    else
150
-        if test $llvmver_test -ge 350; then
151
-           dnl LLVM 3.5.0 and after splits linker flags into two sets
152
-           ldflags=`$llvmconfig --ldflags`
153
-           syslibs=`$llvmconfig --system-libs`
154
-           AC_SUBST(LLVMCONFIG_LDFLAGS, ["$ldflags $syslibs"])
155
-        else
156
-           AC_SUBST(LLVMCONFIG_LDFLAGS, [`$llvmconfig --ldflags`])
157
-        fi
158
-        AC_SUBST(LLVMCONFIG_LIBS, [`$llvmconfig --libs $llvmcomp`])
159
-        AC_SUBST(LLVMCONFIG_LIBFILES, [`$llvmconfig --libfiles $llvmcomp`])
160
-    fi
161
-
162
-    AC_MSG_NOTICE([CXXFLAGS from llvm-config: $LLVMCONFIG_CXXFLAGS])
163
-    AC_MSG_NOTICE([LDFLAGS from llvm-config: $LLVMCONFIG_LDFLAGS])
164
-    AC_MSG_NOTICE([LIBS from llvm-config: $LLVMCONFIG_LIBS])
165 58
 fi
166
-dnl patch does not affect clamav source (yet)
167
-llvmver_int=${llvmver_major}${llvmver_minor}
168 59
 
169 60
 AC_SUBST([LLVM_VERSION], [$llvmver_int])
170 61
 
171 62
new file mode 100644
... ...
@@ -0,0 +1,125 @@
0
+dnl Act as a single handler point for LLVM options
1
+dnl Compile a set of compile and linker flags for LLVM
2
+dnl Populates LLVMCONFIG_CXXFLAGS, LLVMCONFIG_LDFLAGS, LLVMCONFIG_LIBS, and LLVMCONFIG_LIBFILES macros
3
+dnl Assigns llvmver_int, system_llvm, llvm_linking, and enable_llvm variables (for tracking in features summary)
4
+
5
+dnl Determine if LLVM is requested (or auto, reassigned if system-llvm specified)
6
+AC_ARG_ENABLE([llvm],AC_HELP_STRING([--enable-llvm],
7
+[enable 'llvm' JIT/verifier support @<:@default=auto@:>@]),
8
+[enable_llvm=$enableval], [enable_llvm="auto"])
9
+
10
+dnl Determine whether to user built in LLVM or to use system-specified LLVM
11
+dnl locate the llvmconfig program
12
+AC_ARG_WITH([system-llvm], AC_HELP_STRING([--with-system-llvm],
13
+[Use system llvm instead of built-in, uses full path to llvm-config or bin directory
14
+     (default=search PATH environment variable)]),
15
+[case "$withval" in
16
+  yes)
17
+     AC_PATH_PROG([llvmconfig], [llvm-config])
18
+     if test "x$llvmconfig" = "x"; then
19
+         AC_MSG_ERROR([llvm-config cannot be found within PATH])
20
+     fi
21
+     ;;
22
+  no) ;;
23
+  *)
24
+     if test -d "$withval"; then
25
+         AC_PATH_PROG([llvmconfig], [llvm-config], [], [$withval/bin])
26
+     else
27
+         llvmconfig=$withval
28
+         if test ! -x "$llvmconfig"; then
29
+             llvmconfig=""
30
+         fi
31
+     fi
32
+
33
+     if test "x$llvmconfig" = "x"; then
34
+         AC_MSG_ERROR([llvm-config does not exist at $withval])
35
+     fi
36
+     ;;
37
+  esac
38
+])
39
+
40
+dnl Determine linking method to external LLVM, built-in only does static linking
41
+AC_ARG_WITH([llvm-linking], [AC_HELP_STRING([--with-llvm-linking],
42
+[specifies method to linking llvm @<:@static|dynamic@:>@, only valid with --with-system-llvm])],
43
+[if test "x$llvmconfig" = "x"; then
44
+   AC_MSG_ERROR([Failed to configure LLVM, and LLVM linking was specified without valid llvm-config])  
45
+else
46
+   case "$withval" in
47
+     static)
48
+         llvm_linking="static"
49
+         ;;
50
+     dynamic)
51
+         llvm_linking="dynamic"
52
+         ;;
53
+     *)
54
+         AC_MSG_ERROR([Invalid argument to --with-llvm-linking])
55
+   esac
56
+fi
57
+], [llvm_linking=""])
58
+
59
+dnl Version number check
60
+if test "x$llvmconfig" != "x"; then
61
+    llvmver=`$llvmconfig --version`
62
+    AC_MSG_NOTICE([Using external LLVM])
63
+else
64
+    llvmver="2.8"
65
+    packaged_llvm="yes"
66
+fi
67
+
68
+llvmver_val=`echo "$llvmver" | sed -e 's/svn//g'`
69
+llvmver_major=`echo "$llvmver_val" | sed -e 's/\([[0-9]]\).*/\1/'`
70
+llvmver_minor=`echo "$llvmver_val" | sed -e 's/[[0-9]]//' | sed -e 's/^\.//' | sed -e 's/\([[0-9]]\).*/\1/'`
71
+llvmver_patch=`echo "$llvmver_val" | sed -e 's/[[0-9]]\.[[0-9]]//' | sed -e 's/^\.//' | sed -e 's/\([[0-9]]\).*/\1/'`
72
+dnl suffix unused as of LLVM 3.4.1
73
+llvmver_suffix=
74
+if test "x$llvmver_patch" = "x"; then
75
+    llvmver_patch=0
76
+fi
77
+
78
+AC_MSG_CHECKING([for supported LLVM version])
79
+llvmver_test=${llvmver_major}${llvmver_minor}${llvmver_patch}
80
+if test "x$packaged_llvm" = "xyes"; then
81
+    AC_MSG_RESULT([ok ($llvmver)])
82
+elif test $llvmver_test -lt 290; then
83
+    AC_MSG_RESULT([no ($llvmver)])
84
+    AC_MSG_ERROR([LLVM >= 2.9 required, but "$llvmver"($llvmver_test) found])
85
+elif test $llvmver_test -lt 360; then
86
+    llvmcomp="jit nativecodegen scalaropts ipo"
87
+    AC_MSG_RESULT([ok ($llvmver)])
88
+elif test $llvmver_test -lt 370; then
89
+    dnl LLVM 3.6.0 removed jit, so we have to use mcjit
90
+    dnl and we're using InitializeNativeTargetAsmParser, so we need the architecture specific parsers
91
+    llvmcomp="mcjit nativecodegen scalaropts ipo x86asmparser powerpcasmparser"
92
+    AC_MSG_RESULT([ok ($llvmver)])
93
+else
94
+    AC_MSG_RESULT([no ($llvmver)])
95
+    AC_MSG_ERROR([LLVM < 3.7 required, but "$llvmver"($llvmver_test) found])
96
+fi
97
+
98
+dnl aquire the required flags to properly link in external LLVM
99
+if test "x$llvmconfig" != "x"; then
100
+    AC_SUBST(LLVMCONFIG_CXXFLAGS, [`$llvmconfig --cxxflags`])
101
+
102
+    if test "x$llvm_linking" = "xdynamic"; then
103
+        AC_SUBST(LLVMCONFIG_LDFLAGS, [`$llvmconfig --ldflags`])
104
+        AC_SUBST(LLVMCONFIG_LIBS, [-lLLVM-$llvmver])
105
+        AC_SUBST(LLVMCONFIG_LIBFILES, [])
106
+    else
107
+        if test $llvmver_test -ge 350; then
108
+           dnl LLVM 3.5.0 and after splits linker flags into two sets
109
+           ldflags=`$llvmconfig --ldflags`
110
+           syslibs=`$llvmconfig --system-libs`
111
+           AC_SUBST(LLVMCONFIG_LDFLAGS, ["$ldflags $syslibs"])
112
+        else
113
+           AC_SUBST(LLVMCONFIG_LDFLAGS, [`$llvmconfig --ldflags`])
114
+        fi
115
+        AC_SUBST(LLVMCONFIG_LIBS, [`$llvmconfig --libs $llvmcomp`])
116
+        AC_SUBST(LLVMCONFIG_LIBFILES, [`$llvmconfig --libfiles $llvmcomp`])
117
+    fi
118
+
119
+    AC_MSG_NOTICE([CXXFLAGS from llvm-config: $LLVMCONFIG_CXXFLAGS])
120
+    AC_MSG_NOTICE([LDFLAGS from llvm-config: $LLVMCONFIG_LDFLAGS])
121
+    AC_MSG_NOTICE([LIBS from llvm-config: $LLVMCONFIG_LIBS])
122
+fi
123
+dnl patch does not affect clamav source (yet)
124
+llvmver_int=${llvmver_major}${llvmver_minor}