Skip to content

Instantly share code, notes, and snippets.

@HimaJyun

HimaJyun/mozjpeg.sh

Last active Feb 15, 2021
Embed
What would you like to do?
mozjpeg cross compile for windows
#!/bin/bash -eux
: "install utils" && {
apt-get update
apt-get install -y nasm cmake curl git mingw-w64 libz-mingw-w64-dev
}
: "compile libpng" && {
tmp=$(curl -s "https://sourceforge.net/projects/libpng/rss" | \
grep "<link>.*.tar.gz" | grep -v "older-releases" | \
sort -r | head -1 | grep -o "https://.*/download")
curl -L -o "libpng.tar.gz" "${tmp}"
mkdir libpng
tar xvf "libpng.tar.gz" --strip-components 1 -C libpng
cd libpng
./configure --host=x86_64-w64-mingw32 \
--prefix=/usr/x86_64-w64-mingw32 \
CPPFLAGS=-I/usr/x86_64-w64-mingw32/include \
LDFLAGS=-L/usr/x86_64-w64-mingw32/lib
make
make install
cd ../
}
: "compile mozjpeg" && {
git clone https://github.com/mozilla/mozjpeg.git
if [ "${MOZJPEG_VERSION:+true}" ];then
cd mozjpeg
git checkout "refs/tags/${MOZJPEG_VERSION}"
cd ../
fi
mkdir build
cd build
cmake -G"Unix Makefiles" \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_SYSTEM_PROCESSOR=AMD64 \
-DCMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc \
-DCMAKE_RC_COMPILER=/usr/bin/x86_64-w64-mingw32-windres \
-DCMAKE_INCLUDE_PATH=/usr/x86_64-w64-mingw32/include \
-DCMAKE_LIBRARY_PATH=/usr/x86_64-w64-mingw32/lib \
"$@" \
../mozjpeg
make
cd ../
}
: "collect exe" && {
if [ -d "/exe" ];then
cp build/*.{exe,dll} libpng/.libs/libpng*.dll "/exe/"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment