# SConscript for Nonpareil
# $Id: SConscript 844 2005-06-27 04:31:13Z eric $
# Copyright 2004, 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')

#-----------------------------------------------------------------------------
# Sources
#-----------------------------------------------------------------------------

unmod_images = Split ("""35.png 45.png 55.png 80.png
                         21.png 25.png
                         32e.png 33c.png 34c.png 37e.png 38c.png
                         41cv.png""")

voyager_base_images = Split ("""11c_base.png 12c_base.png 15c_base.png 16c_base.png""")

voyager_segment_image = Split ("""voyager_segments.png""")

base_images = voyager_base_images       # some day there may be others

segment_images = voyager_segment_image  # some day there may be others

#-----------------------------------------------------------------------------
# convert PNG files to PNM for manipulation
#-----------------------------------------------------------------------------

PNG2PNM = Builder (action = "pngtopnm $SOURCE >$TARGET",
                   suffix = ".pnm",
                   src_suffix = ".png")

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

voyager_pnm_images = [env.PNG2PNM(src) for src in voyager_base_images]

voyager_segment_pnm = env.PNG2PNM (voyager_segment_image)

#-----------------------------------------------------------------------------
# build Voyager PNG images from the PNM pieces (base image + segment image)
#-----------------------------------------------------------------------------

vimg_env = env.Copy ()

def VPNM2PNG_Emitter (target, source, env):
    source.append (voyager_segment_pnm)
    return (target, source)

VPNM2PNG = Builder (action = "pnmcat -lr $SOURCES | pnmtopng -compression 9 >$TARGET",
                   suffix = ".png",
                   src_suffix = "_base.pnm",
                   emitter = VPNM2PNG_Emitter)

vimg_env.Append (BUILDERS = { 'VPNM2PNG' : VPNM2PNG })


derived_images = [vimg_env.VPNM2PNG(src) for src in voyager_pnm_images]

#-----------------------------------------------------------------------------
# Export 41CV image for use in building Nonpareil executable
#-----------------------------------------------------------------------------

env.Append (IMAGE_41CV = File ('41cv.png'))

#-----------------------------------------------------------------------------
# Default targets
#-----------------------------------------------------------------------------

Default (derived_images)

#-----------------------------------------------------------------------------
# Install image files
#-----------------------------------------------------------------------------

env.Alias (target = 'install',
           source = env.Install (dir = env ['destdir'] + env ['libdir'],
                                 source = unmod_images + derived_images))

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

dist_files = ['SConscript'] + unmod_images + base_images + segment_images

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, unmod_images + derived_images)
