from __future__ import division, print_function, unicode_literals

import os

Import ('env')

# math libs
mlib = env['RAD_MLIB']

# compose paths
def rbin(name): return os.path.join(env['RAD_BUILDBIN'], name)

trans = env.Object(source="trans.c")
bsdfrep = env.Object(source="bsdfrep.c")
bsdfinterp = env.Object(source="bsdfinterp.c")

# standard targets
PROGS = [
('3ds2mgf', Split('3ds2mgf.c rayopt3ds.c vect3ds.c'), ['mgf','rtrad'] + mlib),
('ies2rad',   ['ies2rad.c'],       ['rtrad'] + mlib),
#('arch2rad',  ['arch2rad.c',trans],['rtrad'] + mlib),
('nff2rad',   ['nff2rad.c'],       []),
('lampcolor', ['lampcolor.c'],     ['rtrad'] ),
('tmesh2rad', ['tmesh2rad.c'],     ['rtrad']  + mlib),
('obj2rad',   ['obj2rad.c',trans], ['rtrad']  + mlib),
('mgf2rad',   ['mgf2rad.c'],       ['mgf','rtrad']  + mlib),
('rad2mgf',   ['rad2mgf.c'],       ['rtrad'] + mlib),
('mgfilt',    ['mgfilt.c'],        ['mgf','rtrad'] + mlib),
('mgf2inv',   ['mgf2inv.c'],       ['mgf','rtrad'] + mlib),
('pabopto2bsdf', 
	['pabopto2bsdf.c',bsdfrep,'bsdfrbf.c', 'bsdfmesh.c', 'bsdftrans.cpp',], 
	['rtrad'] + mlib),
('bsdf2klems',['bsdf2klems.c', bsdfrep, bsdfinterp,], ['rtrad'] + mlib),
('bsdf2ttree',['bsdf2ttree.c', bsdfrep, bsdfinterp,], ['rtrad'] + mlib),
('pkgBSDF',   ['pkgBSDF.c', ], ['rtrad'] + mlib),
('epw2wea',   ['epw2wea.c', ], ['rtrad'] + mlib),
('mgf2meta',  ['mgf2meta.c'],  ['meta', 'mgf','rtrad'] + mlib,
	[os.path.join('#src','meta')]),
]
for p in PROGS:
	if len(p) == 4: inclp = env.get('CPPPATH', []) + [os.path.join('#src','meta')],
	else: inclp = env.get('CPPPATH', [])
	prog = env.Program(target=rbin(p[0]), source=p[1], LIBS=p[2], CPPPATH=inclp)
	Default(prog)
	env.Append(RAD_BININSTALL=[env.Install(env['RAD_BINDIR'], prog)])

LIBFILES = Split('bsdf2rad.cal source.cal tilt.cal window.cal')
env.Append(RAD_RLIBINSTALL=env.Install(env['RAD_RLIBDIR'], LIBFILES))

if os.name == 'posix':
	for s in Split('''optics2rad'''):
		Default(env.InstallScript(rbin(s), s + '.csh'))

# vim: set syntax=python:
# vi: set ts=4 sw=4 :
