# SConstruct for lcdtest
# $Id: SConstruct 38 2007-06-05 23:37:28Z eric $
# Copyright 2004, 2005, 2006 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.

release = '1.08'

conf_file = 'lcdtest.conf'

#-----------------------------------------------------------------------------
# Options
#-----------------------------------------------------------------------------

opts = Options (conf_file)

opts.AddOptions (PathOption ('prefix',
			     'installation path prefix',
			     '/usr/local'),

		 # Don't use PathOption for other paths, because we don't
		 # require the directories to preexist.
		 ('bindir',
		  'path for executable files (default is $prefix/bin)',
		  ''),

		 ('mandir',
		  'path for manual file (default is $prefix/man/man1)',
		  ''),

		 ('destdir',
		  'installation virtual root directory (for packaging)',
		  ''))

#-----------------------------------------------------------------------------
# Cache options
#-----------------------------------------------------------------------------

env = Environment (options = opts)
opts.Update (env)
opts.Save (conf_file, env)

#-----------------------------------------------------------------------------
# Generate help text from options
#-----------------------------------------------------------------------------

Help (opts.GenerateHelpText (env))

#-----------------------------------------------------------------------------
# More defaults and variable settings
#-----------------------------------------------------------------------------

env ['RELEASE'] = release
Export ('env')

#-----------------------------------------------------------------------------
# Add some builders to the environment:
#-----------------------------------------------------------------------------
import sys
import os

SConscript ('scons/tarball.py')

#-----------------------------------------------------------------------------
# package a release source tarball
#-----------------------------------------------------------------------------

bin_dist_files = Split ("""README COPYING""")

src_dist_files = Split ("""SConstruct INSTALL""")

source_release_dir = env.Distribute ('lcdtest-' + release,
				     bin_dist_files + src_dist_files)

source_release_tarball = env.Tarball ('lcdtest-' + release + '.tar.gz',
                                      source_release_dir)

env.Alias ('srcdist', source_release_tarball)

env.AddPostAction (source_release_tarball, Delete (source_release_dir))

#-----------------------------------------------------------------------------
# package a source snapshot tarball
#-----------------------------------------------------------------------------

import time

snap_date = time.strftime ("%Y.%m.%d")

snapshot_dir = env.Distribute ('lcdtest-' + snap_date, src_dist_files)

snapshot_tarball = env.Tarball ('lcdtest-' + snap_date + '.tar.gz',
                                snapshot_dir)

env.Alias ('srcsnap', snapshot_tarball)

env.AddPostAction (snapshot_tarball, Delete (snapshot_dir))

#-----------------------------------------------------------------------------
# Installation paths
#-----------------------------------------------------------------------------

if not env ['bindir']:
	env ['bindir'] = env ['prefix'] + '/bin'

if not env ['mandir']:
	env ['mandir'] = env ['prefix'] + '/man/man1'

#-----------------------------------------------------------------------------
# Prepare for SConscription
#-----------------------------------------------------------------------------

env.Append (SOURCE_RELEASE_DIR = source_release_dir)
env.Append (SNAPSHOT_DIR = snapshot_dir)

build_dir = 'build/'

#-----------------------------------------------------------------------------
# code
#-----------------------------------------------------------------------------

SConscript ('src/SConscript',
            build_dir = build_dir,
            duplicate = 0,
	    exports = {'env' : env})

#-----------------------------------------------------------------------------
# man page
#-----------------------------------------------------------------------------

SConscript ('man/SConscript')

#-----------------------------------------------------------------------------
# scons directory, which contains various scons builders we use, and the
# scons-local tarball for those that don't want to install SCons
#-----------------------------------------------------------------------------

SConscript ('scons/SConscript')
