forked from doing-dev-stuff/openzim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macosx-build.sh
executable file
·72 lines (60 loc) · 2.27 KB
/
macosx-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
if [ "x$KIWIX_ROOT" = "x" ];
then
echo "You must define envvironment variable KIWIX_ROOT to the root of Kiwix git repository. Exiting."
exit 1
fi
ZIM_DIR="${KIWIX_ROOT}/src/dependencies/zimlib-1.2"
LIBZIM_DIR="${ZIM_DIR}/build/lib"
LZMA_DIR="${KIWIX_ROOT}/src/dependencies/xz/build"
LIBLZMA_DIR="${LZMA_DIR}/lib"
MAGIC_DIR="/usr/local/Cellar/libmagic/5.22_1"
LIBMAGIC_DIR="${MAGIC_DIR}/lib"
STATIC_LDFLAGS="${LIBZIM_DIR}/libzim.a ${LIBLZMA_DIR}/liblzma.a ${LIBMAGIC_DIR}/libmagic.a -lz"
CC="clang -O3"
CXX="clang++ -O3"
CXXFLAGS="-Igumbo -I${ZIM_DIR}/include -I${MAGIC_DIR}/include/ -I${LZMA_DIR}/include"
CFLAGS="$CXXFLAGS"
LDFLAGS="-L. -lzim -llzma -lmagic -lz"
SHARED_OUTPUT="zimwriterfs-shared"
STATIC_OUTPUT="zimwriterfs-static"
function compile {
$CXX $CXXFLAGS -c zimwriterfs.cpp
$CC $CFLAGS -c gumbo/utf8.c
$CC $CFLAGS -c gumbo/string_buffer.c
$CC $CFLAGS -c gumbo/parser.c
$CC $CFLAGS -c gumbo/error.c
$CC $CFLAGS -c gumbo/string_piece.c
$CC $CFLAGS -c gumbo/tag.c
$CC $CFLAGS -c gumbo/vector.c
$CC $CFLAGS -c gumbo/tokenizer.c
$CC $CFLAGS -c gumbo/util.c
$CC $CFLAGS -c gumbo/char_ref.c
$CC $CFLAGS -c gumbo/attribute.c
}
echo "Compiling zimwriterfs for OSX as static then shared."
# remove object files
echo "Clean-up repository (*.o, zimwriterfs-*, *.dylib)"
rm *.o ${STATIC_OUTPUT} ${SHARED_OUTPUT} *.dylib
# compile source code
echo "Compile source code file objects"
compile
# link statically
echo "Link statically into ${STATIC_OUTPUT}"
$CXX $CXXFLAGS $STATIC_LDFLAGS -o ${STATIC_OUTPUT} *.o
# copy dylib to current folder
echo "Copy dylibs into the current folder"
cp -v ${KIWIX_ROOT}/src/dependencies/zimlib-1.2/build/lib/libzim.dylib .
cp -v ${KIWIX_ROOT}/src/dependencies/xz/build/lib/liblzma.dylib .
cp -v ${LIBMAGIC_DIR}/libmagic.dylib .
chmod 644 ./libmagic.dylib
# link dynamicaly
echo "Link dynamically into ${SHARED_OUTPUT}"
$CXX $CXXFLAGS $LDFLAGS -o zimwriterfs-shared *.o
echo "Fix install name tool on ${SHARED_OUTPUT}"
install_name_tool -change ${LIBZIM_DIR}/libzim.0.dylib libzim.dylib ${SHARED_OUTPUT}
install_name_tool -change ${LIBLZMA_DIR}/liblzma.5.dylib liblzma.dylib ${SHARED_OUTPUT}
install_name_tool -change ${LIBMAGIC_DIR}/libmagic.1.dylib libmagic.dylib ${SHARED_OUTPUT}
otool -L ${SHARED_OUTPUT}
ls -lh ${STATIC_OUTPUT}
ls -lh ${SHARED_OUTPUT}