# SConscript for Nonpareil
# $Id: SConscript 851 2005-06-28 00:04:30Z eric $
# Copyright 2005, Eric L. Smith <eric@brouhaha.com>

# Nonpareil is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.  Note that I am not
# granting permission to redistribute or modify Nonpareil under the
# terms of any later version of the General Public License.

# Nonpareil is distributed in the hope that they will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program (in the file "COPYING"); if not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111, USA.

Import('env source_release_dir snapshot_dir')

#-----------------------------------------------------------------------------
# Unzip stuff
#-----------------------------------------------------------------------------

import os.path
import zipfile

def unzip_action (target, source, env):
    zf = zipfile.ZipFile (str (source [0]), 'r')
    for name in zf.namelist ():
        if os.path.basename (str (target [0])) == os.path.basename (name):
            open (str (target [0]), 'w').write (zf.read (name))
            zf.close ()
            return 0   # OK
    zf.close ()
    return 1   # error - target wasn't found

UNZIP = Builder (action = unzip_action,
                 suffix = '.dll',
                 src_suffix = 'zip')

env.Append (BUILDERS = { 'UNZIP' : UNZIP })

#-----------------------------------------------------------------------------
# Win32 DLLs
#
# We don't currently build these ourselves, but we've got the source and
# binary distribution archives in our source repository.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# libxml2
#-----------------------------------------------------------------------------

# from http://xmlsoft.org/sources/
libxml2_src_dist = 'libxml2-2.6.19.tar.gz'

# from http://www.zlatkovic.com/libxml.en.html
libxml2_bin_dist = 'libxml2-2.6.19.win32.zip'

libxml2_dll = env.UNZIP ('libxml2.dll', libxml2_bin_dist)

#-----------------------------------------------------------------------------
# sdl
#-----------------------------------------------------------------------------

# from http://www.libsdl.org/download-1.2.php
sdl_src_dist = 'SDL-1.2.8.zip'
sdl_bin_dist = 'SDL-1.2.8-win32.zip'

sdl_dll = env.UNZIP ('SDL.dll', sdl_bin_dist)

#-----------------------------------------------------------------------------
# all together now
#-----------------------------------------------------------------------------

all_dll_src_dist = [libxml2_src_dist, sdl_src_dist]
all_dll_bin_dist = [libxml2_bin_dist, sdl_bin_dist]
all_dll          = [libxml2_dll,      sdl_dll]

#-----------------------------------------------------------------------------
# source tarball
#-----------------------------------------------------------------------------

dist_files = ['SConscript'] + all_dll

env.Distribute (source_release_dir, dist_files)

env.Distribute (snapshot_dir, dist_files)

#-----------------------------------------------------------------------------
# Windows distribution ZIP file
#-----------------------------------------------------------------------------

if env ['target'] == 'win32':
    Import ('win32_bin_dist_dir')
    Install (win32_bin_dist_dir, all_dll)
