import os, SCons

# import variables
try:
	Import('install_dir')
except SCons.Errors.UserError:
	# Install directory
	root = ARGUMENTS.get('root', '/')
	prefix = ARGUMENTS.get('prefix', 'usr/local')
	if root != '' and prefix != '': # not defaults
		if prefix[0] == '/':
			prefix = prefix[1:]
	install_dir = os.path.join(root, prefix, 'share/globs/benchmarks')

# create build environment
env = Environment()

# determine compiler and linker flags for SDL
env.ParseConfig('sdl-config --cflags')
env.ParseConfig('sdl-config --libs')

# check for libraries and headers (if not cleaning)
if not env.GetOption('clean'):
	print ":: Checking for libs"
	conf = Configure(env)
	if not conf.CheckLibWithHeader('libSDL', 'SDL.h', 'c', 'SDL_Init(SDL_INIT_VIDEO);', autoadd=0):
		print 'Did not find libSDL, exiting!'
		Exit(1)
	if not conf.CheckLibWithHeader('libSDL_image', 'SDL_image.h', 'c', 'IMG_GetError();'):
		print 'Did not find libSDL_image, exiting!'
		Exit(1)
	if not conf.CheckLibWithHeader('libGL', 'GL/gl.h', 'c', 'glLoadIdentity();'):
		print 'Did not find libGL, exiting!'
		Exit(1)
	env = conf.Finish()


# print building message
if not env.GetOption('clean'):
	print ":: Compiling benchmarks for posix"


# run sub scripts
Export('env', 'install_dir')
# benchmarks
dirs = ('Fake', 'GL_smoke', 'GL_pointz', 'GL_shadow', 'GL_blit', 'GLSL_parallax')

for x in dirs:
    SConscript(x + '/SConscript')
