From ca180a5fcd288baec6abc53d74138f6df5ffb488 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sat, 1 Feb 2014 00:21:54 -0600 Subject: [PATCH] Added initial checkin of Windows build script to automate ImageMagick compilation in Windows. It can build ImageMagick against a default MinGW installation or Qt's MinGW installation. --- cmake/Windows/build-imagemagick.sh | 230 +++++++++++++++++++++++++++++ cmake/Windows/urls.txt | 10 ++ 2 files changed, 240 insertions(+) create mode 100644 cmake/Windows/build-imagemagick.sh create mode 100644 cmake/Windows/urls.txt diff --git a/cmake/Windows/build-imagemagick.sh b/cmake/Windows/build-imagemagick.sh new file mode 100644 index 00000000..78fa7eed --- /dev/null +++ b/cmake/Windows/build-imagemagick.sh @@ -0,0 +1,230 @@ +#!/bin/bash +# xml2 build ok but failed test +# libfpx build error + +function ised() { + IN=$1 + shift + tmp=$RANDOM.$$ + <$IN sed "$@" >$tmp && cat $tmp > $IN + rm $tmp +} + +function ask() { + read -p "${1:-Are you sure?]} [Y/n] " response + case $response in + y|Y|"") + true;; + *) + false;; + esac +} + +function download() { + while IFS=\; read url md5 <&3; do + fileName=${url##*/} + + echo "Downloading ${fileName}..." + while true; do + if [[ ! -e $fileName ]]; then + wget ${url} -O ${fileName} + else + echo "File exists!" + fi + + localMd5=$(md5sum ${fileName} | cut -d\ -f1) + + if [[ ${localMd5} != ${md5} ]]; then + ask "Checksum failed. Do you want to download this file again? [Y/n] " + if [[ $? -ne 0 ]]; then + exit 1 + fi + rm ${fileName} + else + break + fi + done + done 3< urls.txt +} + +function extract() { + file=$1 + if [[ ! -e ${file} ]]; then + return + fi + + case $file in + *.tar.gz) + tar xzf $file + ;; + *.tar.xz|*.tar.lzma) + tar xJf $file + ;; + *.tar.bz2) + tar xjf $file + ;; + *) + "Don't know how to extract $file" + esac +} + +function isLibsInstalled() { + libs="$@" + notfound=false + for l in "${libs}"; do + ld -L/usr/local/lib -l"${l}" + if [[ $? -ne 0 ]]; then + notfound=true + fi + done + + ! ${notfound} +} + +function isDirExists() { + dir="$@" + found=false + for d in ${dir}; do + if [[ -d "${d}" ]]; then + found=true + break + fi + done + + ${found} +} + +function extractIfNeeded() { + file=$1 + isDirExists ${file%%-*}-* + if [[ $? -ne 0 ]]; then + echo "Extracting $file" + extract $file + fi +} + +function buildbzip2() { + if isLibsInstalled "bz2"; then + if ask "Found bzip2 installed. Do you want to reinstall it?"; then : + else + return 0 + fi + fi + + extractIfNeeded bzip2-*.tar.lzma + + cd bzip2-*/ + tar xzf bzip2-1.0.6.tar.gz + tar xzf cygming-autotools-buildfiles.tar.gz + cd bzip2-*/ + autoconf + mkdir ../build + cd ../build + ../bzip2-*/configure + make + make install + cd ../.. +} + +function buildzlib() { + if isLibsInstalled "z"; then + if ask "Found zlib installed. Do you want to reinstall it?"; then : + else + return 0 + fi + fi + + extractIfNeeded zlib-*.tar.xz + + cd zlib-*/ + INCLUDE_PATH=/usr/local/include LIBRARY_PATH=/usr/local/lib BINARY_PATH=/usr/local/bin make install -f win32/Makefile.gcc SHARED_MODE=1 + cd .. +} + +function buildlibxml2() { + if isLibsInstalled "xml2"; then + if ask "Found libxml2 installed. Do you want to reinstall it?"; then : + else + return 0 + fi + fi + extractIfNeeded libxml2-*.tar.gz + cd libxml2-*/win32/ + cscript.exe configure.js compiler=mingw prefix=/usr/local + ised ../dict.c '/typedef.*uint32_t;$/d' + ised Makefile.mingw 's/cmd.exe \/C "\?if not exist \(.*\) mkdir \1"\?/mkdir -p \1/' + ised Makefile.mingw 's/cmd.exe \/C "copy\(.*\)"/cp\1/' + ised Makefile.mingw '/cp/{y/\\/\//;}' + ised Makefile.mingw '/PREFIX/{y/\\/\//;}' + make -f Makefile.mingw + make -f Makefile.mingw install + cd ../../ +} + +function buildlibpng() { + if isLibsInstalled "png"; then + if ask "Found libpng installed. Do you want to reinstall it?"; then : + else + return 0 + fi + fi + + extractIfNeeded libpng-*.tar.xz + + cd libpng-*/ + make -f scripts/makefile.msys + make install -f scripts/makefile.msys + cd .. +} + +function buildjpegsrc() { + if isLibsInstalled "jpeg"; then + if ask "Found jpegsrc installed. Do you want to reinstall it?"; then : + else + return 0 + fi + fi + + extract jpegsrc*.tar.gz + + cd jpeg-*/ + ./configure + make + make install + cd .. +} + +function buildDelegate() { + delegates="bzip2 zlib libxml2 libpng jpegsrc freetype libwmf libwebp" + for d in ${delegates}; do + echo "**********************************************************" + echo "Building $d" + build${d} + done +} + +function build() { + extractIfNeeded ImageMagick-*.tar.xz + + local oldPwd=$(pwd -L) + cd ImageMagick-*/ + # patch configure + #sed -i 's/${GDI32_LIBS}x" !=/${GDI32_LIBS} ==/' configure + ised configure 's/${GDI32_LIBS}x" !=/${GDI32_LIBS} ==/' + ./configure --enable-shared --disable-static --enable-delegate-build --without-modules CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" + make + make install + cd ${oldPwd} +} + +function spitDll() { + cd /usr/local/lib + for f in libMagick*.dll.a; do + gcc --shared -o ${f%.a} -Wl,--out-implib=$f -Wl,--export-all-symbols -Wl,--enable-auto-import + done +} + +download +buildDelegate +build +spitDll diff --git a/cmake/Windows/urls.txt b/cmake/Windows/urls.txt new file mode 100644 index 00000000..f774b8a7 --- /dev/null +++ b/cmake/Windows/urls.txt @@ -0,0 +1,10 @@ +ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.8.8-4.tar.xz;fe7c78dd29aa7d88e77a7f4c617bf29d +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/libpng-1.6.8.tar.xz;51ce71a1642cdde1f4485a7ff82193c0 +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/libwebp-0.3.1.tar.gz;dc862bb4006d819b7587767a9e83d31f +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/libwmf-0.2.8.4.tar.gz;d1177739bf1ceb07f57421f0cee191e0 +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/libxml2-2.9.1.tar.gz;9c0cfef285d5c4a5c80d00904ddab380 +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/zlib-1.2.8.tar.xz;28f1205d8dd2001f26fec1e8c2cebe37 +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/freetype-2.5.2.tar.bz2;10e8f4d6a019b124088d18bc26123a25 +http://ncu.dl.sourceforge.net/project/mingw/MinGW/Extension/bzip2/bzip2-1.0.6-4/bzip2-1.0.6-4-mingw32-src.tar.lzma;2a25de4331d1e6e1458d8632dff55fad +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/libfpx-1.3.1-3.tar.xz;e61be90557b26bf365ad63d3dd3b0877 +ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/jpegsrc.v9.tar.gz;b397211ddfd506b92cd5e02a22ac924d