#!/bin/sh
#
# $Id$
#
# This script is probably not useful to most people.  It is used
# to extract a set of downloaded files for gtk for windows and 
# also extract a bunch of license files.
#
# It is used when initially setting up a cygwin environment for 
# building gerbv or pcb with a non-cygwin version for windows
# as the goal.

# directory where all the files have been downloaded
gtk_win32_downloads=${HOME}/gtk_win32_downloads

# directory to extract everything (including headers) to.
# This must match ./build_pcb.
gtk_win32=${HOME}/gtk_win32
gd_win32=${HOME}/gd_win32

# directory to extract runtime files (excluding headers) to.
# This must match ./build_pcb.
gtk_win32_runtime=${HOME}/gtk_win32_runtime
gd_win32_runtime=${HOME}/gd_win32_runtime

# clean out old directories
test ! -d ${gtk_win32} || rm -fr ${gtk_win32}
test ! -d ${gtk_win32_runtime} || rm -fr ${gtk_win32_runtime}

test ! -d ${gd_win32} || rm -fr ${gd_win32}
test ! -d ${gd_win32_runtime} || rm -fr ${gd_win32_runtime}

# make the new ones
mkdir -p ${gtk_win32}
mkdir -p ${gtk_win32_runtime}

mkdir -p ${gd_win32}
mkdir -p ${gd_win32_runtime}/bin

# extract the runtime files
cd ${gtk_win32_runtime}
for f in ${gtk_win32_downloads}/*.zip ; do
	fb=`basename "${f}"`
	case "$fb" in
		gd-*)
			echo "Skip gd"
			;;
		*dev*)
			echo "Skip developer file `basename ${fb}`"
			;;
		*src*)
			echo "Skip source file `basename ${fb}`"
			;;
		*)
			echo "Extract ${fb}"
			unzip -n -q "$f"
			;;
	esac
done

# extract the runtime+developer files
cd ${gtk_win32}
for f in ${gtk_win32_downloads}/*.zip ; do
	fb=`basename "${f}"`
	case "$fb" in
		gd-*)
			echo "Skip gd"
			;;
		*src*)
			echo "Skip source file `basename ${fb}`"
			;;
		*)
			echo "Extract ${fb}"
			unzip -n -q "$f"
			;;
	esac
done

chmod 755 ${gtk_win32}/bin/*
mv ${gtk_win32_runtime}/zlib*.dll ${gtk_win32_runtime}/bin
chmod 755 ${gtk_win32_runtime}/bin/*

cd ${HOME}


cd ${gd_win32}
unzip ${gtk_win32_downloads}/gd-*-win32.zip
cp */*.dll ${gd_win32_runtime}/bin
cat > ${gd_win32_runtime}/gd-license.txt << EOF
The GD library which provides png/gif/jpeg exporting
is covered by the following license:

EOF
cat ${gd_win32}/COPYING.TXT >> ${gd_win32_runtime}/gd-license.txt
chmod 755 ${gd_win32}/*/*
chmod 755 ${gd_win32_runtime}/*

cd ${HOME}

# extract licenses

cd
tmpd=/tmp/ext.$$
mkdir ${tmpd}

cd ${tmpd}


cat > ${gtk_win32_runtime}/LICENSE-lgpl << EOF
The following packages are covered by the 
GNU Library General Public License (LGPL)

atk
cairo
glib
gtk+
libiconv
pango
proxy-libintl

----------------------------------------

EOF

cat > ${gtk_win32_runtime}/LICENSE-gpl2 << EOF
The following packages are covered by the GNU General Public License (GPL) v2.

freetype
pkg-config

----------------------------------------

EOF

cat > ${gtk_win32_runtime}/LICENSE-gpl3 << EOF
The following packages are covered by the GNU General Public License (GPL) v3.

gettext

----------------------------------------

EOF


# LGPL
#
# atk-1.22.0.tar.bz2
# atk-1.22.0.zip
# atk-dev-1.22.0.zip

bzcat ${gtk_win32_downloads}/atk-*.tar.bz2 | tar -xf -
cat atk-*/COPYING >> ${gtk_win32_runtime}/LICENSE-lgpl
rm -fr atk-*

# dual LGPL and MPL (Mozilla public license)
#
#cairo-1.6.4.tar.gz
#cairo-1.6.4.zip
#cairo-dev-1.6.4.zip

# no copyright assigned and placed in public domain
#
# dirent.zip

# sort of BSD with advertising like
#expat-2.0.0.zip
echo "expat is covered by the following copyright and license" > ${gtk_win32_runtime}/LICENSE-expat
cat ${gtk_win32_downloads}/COPYING-expat >> ${gtk_win32_runtime}/LICENSE-expat


