Rgaudin has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/216507

Change subject: Fixed compilation on OSX. made a script to compile both static 
and shared
......................................................................

Fixed compilation on OSX. made a script to compile both static and shared

Change-Id: I9dd7b7039988be13f932bdb3e4b30c5bcf2e6783
---
M zimwriterfs/README
A zimwriterfs/macosx-build.sh
2 files changed, 79 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/openzim refs/changes/07/216507/1

diff --git a/zimwriterfs/README b/zimwriterfs/README
index c1d2b10..d8d6a83 100644
--- a/zimwriterfs/README
+++ b/zimwriterfs/README
@@ -32,16 +32,10 @@
 OSX compilation
 ----------------
 
-Until the autotool is configured properly to support flexible options,
-you can still compile and use zimwriterfs with some manual work.
+On MaxOSX, a script helps you build zimwriterfs both statically and 
dynamically.
+You must have a working and set up Kiwix repository (with dependencies ready).
 
-1. Have a working Kiwix dev environnment (up to make inside src/dependencies)
-2. Install libmagic: brew install libmagic
-3. zimwriterfs compilation
-./autogen.sh
-LDFLAGS="-L$KIWIX_ROOT/src/dependencies/zimlib-1.1/build/lib/ 
-L/usr/local/Cellar/libmagic/5.14/lib/ 
-L$KIWIX_ROOT/src/dependencies/xz/build/lib/" CXXFLAGS="-I 
$KIWIX_ROOT/src/kiwix/src/dependencies/zimlib-1.1/include/ 
-I/usr/local/Cellar/libmagic/5.14/include/ 
-I$KIWIX_ROOT/src/kiwix/src/dependencies/xz/src/liblzma/lzma/ 
-I$KIWIX_ROOT/src/kiwix/src/dependencies/xz/src/liblzma/" ./configure && make
-4. Copy libs if not in LIBRARY_PATH
-ln -s $KIWIX_ROOT/src/dependencies/zimlib-1.1/build/lib/libzim.dylib .
-ln -s $KIWIX_ROOT/src/dependencies/xz/build/lib/liblzma.dylib .
-5. Use it
-./zimwriterfs
\ No newline at end of file
+1. Install libmagic with brew (it's important)
+       - ruby -e "$(curl -fsSL 
https://raw.githubusercontent.com/Homebrew/install/master/install)"
+       - brew install libmagic
+2. KIWIX_ROOT=/Users/xxx/src/kiwix ./macosx-build.sh
diff --git a/zimwriterfs/macosx-build.sh b/zimwriterfs/macosx-build.sh
new file mode 100755
index 0000000..6f2e3bc
--- /dev/null
+++ b/zimwriterfs/macosx-build.sh
@@ -0,0 +1,73 @@
+#!/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"
+LIBMAGIC_DIR="${MAGIC_DIR}/lib"
+STATIC_LDFLAGS="${LIBZIM_DIR}/libzim.a ${LIBLZMA_DIR}/liblzma.a 
${LIBMAGIC_DIR}/libmagic.a -lz"
+#LDFLAGS="-L${KIWIX_ROOT}/src/dependencies/zimlib-1.2/build/lib/ -lzim 
-L${KIWIX_ROOT}/src/dependencies/xz/build/lib/ -llzma 
-L/usr/local/Cellar/libmagic/5.22_1/lib/ -lmagic -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}

-- 
To view, visit https://gerrit.wikimedia.org/r/216507
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9dd7b7039988be13f932bdb3e4b30c5bcf2e6783
Gerrit-PatchSet: 1
Gerrit-Project: openzim
Gerrit-Branch: master
Gerrit-Owner: Rgaudin <rgau...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to