#! /bin/sh
# mingw32-build.sh
#
  ISSUE=1 DLLVER=1
#
# A quick and dirty build script, for zlib-1.2.3 on mingw32
# Written 26-Jul-2009 by Keith Marshall <keithmarshall@users.sourceforge.net>
#
# For native building, invoke as:
#   /bin/sh mingw32-build.sh
#
# For cross-hosted building, invoke as:
#   tool_prefix=i586-pc-mingw32- /bin/sh mingw32-build.sh
#
#   (substitute the appropriate prefix for your tool chain, and note
#    the final hyphen)
#
# ----------------------------------------------------------------------------
#
# Need to patch the original sources:
#
  if test ! -f patch.stamp
  then
    patchdir=`dirname $0`
    for patch in ${patchdir}/mingw32-patch.*
    do
      patch -p0 < $patch
    done
    echo timestamp > patch.stamp
  fi
#
# zlib's Noddy configure script gets EXEEXT determination wrong,
# so we need to force the correct setting; (they call it EXE)...
#
  EXE=.exe ./configure
#
# We can now proceed to build and test the static library...
#
  if make all check
  then
#
#   Static library build was successful; this Q&D hack builds a DLL version,
#   together with its associated import library...
#
    ${tool_prefix}gcc -s -shared -o libz-${DLLVER-"1"}.dll \
	-Wl,--out-implib=libz.dll.a win32/zlib.def libz.a
#
#   Now, we relink the executables, using the DLL, and retest...
#
    set -e; rm -f *.exe; make all check
  fi
#
# If we got this far, we've completed a successful build; package it...
#
  version=`pwd | sed 's,.*-,,'`
  echo "Creating packages..."
  rm -rf staged; make prefix=`pwd`/staged install
  cd staged; mkdir bin; cp ../libz-1.dll bin; cp ../libz.dll.a lib
  tar czf libz-${version}-${ISSUE-"1"}-mingw32-dev.tar.gz include lib
  tar czf libz-${version}-${ISSUE-"1"}-mingw32-dll-${DLLVER-"1"}.tar.gz bin
  tar czf zlib-${version}-${ISSUE-"1"}-mingw32-man.tar.gz share
  mkdir -p share/doc/zlib/${version}; cp ../README share/doc/zlib/${version}
  rm -rf share/man; tar czf zlib-${version}-${ISSUE-"1"}-mingw32-lic.tar.gz share
  rm share/doc/zlib/${version}/README; cp ../FAQ share/doc/zlib/${version}
  (cd ..; tar cf - examples) | (cd share/doc/zlib/${version}; tar xf -)
  tar czf zlib-${version}-${ISSUE-"1"}-mingw32-doc.tar.gz share
  rm -rf bin include lib share
  echo "... done"
#
# mingw32-build.sh: end of file