#fontconfig-2.4.2-tml-20071015.diff
#fontconfig-2.4.2-tml-20071015.zip
#fontconfig-2.4.2.tar.gz
#fontconfig-dev-2.4.2-tml-20071015.zip
tar -zxvf ${gtk_win32_downloads}/fontconfig-*.tar.gz 
echo "fontconfig is covered by the following license" > ${gtk_win32_runtime}/LICENSE-fontconfig
cat fontconfig*/COPYING >> ${gtk_win32_runtime}/LICENSE-fontconfig
rm -fr fontconfig-*

#
# Dual, "you choose" license.  We pick GPL v2.
#freetype-2.3.4.tar.bz2
#freetype-2.3.4.zip
#freetype-dev-2.3.4.zip
#bzcat  ${gtk_win32_downloads}/freetype-2.3.4.tar.bz2  | tar -xvf - mv freetype-*/*/LICENSE.TXT ${gtk_win32_runtime}/LICENSE-freetype
#rm -fr freetype-*


# GPL v3
#
#gettext-0.17.tar.gz
#gettext-runtime-0.17.zip
#gettext-runtime-dev-0.17.zip
#gettext-tools-0.17.zip
tar -zxvf ${gtk_win32_downloads}/gettext-*.tar.gz
cat gettext-*/COPYING >> ${gtk_win32_runtime}/LICENSE-gpl3
rm -fr gettext-*


# LGPL
#glib-2.16.5.tar.bz2
#glib-2.16.5.zip
#glib-dev-2.16.5.zip

# LGPL
#
#gtk+-2.12.11.tar.bz2
#gtk+-2.12.11.zip
#gtk+-dev-2.12.11.zip


# jpeg license
#
#jpeg-6b-4-bin.zip
#jpeg-6b-4-dep.zip
#jpeg-6b-4-lib.zip
#jpegsrc.v6b.tar.gz

#unzip ${gtk_win32_downloads}/jpeg-*-src.zip
tar -zxvf ${gtk_win32_downloads}/jpegsrc.v6b.tar.gz
echo "libjpeg is covered by the following license:" > ${gtk_win32_runtime}/LICENSE-jpeg
cat jpeg-6b/README >> ${gtk_win32_runtime}/LICENSE-jpeg
rm -fr jpeg-6b

# LGPL
#
#libiconv-1.9.1.bin.woe32.zip
#libiconv-1.9.1.tar.gz

#libpng-1.2.9.tar.gz
#libpng-dev-1.2.9.zip
#libpng-1.2.9.zip
mkdir tmppng
cd tmppng
unzip ${gtk_win32_downloads}/libpng-dev-*.zip
ls 
ls include

echo "libpng is covered by the following copyright and license" > ${gtk_win32_runtime}/LICENSE-png
awk '/COPYRIGHT/,/^[ \t]*$/ {print}' include/png.h >> ${gtk_win32_runtime}/LICENSE-png
cd ..
rm -fr tmppng

# LGPL
#
#pango-1.20.5.tar.bz2
#pango-1.20.5.zip
#pango-dev-1.20.5.zip


# GPL
#
#pkg-config-0.23.tar.gz
#pkg-config-0.23-2.zip
tar -zxvf ${gtk_win32_downloads}/pkg-config-*.tar.gz
cat pkg-config-*/COPYING >> ${gtk_win32_runtime}/LICENSE-gpl2
rm -fr pkg-config-*

# LGPL
#
# proxy-libintl-20080728.zip

# BSD-like with advertising clause
#
#tiff-3.8.2.tar.gz
#libtiff-3.8.2.zip
#libtiff-dev-3.8.2.zip
tar -zxvf ${gtk_win32_downloads}/tiff-*.tar.gz
echo "libtiff is covered by the following license:" > ${gtk_win32_runtime}/LICENSE-tiff
cat tiff-*/COPYRIGHT >> ${gtk_win32_runtime}/LICENSE-tiff
rm -fr tiff-*

# Not needed anymore
#xpm-nox-4.0.3-20020617.zip
#xpm-nox-dev-4.0.3-20020112.zip
#tar -zxvf ${gtk_win32_downloads}/xpm-*.tar.gz
#echo "The xpm library is covered by the following license and copyright:" > ${gtk_win32_runtime}/LICENSE-xpm
#cat xpm-*/COPYRIGHT >> ${gtk_win32_runtime}/LICENSE-xpm
#rm -fr xpm-*

#zlib123-dll.zip
# the license had to be found on the zlib web site
echo "zlib is covered by the following license and copyright" > ${gtk_win32_runtime}/LICENSE-zlib
cat ${gtk_win32_downloads}/zlib_license.txt >> ${gtk_win32_runtime}/LICENSE-zlib


