rewritten entirely

This commit is contained in:
James Turk 2005-05-14 02:16:42 +00:00
parent adfbce47a9
commit d30015b757

View File

@ -5,108 +5,73 @@
# James Turk (jpt2433@rit.edu) # James Turk (jpt2433@rit.edu)
# #
# Version: # Version:
# $Id: SConstruct,v 1.7 2005/04/21 19:30:19 cozman Exp $ # $Id: SConstruct,v 1.8 2005/05/14 02:16:42 cozman Exp $
import os,os.path import os,os.path
import glob import glob
import string
def buildSuperHeader(self):
def combine(prefix, dirs): header = file('include/'+LIBRARY+'.hpp','w')
"""Add a common prefix to all directories""" incGuard = string.upper(LIBRARY)+'_HPP'
return [os.path.join(prefix,d) for d in dirs] header.write('#ifndef '+incGuard+'\n')
header.write('#define '+incGuard+'\n\n')
def getFiles(path, pat): for inc in INC_FILES:
"""Get all files which match a glob in a directory""" header.write('#include "'+inc+'"\n')
return glob.glob( os.path.join(path,pat) ) header.write('\n#endif // '+incGuard+'\n')
def getFilesMulti(paths, pat): def getFilesMulti(paths, pat):
"""Get all files which match a glob in a set of directories""" """Get all files which match a glob in a set of directories"""
filelist = [] filelist = []
for d in paths: for d in paths:
filelist += getFiles(d, pat) filelist += glob.glob( os.path.join(d,pat) )
return filelist return filelist
def getFilesRecursive(path, pat): ## config variables ##
files = glob.glob( os.path.join(path,pat) ) LIBRARY = 'photon'
for item in os.walk(path): SUB_DIRS = ['', 'audio', 'math', 'util', 'util/filesys', 'video']
basePath = item[0] SRC_DIRS = ["src/%s" % d for d in SUB_DIRS]
for subdir in item[1]: INC_DIRS = ["include/%s" % d for d in SUB_DIRS]
files += glob.glob( os.path.join(basePath,subdir,pat) ) SRC_FILES = [f.replace('src','build') for f in getFilesMulti(SRC_DIRS, '*.cpp')]
return [modf.replace(path+os.sep, '').replace(os.sep,'/') for modf in files] INC_FILES = getFilesMulti(INC_DIRS, '*.hpp')
class Builder: libsMap = {
def __init__(self): 'nt':('opengl32','glu32','openal32'),
self.libName = 'photon' 'posix':('GL','GLU','openal'),
self.subDirs = ['', 'audio', 'math', 'util', 'util/filesys', 'video'] 'mac':('GL','GLU','openal') }
self.srcDirs = combine('src',self.subDirs) try:
self.incDirs = combine('include',self.subDirs) OGL_LIB,GLU_LIB,OAL_LIB = libsMap[os.name]
self.srcFiles = getFilesMulti(self.srcDirs, '*.cpp') except KeyError:
self.srcFiles = [f.replace('src','build') for f in self.srcFiles] print """Building on this platform (' + os.name + ') is not
self.incFiles = getFilesMulti(self.srcDirs, '*.hpp') supported. Contact James (jpt2433@rit.edu) to check on
support."""
def checkLibrary(self, name, lib, header):
"""Check if a library/header pair exists, report and bail if not"""
if not self.conf.CheckLibWithHeader(lib, header, 'C++'):
print name,'not found, exiting.'
Exit(1) Exit(1)
def checkDepends(self): # Configure the environment (Check libraries):
"""Check all the dependencies for the current project""" env = Environment(ENV = os.environ)
self.env = Environment(ENV = os.environ, conf = Configure(env)
LIBPATH=['/usr/lib', '/usr/local/lib'], if not conf.CheckLibWithHeader(OAL_LIB, 'AL/al.h', 'C++'):
INCPATH=['/usr/include', '/usr/local/include']) print 'OpenAL not found, exiting.'
self.conf = Configure(self.env) Exit(1)
self.checkLibrary('OpenAL','openal','AL/al.h') if not conf.CheckLibWithHeader(OGL_LIB, 'GL/gl.h', 'C++'):
self.checkLibrary('OpenGL','GL','GL/gl.h') print 'OpenGL not found, exiting.'
self.checkLibrary('GLFW','glfw','GL/glfw.h') Exit(1)
self.env = self.conf.Finish() if not conf.CheckLibWithHeader(GLU_LIB, 'GL/glu.h', 'C++'):
print 'GLU not found, exiting.'
Exit(1)
if not conf.CheckLibWithHeader('glfw', 'GL/glfw.h', 'C++'):
print 'GLFW not found, exiting.'
Exit(1)
env = conf.Finish()
def namedBuild(self, name, target, buildType, default=False, **extra): # Define Builds:
"""Add a build target which can be addressed by name on the command line BuildDir('build', 'src', duplicate=0)
name - Name to give to the target (using Alias)
target - Actual build target
buildType - string describing what is being built (eg. Library, PDF)
[default - whether or not target is built by default (False)]
**extra - any options which should be given to the builder
(eg. source='foo.c', CPPPATH='/foo/bar/baz')
"""
# create a string with the desired buildType
regStr = "self.env."+buildType+"(target = target, **extra)"
# alias the build to the given name
reg = self.env.Alias(name, eval(regStr))
if default:
self.env.Default(reg)
return reg
def buildSuperHeader(self): lib = env.Library(os.path.join('lib',LIBRARY), source=SRC_FILES,
header = file('include/'+self.libName+'.hpp','w') CPPPATH = 'include', CPPFLAGS = '-Wall -pedantic -O3')
incGuard = string.upper(self.libName)+'_HPP' env.Alias(LIBRARY,lib)
header.write('#ifndef '+incGuard+'\n') env.Default(LIBRARY)
header.write('#define '+incGuard+'\n\n')
for inc in getFilesRecursive('./include','*.hpp'):
header.write('#include "'+inc+'"\n')
header.write('\n#endif // '+incGuard+'\n')
def build(self): ndoc = env.Command('docs/index.html', './include',
BuildDir('build', 'src', duplicate=0)
self.checkDepends()
self.namedBuild('photon', os.path.join('lib',self.libName), 'Library',
default=True,
source = self.srcFiles, CPPPATH = 'include',
CPPFLAGS = '-Wall -pedantic -pg')
self.namedBuild('test00', 'test00', 'Program', default=False,
source = 'test00.cpp', CPPPATH = self.incDirs,
LIBPATH='./lib',
LIBS=['photon','openal32','glfw','opengl32','glu32','physfs'],
CPPFLAGS = '-Wall -pedantic -pg', LINKFLAGS='-pg')
self.buildSuperHeader()
ndoc = self.env.Command('docs/index.html', './include',
"""NaturalDocs -nag -i $SOURCES -o HTML ./docs -p ./ndoc""") """NaturalDocs -nag -i $SOURCES -o HTML ./docs -p ./ndoc""")
#self.env.Alias("docs",ndoc) env.Alias("docs",ndoc)
self.env.AlwaysBuild('docs/index.html')
b = Builder()
b.build()