1# Copyright (c) 2016-2019 Michael Scholz <mi-scholz@users.sourceforge.net> 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions 6# are met: 7# 1. Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# 2. Redistributions in binary form must reproduce the above copyright 10# notice, this list of conditions and the following disclaimer in the 11# documentation and/or other materials provided with the distribution. 12# 13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23# SUCH DAMAGE. 24# 25# @(#)SConscript 1.12 11/18/19 26 27import os 28 29Import('env') 30 31prefix = env['prefix'] 32shared = env['shared'] 33warnings = env['warnings'] 34verbose = env['verbose'] 35missing = env['missing'] 36dbm = env['dbm'] 37dbm_lib = env['dbm_lib'] 38build_dir = env['build'] 39top_srcdir = env['top_srcdir'] 40prog = env['NAME'] 41top_dir = Dir('.').path 42obj_dir = top_dir + '/src' 43so_lib = 'src/libfth' 44pg_fth = 'src/fth' 45sources = [] 46sources.extend(Glob('ficl/*.c')) 47sources.extend(missing) 48sources.extend(Glob('src/*.c', exclude = ['src/fth.c', 'src/misc.c'])) 49env.MergeFlags(['-g', '-O3']) 50 51# We don't use warnings (CFLAGS) for mp*.c sources. 52mp_env = env.Clone() 53 54if warnings: 55 env.Append(CFLAGS = [ 56 '-ansi', 57 '-std=c99', # otherwise va_copy() is hidden 58 '-Wall', 59 '-Wextra', 60 '-Wmissing-declarations', 61 '-Wmissing-prototypes', 62 '-Wundef', 63 '-Wunused']) 64 65env['CPPDEFINES'] = ['HAVE_CONFIG_H'] 66 67misc_env = env.Clone(CPPDEFINES = ['HAVE_CONFIG_H', 68 'FTH_PREFIX_PATH=\\"' + prefix + '\\"', 69 'FTH_PROG_NAME=\\"' + prog + '\\"']) 70 71if shared: 72 ms = misc_env.SharedObject('src/misc.c') 73 mp = mp_env.SharedObject(['lib/mp.c', 'lib/mpi.c', 'lib/mpr.c']) 74 so = env.SharedLibrary(so_lib, [sources, ms, mp]) 75 po = env.SharedObject('src/fth.c') 76 pg = env.Clone(LIBS = [prog, 'm']).Program(pg_fth, [po]) 77else: 78 ms = misc_env.StaticObject('src/misc.c') 79 mp = mp_env.StaticObject(['lib/mp.c', 'lib/mpi.c', 'lib/mpr.c']) 80 so = env.StaticLibrary(so_lib, [sources, ms, mp]) 81 po = env.StaticObject('src/fth.c') 82 pg = env.Program(pg_fth, [po, so]) 83 84if dbm: 85 ext_env = env.Clone(LIBS = [dbm_lib, 'm']) 86 od = ext_env.SharedObject('examples/dbm/fth-dbm.c') 87 el = ext_env.SharedLibrary('fth-dbm', od) 88 89# 90# substitutions 91# 92conf_input = "Generated by scons." 93subst_dict = { 94 '@prefix@' : prefix, 95 '@prog_name@' : prog, 96 '@configure_input@' : conf_input, 97 '@abs_top_builddir@' : top_dir, 98 '@top_srcdir@' : top_srcdir, 99 '@abs_top_srcdir@' : top_srcdir } 100fth_sh = top_srcdir + '/fth.sh' 101fth_test = top_srcdir + '/examples/scripts/fth-test.fth' 102install = top_srcdir + '/examples/scripts/install.fth' 103play_sound = top_srcdir + '/examples/scripts/play-sound.fth' 104xm = top_srcdir + '/examples/scripts/xm.fth' 105fs = [] 106se = Environment(tools = ['textfile']) 107for s in [fth_sh, fth_test, install, play_sound, xm]: 108 t = se.Substfile(s + '.in', SUBST_DICT = subst_dict) 109 # python3.7 isn't able to scan 0755 as octal number 110 # 0755 octal == 493 decimal. 111 fs.extend(Command(None, s, Chmod(s, 493))) 112 113# 114# install 115# uninstall 116# 117inst = [] 118bindir = prefix + '/bin' 119libdir = prefix + '/lib' 120pkglibdir = libdir + '/' + prog 121incdir = prefix + '/include/' + prog 122datadir = prefix + '/share/' + prog 123flibdir = datadir + '/fth-lib' 124fsitedir = datadir + '/site-fth' 125mandir = prefix + '/man' 126man1dir = mandir + '/man1' 127man3dir = mandir + '/man3' 128cat1dir = mandir + '/cat1' 129cat3dir = mandir + '/cat3' 130 131if shared: 132 iso = env.InstallAs(libdir + '/lib' + prog + '.so', so) 133 if dbm: 134 inst.extend(env.InstallAs(pkglibdir + '/dbm.so', el)) 135else: 136 iso = env.InstallAs(libdir + '/lib' + prog + '.a', so) 137 138env.Depends(pg, iso) 139env.NoClean(iso) 140 141inst.extend(env.InstallAs(bindir + '/' + prog, pg)) 142inst.extend(iso) 143 144inst.extend(env.Install(incdir, [ 145 'ficl/ficl.h', 146 'ficl/ficllocal.h', 147 'ficl/ficltokens.h', 148 'lib/mp.h', 149 'fth-config.h', 150 'src/fth-lib.h', 151 'src/fth.h'])) 152inst.extend(env.Install(flibdir, Glob('examples/fth-lib/*.f[rs]'))) 153inst.extend(env.Install(fsitedir, Glob('examples/site-lib/*.fs*'))) 154inst.extend(env.Install(man1dir, 'fth.1')) 155inst.extend(env.Install(man3dir, 'libfth.3')) 156if os.path.exists(cat1dir): 157 inst.extend(env.Install(cat1dir, 'fth.0')) 158if os.path.exists(cat3dir): 159 inst.extend(env.Install(cat3dir, 'libfth.0')) 160env.Alias('install', inst) 161env.Alias('uninstall', env.Command(None, 'README.man', Delete(Flatten(inst)))) 162env.Default(pg, fs) 163 164# 165# test 166# clean 167# 168fsargs = ' -qs ' 169if verbose: 170 fsargs = ' -vs ' 171 172env.Alias('test', env.Command('test', [pg, fs], fth_sh + fsargs + fth_test)) 173# scons -c removes these extra files 174Clean('clean', fs) 175 176# SConscript ends here 177