Merge pull request #74 from finnhaedicke/namespace_minisat
[cvc5.git] / config / abc.m4
1 # CVC4_CHECK_FOR_ABC
2 # ------------------
3 # Look for abc and link it in, but only if user requested.
4 AC_DEFUN([CVC4_CHECK_FOR_ABC], [
5 AC_MSG_CHECKING([whether user requested abc support])
6 LIBABC=
7 have_libabc=0
8 ABC_LIBS=
9 ABC_LDFLAGS=
10 if test "$with_abc" = no; then
11 AC_MSG_RESULT([no, abc disabled by user])
12 elif test -n "$with_abc"; then
13 AC_MSG_RESULT([yes, abc requested by user])
14
15 # Get the location of all the ABC stuff
16 AC_ARG_VAR(ABC_HOME, [path to top level of abc source tree])
17 AC_ARG_WITH(
18 [abc-dir],
19 AS_HELP_STRING(
20 [--with-abc-dir=PATH],
21 [path to top level of abc source tree]
22 ),
23 [ABC_HOME="$withval"],
24 [ if test -z "$ABC_HOME"; then
25 AC_MSG_FAILURE([must give --with-abc-dir=PATH or define environment variable ABC_HOME!])
26 fi
27 ]
28 )
29 if ! test -d "$ABC_HOME" || ! test -x "$ABC_HOME/arch_flags"; then
30 AC_MSG_FAILURE([either $ABC_HOME is not an abc source tree or it's not yet built])
31 fi
32
33 AC_MSG_CHECKING([for arch_flags to use with libabc])
34 libabc_arch_flags="$("$ABC_HOME/arch_flags")"
35 AC_MSG_RESULT([$libabc_arch_flags])
36 CVC4CPPFLAGS="${CVC4CPPFLAGS:+$CVC4CPPFLAGS }-I$ABC_HOME/src $libabc_arch_flags"
37 ABC_LDFLAGS="-L$ABC_HOME"
38
39 dnl Try a bunch of combinations until something works :-/
40 cvc4_save_LDFLAGS="$LDFLAGS"
41 ABC_LIBS=
42 CPPFLAGS="$CPPFLAGS -I$ABC_HOME/src $libabc_arch_flags"
43 LDFLAGS="$LDFLAGS $ABC_LDFLAGS"
44 AC_CHECK_HEADER([base/abc/abc.h], [], [AC_MSG_FAILURE([cannot find abc.h, the ABC header!])])
45 AC_MSG_CHECKING([how to link abc])
46 CVC4_TRY_ABC_WITH([])
47 CVC4_TRY_ABC_WITH([-lm])
48 CVC4_TRY_ABC_WITH([-lm -lrt])
49 CVC4_TRY_ABC_WITH([-lm -lrt -ldl])
50 CVC4_TRY_ABC_WITH([-lm -lrt -lreadline -ldl])
51 CVC4_TRY_ABC_WITH([-lm -lpthread])
52 CVC4_TRY_ABC_WITH([-lm -lpthread -lrt])
53 CVC4_TRY_ABC_WITH([-lm -lpthread -lrt -ldl])
54 CVC4_TRY_ABC_WITH([-lm -lpthread -lrt -lreadline -ldl])
55 dnl CVC4_TRY_ABC_WITH([-lm -rdynamic -lreadline -lpthread -lrt -ldl])
56 if test -z "$ABC_LIBS"; then
57 AC_MSG_FAILURE([cannot link against libabc!])
58 else
59 AC_MSG_RESULT([$ABC_LIBS])
60 # make sure it works in static builds, too
61 if test "$enable_static_binary" = yes; then
62 ABC_LIBS=
63 AC_MSG_CHECKING([whether statically-linked abc is functional])
64 CVC4_TRY_STATIC_ABC_WITH([])
65 CVC4_TRY_STATIC_ABC_WITH([-lm])
66 CVC4_TRY_STATIC_ABC_WITH([-lm -lrt])
67 CVC4_TRY_STATIC_ABC_WITH([-lm -lrt -ldl])
68 CVC4_TRY_STATIC_ABC_WITH([-lm -lrt -lreadline -ldl])
69 CVC4_TRY_STATIC_ABC_WITH([-lm -lpthread])
70 CVC4_TRY_STATIC_ABC_WITH([-lm -lpthread -lrt])
71 CVC4_TRY_STATIC_ABC_WITH([-lm -lpthread -lrt -ldl])
72 CVC4_TRY_STATIC_ABC_WITH([-lm -lpthread -lrt -lreadline -ldl])
73 if test -n "$ABC_LIBS"; then
74 AC_MSG_RESULT([yes, it works])
75 with_abc=yes
76 else
77 AC_MSG_RESULT([no])
78 AC_MSG_FAILURE([abc installation appears incompatible with static-binary])
79 fi
80 else
81 with_abc=yes
82 fi
83 fi
84 if test "$with_abc" = yes; then
85 have_libabc=1
86 else
87 with_abc=no
88 have_libreadline=0
89 ABC_LIBS=
90 fi
91 LDFLAGS="$cvc4_save_LDFLAGS"
92 else
93 AC_MSG_RESULT([no, user didn't request abc])
94 with_abc=no
95 fi
96 ])# CVC4_CHECK_FOR_ABC
97
98 # CVC4_TRY_ABC_WITH(LIBS)
99 # -----------------------
100 # Try AC_CHECK_LIB(abc) with the given linking libraries
101 AC_DEFUN([CVC4_TRY_ABC_WITH], [
102 if test -z "$ABC_LIBS"; then
103 AC_LANG_PUSH([C++])
104 cvc4_save_LIBS="$LIBS"
105 LIBS="-labc $1"
106 AC_LINK_IFELSE([AC_LANG_PROGRAM([extern "C" { void Abc_Start(); }],
107 [Abc_Start()])],
108 [ABC_LIBS="-labc $1"],
109 [])
110 LIBS="$cvc4_save_LIBS"
111 AC_LANG_POP([C++])
112 fi
113 ])# CVC4_TRY_ABC_WITH
114
115 # CVC4_TRY_STATIC_ABC_WITH(LIBS)
116 # ------------------------------
117 # Try AC_CHECK_LIB(abc) with the given linking libraries
118 AC_DEFUN([CVC4_TRY_STATIC_ABC_WITH], [
119 if test -z "$ABC_LIBS"; then
120 AC_LANG_PUSH([C++])
121 cvc4_save_LIBS="$LIBS"
122 cvc4_save_LDFLAGS="$LDFLAGS"
123 LDFLAGS="-static $LDFLAGS"
124 LIBS="-labc-static $1"
125 AC_LINK_IFELSE([AC_LANG_PROGRAM([extern "C" { void Abc_Start(); }],
126 [Abc_Start()])],
127 [ABC_LIBS="-labc-static $1"],
128 [ LIBS="-labc $1"
129 AC_LINK_IFELSE([AC_LANG_PROGRAM([extern "C" { void Abc_Start(); }],
130 [Abc_Start()])],
131 [ABC_LIBS="-labc $1"]) ])
132 LIBS="$cvc4_save_LIBS"
133 LDFLAGS="$cvc4_save_LDFLAGS"
134 AC_LANG_POP([C++])
135 fi
136 ])# CVC4_TRY_STATIC_ABC_WITH