Created
June 20, 2012 09:38
-
-
Save jeeb/2959078 to your computer and use it in GitHub Desktop.
Compilation script for zlib/bzip2 on windows for the usual mingw toolchains
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 | |
# Get the date and compile folder | |
DATE_PREFIX=`date +"%Y-%m-%d_%H-%M_"` | |
FOLDERNAME="${DATE_PREFIX}compiles" | |
# Get the mingw prefixes | |
P32B=i686-w64-mingw32 | |
P64B=x86_64-w64-mingw32 | |
# Install prefixes | |
IP32B=${HOME}/ownapps/mingw-w64-i686 | |
IP64B=${HOME}/ownapps/mingw-w64-x86_64 | |
# Set the zlib and bzip2 versions | |
ZLIB_VER="1.2.8" | |
BZIP_VER="1.0.6" | |
ZLIB_DIR_NAME="zlib-${ZLIB_VER}" | |
ZLIB_ARC_NAME="${ZLIB_DIR_NAME}.tar.gz" | |
ZLIB_URL="http://zlib.net/${ZLIB_ARC_NAME}" | |
BZIP_DIR_NAME="bzip2-${BZIP_VER}" | |
BZIP_ARC_NAME="${BZIP_DIR_NAME}.tar.gz" | |
BZIP_URL="http://www.bzip.org/${BZIP_VER}/${BZIP_ARC_NAME}" | |
# Boilerplate functions | |
COL_R='\E[31m' | |
COL_G='\E[32m' | |
COL_Y='\E[33m' | |
COL_RESET='\E[0m' | |
info() | |
{ | |
message=${1} | |
echo -e "[${COL_G}INF${COL_RESET}] ${message}" | |
return | |
} | |
warning() | |
{ | |
message=${1} | |
echo -e "[${COL_Y}WAR${COL_RESET}] ${message}" | |
return | |
} | |
error() | |
{ | |
message=${1} | |
echo -e "[${COL_R}ERR${COL_RESET}] ${message}" | |
return | |
} | |
download() | |
{ | |
file=${1} | |
wget "${file}" | |
RETVAL=$? | |
if [ ! "${RETVAL}" -eq 0 ]; then | |
error "Download of ${file} failed!" | |
exit 1 | |
else | |
info "Download of ${file} succeeded." | |
return | |
fi | |
} | |
extract() | |
{ | |
file=${1} | |
tar -xf "${file}" | |
RETVAL=$? | |
if [ ! "${RETVAL}" -eq 0 ]; then | |
error "Extraction of ${file} failed!" | |
exit 1 | |
else | |
info "Extraction of ${file} succeeded." | |
return | |
fi | |
} | |
compile() | |
{ | |
specs=${1} | |
name=${2} | |
make ${specs} | |
RETVAL=$? | |
if [ ! "${RETVAL}" -eq 0 ]; then | |
error "Compilation of ${name} failed (make ${specs})!" | |
exit 1 | |
else | |
info "Compilation of ${name} succeeded." | |
return | |
fi | |
} | |
# Boilerplate ends | |
info "Starting the compile script." | |
info "32bit prefix is: ${P32B}" | |
info "64bit prefix is: ${P64B}" | |
info "Creating folder: ${FOLDERNAME}" | |
mkdir "${FOLDERNAME}" | |
cd "${FOLDERNAME}" | |
info "Downloading components..." | |
download "${ZLIB_URL}" | |
download "${BZIP_URL}" | |
info "Extracting components..." | |
extract "${ZLIB_ARC_NAME}" | |
extract "${BZIP_ARC_NAME}" | |
info "Compiling zlib..." | |
cd "${ZLIB_DIR_NAME}" | |
compile "-fwin32/Makefile.gcc PREFIX=${P32B}-" "32bit zlib" | |
info "Installing 32bit zlib..." | |
cp -v zconf.h zlib.h "${IP32B}/${P32B}/include/" | |
cp -v libz.a "${IP32B}/${P32B}/lib/" | |
make -f win32/Makefile.gcc clean | |
compile "-fwin32/Makefile.gcc PREFIX=${P64B}-" "64bit zlib" | |
info "Installing 64bit zlib..." | |
cp -v zconf.h zlib.h "${IP64B}/${P64B}/include/" | |
cp -v libz.a "${IP64B}/${P64B}/lib/" | |
cd .. | |
info "Compiling bzip2..." | |
cd "${BZIP_DIR_NAME}" | |
# Welp, auto-patching an include because otherwise win32/64 bzip2 won't cross-compile | |
sed -i 's/sys\\stat\.h/sys\/stat\.h/g' bzip2.c | |
# Now compile | |
compile "-i CC=${P32B}-gcc AR=${P32B}-ar RANLIB=${P32B}-ranlib" "32bit bzip2" | |
info "Installing 32bit bzip2..." | |
make -i install PREFIX="${IP32B}/${P32B}" | |
make clean | |
compile "-i CC=${P64B}-gcc AR=${P64B}-ar RANLIB=${P64B}-ranlib" "64bit bzip2" | |
make -i install PREFIX="${IP64B}/${P64B}" | |
cd .. | |
info "All compiled and installed!" | |
info "Don't worry about the chmod 'Bad file number' errors, that's just bzip2's Makefile failing." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment