Import('env', 'sys')

libhw_objects = [
	'session.cpp', 'device.cpp', 'gputexture.cpp', 'gpugeometry.cpp', 
	'gpuprogram.cpp', 'renderer.cpp', 'glrenderer.cpp', 'glprogram.cpp', 
	'glgeometry.cpp', 'gltexture.cpp', 'gpusync.cpp', 'glsync.cpp',
	'vpl.cpp', 'font.cpp', 'viewer.cpp', 'gizmo.cpp']

if sys.platform == 'win32':
	libhw_objects += ['wglsession.cpp',
		'wgldevice.cpp',
		'wglrenderer.cpp']

elif sys.platform == 'linux2':
	libhw_objects += ['x11session.cpp',
		'x11device.cpp',
		'glxdevice.cpp', 
		'glxrenderer.cpp']

glEnv = env.Clone()
glEnv.Append(CPPDEFINES = [['MTS_BUILD_MODULE', 'MTS_MODULE_HW']] )
if glEnv.has_key('GLLIB'):
	glEnv.Prepend(LIBS=glEnv['GLLIB'])
if glEnv.has_key('GLLIBDIR'):
	glEnv.Prepend(LIBPATH=glEnv['GLLIBDIR'])
if glEnv.has_key('GLFLAGS'):
	glEnv.Prepend(CPPFLAGS=glEnv['GLFLAGS'])
if glEnv.has_key('GLINCLUDE'):
	glEnv.Prepend(CPPPATH=glEnv['GLINCLUDE'])

if sys.platform == 'darwin':
	glEnv_osx = glEnv.Clone()
	glEnv_osx['CXXFLAGS'].remove('-fstrict-aliasing')
	glEnv_osx['CXXFLAGS'].remove('-ftree-vectorize')
	glEnv_osx['CXXFLAGS'].append('-fno-strict-aliasing')
	libhw_objects += glEnv_osx.SharedObject(['nsglsession.mm',
		'nsgldevice.mm', 'nsglrenderer.mm'])

libhw = glEnv.SharedLibrary('mitsuba-hw', libhw_objects)
if sys.platform == "darwin":
	glEnv.AddPostAction(libhw, 'install_name_tool -id @executable_path/../Frameworks/libmitsuba-hw.dylib $TARGET')

env.Append(LIBS=['mitsuba-hw'])
env.Append(LIBPATH=['#src/libhw'])

