Created
June 24, 2019 14:02
-
-
Save Wizermil/4f738a8dd89284abf2c8a0d87202d272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MINIZIP_VERSION="2.8.8" | |
ROOT_DIR=$(pwd) | |
WORKER=$(getconf _NPROCESSORS_ONLN) | |
BUILD_DIR="build/emscripten/minizip" | |
LOG_FILE="$ROOT_DIR/$BUILD_DIR/build.log" | |
if [ -d "$BUILD_DIR/download" ]; then | |
rm -rf "$BUILD_DIR/download" | |
fi | |
if [ -d "$BUILD_DIR/source" ]; then | |
rm -rf "$BUILD_DIR/source" | |
fi | |
if [ -f "$LOG_FILE" ]; then | |
rm "$LOG_FILE" | |
touch "$LOG_FILE" | |
fi | |
mkdir -p "$BUILD_DIR/download" | |
mkdir -p "$BUILD_DIR/source" | |
error() { | |
echo "$@" 1>&2 | |
} | |
fail() { | |
error "$@" | |
exit 1 | |
} | |
compile_c() { | |
includes=("${!2}") | |
includeArg="" | |
if [ ${#includes} -ne 0 ]; then | |
for i in "${includes[@]}"; do | |
includeArg+="-I \"$i\" " | |
done | |
fi | |
if [ -f "$1" ]; then | |
eval "$CC $CFLAGS -c \"$1\" $includeArg -o \"${1%.cpp}.o\"" >> "$LOG_FILE" 2>&1 || fail "$1 compilation error" | |
else | |
fail "$1 doesn't exist" | |
fi | |
} | |
ar_c() { | |
lib_name="$1" | |
srcs=("${!2}") | |
objects="" | |
for f in "${srcs[@]}"; do | |
filename_obj="${f%.cpp}.o" | |
if [ ! -f "$filename_obj" ]; then | |
fail "$filename_obj doesn't exist" | |
else | |
objects+="\"$filename_obj\" " | |
fi | |
done | |
# echo "$AR -rcs \"$ROOT/$lib_name.a\" $objects" | |
eval "$AR -rcs \"$lib_name.a\" $objects" >> "$LOG_FILE" 2>&1 || fail "ar error" | |
} | |
build_static_library() { | |
lib_name="$1" | |
files=("${!2}") | |
includes=("${!3}") | |
N=$WORKER | |
for f in "${files[@]}"; do | |
((i=i%N)); ((i++==0)) && wait | |
compile_c "$f" includes[@] & | |
done | |
wait | |
ar_c "$lib_name" files[@] | |
} | |
echo "Downloading: minizip" | |
curl -Lo "$BUILD_DIR/download/minizip-$MINIZIP_VERSION.tar.gz" "https://github.com/nmoinvaz/minizip/archive/$MINIZIP_VERSION.tar.gz" >> "$LOG_FILE" 2>&1 || fail "Error download minizip" | |
echo "Downloaded: minizip" | |
echo " " | |
echo "Uncompressing: minizip" | |
tar zxf "$BUILD_DIR/download/minizip-$MINIZIP_VERSION.tar.gz" -C "$BUILD_DIR/source" >> "$LOG_FILE" 2>&1 || fail "Error uncompress minizip" | |
echo "Uncompressed: minizip" | |
echo " " | |
cd "$ROOT_DIR" || exit 1 | |
if [ -d "$BUILD_DIR/output" ]; then | |
rm -rf "$BUILD_DIR/output" | |
fi | |
mkdir -p "$BUILD_DIR/output" | |
cp -R "$BUILD_DIR/source/minizip-$MINIZIP_VERSION/" "$BUILD_DIR/output/$ARCH" | |
if [ -d "$BUILD_DIR/install" ]; then | |
rm -rf "$BUILD_DIR/install" | |
fi | |
mkdir -p "$BUILD_DIR/install" | |
export CFLAGS="-m32 -Os -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_ZLIB=1 -DMZ_ZIP_NO_COMPRESSION=1 -DMZ_ZIP_NO_ENCRYPTION=1 -DMZ_COMPAT=1 -DMZ_COMPAT_VERSION=288 -s USE_ZLIB=1" | |
export CC="emcc" | |
export AR="emar" | |
cd "$ROOT_DIR/$BUILD_DIR/output" || exit 1 | |
if [ -d "$BUILD_DIR/download" ]; then | |
rm -rf "$BUILD_DIR/download" | |
fi | |
echo "Compiling: minizip emscripten" | |
files=( | |
"mz_crypt.c" | |
"mz_os.c" | |
"mz_strm.c" | |
"mz_strm_buf.c" | |
"mz_strm_mem.c" | |
"mz_strm_split.c" | |
"mz_zip.c" | |
"mz_zip_rw.c" | |
"mz_os_posix.c" | |
"mz_strm_os_posix.c" | |
"mz_strm_zlib.c" | |
"mz_compat.c" | |
) | |
includes=() | |
build_static_library "libminizip" files[@] includes[@] | |
echo "Compiled: minizip emscripten" | |
echo " " | |
echo "Installing: minizip emscripten" | |
mkdir -p "$ROOT_DIR/$BUILD_DIR/install/lib" | |
cp libminizip.a "$ROOT_DIR/$BUILD_DIR/install/lib/libminizip.a" | |
mkdir -p "$ROOT_DIR/$BUILD_DIR/install/include" | |
public_headers=( | |
"mz.h" | |
"mz_os.h" | |
"mz_crypt.h" | |
"mz_strm.h" | |
"mz_strm_buf.h" | |
"mz_strm_mem.h" | |
"mz_strm_split.h" | |
"mz_strm_os.h" | |
"mz_zip.h" | |
"mz_zip_rw.h" | |
"mz_strm_zlib.h" | |
"mz_compat.h" | |
) | |
for f in "${public_headers[@]}"; do | |
cp "$f" "$ROOT_DIR/$BUILD_DIR/install/$ARCH/include" | |
done | |
echo "Installed: minizip emscripten" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment