#! /usr/bin/env python
import os
from waflib.Configure import conf
import traceback

CURRENT_MODULE_DIR = "/modules/fastsim2"

def options(opt):
    opt.load('sdl', tooldir=os.getcwd() + CURRENT_MODULE_DIR)

# def detect_sdl(conf):
#     env = conf.env
#     opt = Options.options
#     ret = conf.find_program('sdl-config')
#     conf.check_message_1('Checking for SDL (optional)')
#     if not ret:
#         conf.check_message_2('not found', 'YELLOW')
#         return 0
#     conf.check_message_2('ok')
#     res = commands.getoutput('sdl-config --cflags --libs')
#     config_c.parse_flags(res, 'SDL', env)
#     return 1

# def detect(conf):
#     return detect_sdl(conf)

def configure(conf):
    try:
        conf.check_sdl()
    except:
        traceback.print_exc()
#    conf.env['CPPPATH_SDL'] = commands.getoutput('sdl-config --cflags')
#    conf.env['LIBPATH_SDL'] = commands.getoutput('sdl-config --libs')
    


def build(bld):
    bld.stlib(features = 'cxx cxxstlib',
              source = 'door.cpp display.cpp laser.cpp map.cpp radar.cpp light_sensor.cpp ' + \
                  'robot.cpp linear_camera.cpp tile_sensor.cpp',
              includes = '',
              target = 'fastsim',
              uselib = 'SDL BOOST PTHREAD')

    #test_fastsim = bld.new_task_gen('cxx', 'program')
    #test_fastsim.source = 'test_fastsim.cpp'
    #test_fastsim.includes = '. ../../'
    #test_fastsim.uselib_local = 'sferes2 fastsim'
    #if Options.options.apple:
    #    test_fastsim.uselib = 'SDL'
    #else:
    #    test_fastsim.uselib = 'BOOST_UNIT_TEST_FRAMEWORK SDL'
    #    test_fastsim.unit_test = 1

    #test_fastsim.target = 'test_fastsim'

    if bld.env['SDL_FOUND']:
        bld.program(features = 'cxx',
                source = 'example.cpp',
                includes = '. ../..',
                use = 'sferes2 fastsim',
                uselib = 'SDL BOOST PTHREAD',   
                target = 'example')




