# SConscript for lcdtest
# $Id: SConscript 34 2007-05-24 04:33:06Z eric $
# Copyright 2004, 2005, 2006, 2007 Eric L. Smith <eric@brouhaha.com>

# lcdtest 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 lcdtest under the
# terms of any later version of the General Public License.

# lcdtest 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')

import os

#-----------------------------------------------------------------------------
# convert help SFont from PNG to C source
#-----------------------------------------------------------------------------

help_font_png = '14P_Arial_Plain_Red.png'

PNG2PNM = Builder (action = "$PNG2PNMCOM",
                   suffix = '.pnm',
                   src_suffix = '.png')

env.Append (BUILDERS = { 'PNG2PNM': PNG2PNM },
            PNG2PNMCOM = "pngtopnm $SOURCE >$TARGET")

PPM2C = Builder (action = "$PPM2CCOM",
                 suffix = '.c',
                 src_suffix = '.ppm')

env.Append (BUILDERS = { 'PPM2C': PPM2C },
            PPM2CCOM = "ppmtoxpm -name `basename $SOURCE .ppm`_xpm $SOURCE | sed 's/static //;s/black/#000000/;s/magenta/#FF00FF/;s/#E40808/#009900/' >$TARGET")

env.PNG2PNM (target = 'help_font.ppm',
             source = help_font_png)

help_font_c = env.PPM2C (target = 'help_font.c',
                         source = 'help_font.ppm')

#-----------------------------------------------------------------------------
# compile and link
#-----------------------------------------------------------------------------

headers = Split ("""SFont.h""")
srcs = Split ("""lcdtest.c SFont.c""")

objs = [env.Object(src) for src in srcs]

objs.append (env.Object (target = 'help_font.o',
                         source = help_font_c));

# respect the environment CFLAGS if given
if 'CFLAGS' in ARGUMENTS:
    env.MergeFlags (ARGUMENTS ['CFLAGS'])
elif 'CFLAGS' in os.environ:
    env.MergeFlags (os.environ ['CFLAGS'])
else:
    env.Append (CCFLAGS = ['-g', '-Wall', '-Wextra'])

env.Append (LIBS = ['SDL', 'SDL_image']);

env.Append (CPPDEFINES = [ ('RELEASE', env ['RELEASE'])])

lcdtest = env.Program (target = 'lcdtest',
                       source = objs)

#-----------------------------------------------------------------------------
# default targets
#-----------------------------------------------------------------------------

default_targets = [lcdtest]

Default (default_targets)

#-----------------------------------------------------------------------------
# install
#-----------------------------------------------------------------------------

env.Alias (target = 'install',
           source = env.Install (dir = env ['destdir'] + env ['bindir'],
                                 source = default_targets))

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

misc = Split ("""SConscript""")

dist_files = (misc + headers + srcs + [help_font_png])

env.Distribute (env ['SOURCE_RELEASE_DIR'], dist_files)

env.Distribute (env ['SNAPSHOT_DIR'], dist_files)

