Skip to content

Commit f42917f

Browse files
authored
Merge pull request #430 from sosy-lab/add-libmathsat5j-compile-for-macos
Extend compile.sh for libmathsat5j for macOS dylib
2 parents 1e5b4cc + 5bad3d7 commit f42917f

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

lib/native/source/get_jni_headers.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#
99
# SPDX-License-Identifier: Apache-2.0
1010

11-
if [ `uname` = "Darwin" ] ; then
12-
echo "-I/usr/local/include -I/sw/include -I/System/Library/Frameworks/JavaVM.framework/Headers"
11+
if [ "$(uname)" = "Darwin" ] ; then
12+
java_home=`readlink -f \`which java\``
13+
java_home=`echo $java_home | sed 's#/jre/bin/java##' | sed 's#/bin/java##'`
14+
echo "-I/usr/local/include -I/sw/include -I/System/Library/Frameworks/JavaVM.framework/Headers -I${java_home}/include/ -I${java_home}/include/darwin/"
1315
LINK_OPT="-dynamiclib -o libJOct.jnilib"
1416
elif [ `uname` = "Linux" ] ; then
1517
java_home=`readlink -f \`which java\``

lib/native/source/libmathsat5j/compile.sh

+56-10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ GMP_HEADER_DIR="$2"
6262
SRC_FILES="org_sosy_1lab_java_1smt_solvers_mathsat5_Mathsat5NativeApi.c"
6363
OBJ_FILES="org_sosy_1lab_java_1smt_solvers_mathsat5_Mathsat5NativeApi.o"
6464

65+
if [ "$(uname)" = "Darwin" ]; then
66+
IS_MACOS=true
67+
else
68+
IS_MACOS=false
69+
fi
70+
6571
# check requirements
6672
if [ ! -f "$MSAT_LIB_DIR/libmathsat.a" ]; then
6773
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
7379
exit 1
7480
fi
7581

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+
7696
# switch between MathSAT5 and OptiMathSAT
7797
if [ "$3" = "-optimathsat" ]; then
7898
echo "Compiling bindings to OptiMathSAT"
@@ -81,7 +101,11 @@ if [ "$3" = "-optimathsat" ]; then
81101
OUT_FILE="liboptimathsat5j.so"
82102
ADDITIONAL_FLAGS="-D INCLUDE_OPTIMATHSAT5_HEADER"
83103
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
85109
ADDITIONAL_FLAGS=""
86110
fi
87111

@@ -96,11 +120,20 @@ echo "Linking libraries together into one file..."
96120
# This will link together the file produced above, the Mathsat library, the GMP library and the standard libraries.
97121
# Everything except the standard libraries is included statically.
98122
# 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
101134
else
102135
# 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++
104137
fi
105138

106139
if [ $? -ne 0 ]; then
@@ -115,13 +148,26 @@ strip ${OUT_FILE}
115148

116149
echo "Reduction Done"
117150

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
123161
fi
124-
125162
echo "All Done"
126163
echo "Please check the following dependencies that will be required at runtime by mathsat5j.so:"
127164
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

Comments
 (0)