@@ -62,6 +62,12 @@ GMP_HEADER_DIR="$2"
62
62
SRC_FILES=" org_sosy_1lab_java_1smt_solvers_mathsat5_Mathsat5NativeApi.c"
63
63
OBJ_FILES=" org_sosy_1lab_java_1smt_solvers_mathsat5_Mathsat5NativeApi.o"
64
64
65
+ if [ " $( uname) " = " Darwin" ]; then
66
+ IS_MACOS=true
67
+ else
68
+ IS_MACOS=false
69
+ fi
70
+
65
71
# check requirements
66
72
if [ ! -f " $MSAT_LIB_DIR /libmathsat.a" ]; then
67
73
echo " You need to specify the directory with the downloaded MathSAT5 on the command line!"
@@ -73,6 +79,20 @@ if [ ! -f "$GMP_LIB_DIR/libgmp.a" ]; then
73
79
exit 1
74
80
fi
75
81
82
+ if [ " $IS_MACOS " = true ]; then
83
+ if ! command -v clang & > /dev/null; then
84
+ echo " clang compiler not found."
85
+ echo " Please install Apple's clang through the Xcode developer tools:"
86
+ echo " xcode-select --install"
87
+ exit 1
88
+ elif ! clang --version | grep -q " ^Apple" ; then
89
+ echo " WARNING: clang compiler found but it is not Apple clang."
90
+ echo " This may cause problems with signing the library for use on macOS."
91
+ echo " Please install Apple's clang through the Xcode developer tools:"
92
+ echo " xcode-select --install"
93
+ fi
94
+ fi
95
+
76
96
# switch between MathSAT5 and OptiMathSAT
77
97
if [ " $3 " = " -optimathsat" ]; then
78
98
echo " Compiling bindings to OptiMathSAT"
@@ -81,7 +101,11 @@ if [ "$3" = "-optimathsat" ]; then
81
101
OUT_FILE=" liboptimathsat5j.so"
82
102
ADDITIONAL_FLAGS=" -D INCLUDE_OPTIMATHSAT5_HEADER"
83
103
else
84
- OUT_FILE=" libmathsat5j.so"
104
+ if [ " $IS_MACOS " = true ]; then
105
+ OUT_FILE=" libmathsat5j.dylib"
106
+ else
107
+ OUT_FILE=" libmathsat5j.so"
108
+ fi
85
109
ADDITIONAL_FLAGS=" "
86
110
fi
87
111
@@ -96,11 +120,20 @@ echo "Linking libraries together into one file..."
96
120
# This will link together the file produced above, the Mathsat library, the GMP library and the standard libraries.
97
121
# Everything except the standard libraries is included statically.
98
122
# The result is a single shared library containing all necessary components.
99
- if [ ` uname -m` = " x86_64" ]; then
100
- gcc -Wall -g -o ${OUT_FILE} -shared -Wl,-soname,libmathsat5j.so -L. -L${MSAT_LIB_DIR} -L${GMP_LIB_DIR} -I${GMP_HEADER_DIR} ${OBJ_FILES} -Wl,-Bstatic -lmathsat -lgmpxx -lgmp -static-libstdc++ -lstdc++ -Wl,-Bdynamic -lc -lm
123
+ if [ " $IS_MACOS " = true ]; then
124
+ # Next to some smaller macOS-specific changes compared to the Linux version,
125
+ # there is one important peculiarity: Apple's clang does not support the `-Bstatic` flag
126
+ # for an individual link. The Apple-specific counterpart `-static` has different behavior:
127
+ # If specified, it does not only link the next library statically, but all libraries.
128
+ # We do not want this, so we explicitly specify the path to the static libraries
129
+ # where we want this (without `-l`).
130
+ clang -Wall -g -o " ${OUT_FILE} " -dynamiclib -Wl,-install_name,@rpath/libmathsat5j.dylib -L. -L" ${MSAT_LIB_DIR} " -L" ${GMP_LIB_DIR} " -I" ${GMP_HEADER_DIR} " ${OBJ_FILES} " ${MSAT_LIB_DIR} " /libmathsat.a -lgmpxx -lgmp -lstdc++ -lc -lm
131
+
132
+ elif [ " $( uname -m) " = " x86_64" ]; then
133
+ gcc -Wall -g -o " ${OUT_FILE} " -shared -Wl,-soname,libmathsat5j.so -L. -L" ${MSAT_LIB_DIR} " -L" ${GMP_LIB_DIR} " -I" ${GMP_HEADER_DIR} " ${OBJ_FILES} -Wl,-Bstatic -lmathsat -lgmpxx -lgmp -static-libstdc++ -lstdc++ -Wl,-Bdynamic -lc -lm
101
134
else
102
135
# TODO compiling for/on a 32bit system was not done for quite a long time. We should drop it.
103
- gcc -Wall -g -o ${OUT_FILE} -shared -Wl,-soname,libmathsat5j.so -L${MSAT_LIB_DIR} -L${GMP_LIB_DIR} -I${GMP_HEADER_DIR} ${OBJ_FILES} -Wl,-Bstatic -lmathsat -lgmpxx -lgmp -Wl,-Bdynamic -lc -lm -lstdc++
136
+ gcc -Wall -g -o " ${OUT_FILE} " -shared -Wl,-soname,libmathsat5j.so -L" ${MSAT_LIB_DIR} " -L" ${GMP_LIB_DIR} " -I" ${GMP_HEADER_DIR} " ${OBJ_FILES} -Wl,-Bstatic -lmathsat -lgmpxx -lgmp -Wl,-Bdynamic -lc -lm -lstdc++
104
137
fi
105
138
106
139
if [ $? -ne 0 ]; then
@@ -115,13 +148,26 @@ strip ${OUT_FILE}
115
148
116
149
echo " Reduction Done"
117
150
118
- MISSING_SYMBOLS=" $( readelf -Ws ${OUT_FILE} | grep NOTYPE | grep GLOBAL | grep UND) "
119
- if [ ! -z " $MISSING_SYMBOLS " ]; then
120
- echo " Warning: There are the following unresolved dependencies in libmathsat5j.so:"
121
- readelf -Ws ${OUT_FILE} | grep NOTYPE | grep GLOBAL | grep UND
122
- exit 1
151
+ if [ " $IS_MACOS " = true ]; then
152
+ # TODO: Be nice and also check for missing symbols
153
+ echo -n " "
154
+ else
155
+ MISSING_SYMBOLS=" $( readelf -Ws ${OUT_FILE} | grep NOTYPE | grep GLOBAL | grep UND) "
156
+ if [ -n " $MISSING_SYMBOLS " ]; then
157
+ echo " Warning: There are the following unresolved dependencies in libmathsat5j.so:"
158
+ readelf -Ws ${OUT_FILE} | grep NOTYPE | grep GLOBAL | grep UND
159
+ exit 1
160
+ fi
123
161
fi
124
-
125
162
echo " All Done"
126
163
echo " Please check the following dependencies that will be required at runtime by mathsat5j.so:"
127
164
LANG=C objdump -p ${OUT_FILE} | grep -A50 " required from"
165
+
166
+ if [ " $IS_MACOS " = true ]; then
167
+ echo "
168
+ You've just built ${OUT_FILE} for macOS. Before you can use this library, you
169
+ need to sign it with a certificate that your system trusts, or with an Apple
170
+ Developer ID. Signing with a known, trusted certificate can be done with
171
+ this command:
172
+ codesign -s \" Your Certificate Name\" --timestamp ${OUT_FILE} "
173
+ fi
0 commit comments