# SConstruct for Altogether
# $Id: SConstruct 419 2004-06-15 07:38:44Z eric $
# Copyright 2004, 2005, 2007 Eric L. Smith <eric@brouhaha.com>

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

# Altogether is distributed in the hope that it 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 = '0.12'  # should get from a file, and use only if a release option
                  # is specified

#-----------------------------------------------------------------------------
# Conditionals 
#-----------------------------------------------------------------------------

opts = Options ()

opts.AddOptions (EnumOption ('target',
                             help = 'execution target',
                             allowed_values = ('posix', 'win32'),
                             default = 'posix',
                             ignorecase = 1),

                 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)',
		  ''),

		 ('libdir',
		  'path for library files (default is $prefix/lib/nonpareil)',
		  ''),

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

                 BoolOption ('debug',
                             help = 'compile for debugging',
                             default = 1))

opts.AddOptions (BoolOption ('use_readline',
                             help = 'use_readline',
                             default = 1),
                 BoolOption ('use_tcl',
                             help = 'use_tcl',
                             default = 1),
                 BoolOption ('use_gui',
                             help = 'use_gui',
                             default = 1),
                 BoolOption ('use_benchmark',
                             help = 'use_benchmark',
                             default = 1))

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

conf_file = 'altogether.conf'

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
#-----------------------------------------------------------------------------

# Don't scatter .sconsign files everywhere, and especially don't put them
# into install directories.
SConsignFile ()

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

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

SConscript ('scons/tarball.py')
SConscript ('scons/zip-flat.py')
# SConscript ('scons/nsis.py')

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

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

src_dist_files = Split ("""TODO SConstruct""")

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

source_release_tarball = env.Tarball ('altogether-' + 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 ('altogether-' + snap_date, src_dist_files)

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

env.Alias ('srcsnap', snapshot_tarball)

env.AddPostAction (snapshot_tarball, Delete (snapshot_dir))

#-----------------------------------------------------------------------------
# package a Windows binary distribution ZIP file
#-----------------------------------------------------------------------------

if env ['target'] == 'win32':
    win32_bin_dist_dir = Dir ('altogether-' + release + '-win32')
    Export ('win32_bin_dist_dir')
    Install (win32_bin_dist_dir, bin_dist_files)
    win32_bin_dist_zip = Zip ('altogether-' + release + '-win32.zip', win32_bin_dist_dir)
    env.Alias ('dist', win32_bin_dist_zip)
    env.AddPostAction (win32_bin_dist_zip, Delete (win32_bin_dist_dir.path))

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

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

if not env ['libdir']:
	env ['libdir'] = env ['prefix'] + '/lib/altogether'

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

Export ('source_release_dir snapshot_dir')

host_build_dir = 'build/' + env ['PLATFORM']
target_build_dir = 'build/' + env ['target']

if env ['debug']:
	host_build_dir += '-debug'
	target_build_dir += '-debug'

#-----------------------------------------------------------------------------
# host platform code
#-----------------------------------------------------------------------------

native_env = env.Copy ()
native_env ['build_target_only'] = 0
SConscript ('src/SConscript',
            build_dir = host_build_dir,
            duplicate = 0,
	    exports = {'build_env' : native_env,
		       'native_env' : env})

#-----------------------------------------------------------------------------
# target platform code if cross-compiling
#-----------------------------------------------------------------------------

if (env ['PLATFORM'] != env ['target']):
	cross_build_env = env.Copy ()
	cross_build_env ['build_target_only'] = 1
	SConscript ('src/SConscript',
		    build_dir = target_build_dir,
		    duplicate = 0,
		    exports = {'build_env': cross_build_env,
			       'native_env' : env})

#-----------------------------------------------------------------------------
# microcode
#-----------------------------------------------------------------------------

SConscript ('prom/AltoIIXM/SConscript')
SConscript ('scons/SConscript')
