# SConscript file for Public_Library

import os
import re

Import('env Automatic_Circular_DLLs Automatic_Library Automatic_Global_Library')
env=env.Copy()

ignore=["build","install","Documentation"]
exclude=[]
directories=['Ray_Tracing', 'OpenGL', 'Dynamics', 'Fluids', 'Compressible', 'Incompressible', 'Solids', 'Hybrid_Methods', 'Deformables', 'Rigids', 'Geometry', 'Grid_PDE', 'Grid_Tools', 'Tools', 'Core']

if env['install_headers'] and env['INSTALL_PATH']:
    install_include=os.path.join(env['INSTALL_PATH'],'include','physbam','')
    for d in directories:
        for h in os.listdir(Dir(d).srcnode().abspath):
            if h.endswith('.h'):
                env.Depends(d,env.Install(install_include+d,os.path.join(d,h)))

def Sublibrary(env,name,directories,parent=None):
    lib=Automatic_Library(env,'PhysBAM_'+name,directories,ignore=ignore)
    if parent: env.Depends(parent,lib)
    return lib

for d in ['Ray_Tracing', 'OpenGL', 'Solids', 'Hybrid_Methods', 'Deformables', 'Rigids', 'Geometry', 'Grid_PDE', 'Grid_Tools', 'Tools', 'Core']:
    Sublibrary(env,d,[d],parent=d)

Sublibrary(env,'Dynamics',['Dynamics', 'Fluids', 'Compressible', 'Incompressible'],parent='.')

if env["PLATFORM"].startswith("win32"):
    exclude_regex=re.compile("OpenGL|Ray_Tracing|CVS")
    Automatic_Circular_DLLs(env,filter(lambda x:not exclude_regex.search(x),directories))
else:
    if env["INSTALL_PATH"]:
        env_with_gl=env.Copy(USE_OPENGL=1)
        lib=Automatic_Global_Library(env_with_gl,"PhysBAM",map(lambda x:"PhysBAM_"+x,directories))
        env.Depends('.',env_with_gl.Install(os.path.join(env["INSTALL_PATH"],"lib"),lib))
