import os

Import('context')

context.addFiles('./', Split( """
allegro.c
blit.c
bmp.c
clip3d.c
clip3df.c
colblend.c
color.c
config.c
datafile.c
dataregi.c
display.c
digmid.c
dispsw.c
dither.c
drvlist.c
dtor.c
events.c
evtsrc.c
file.c
fli.c
flood.c
font.c
fontbios.c
fontbmp.c
fontdat.c
fontgrx.c
fonttxt.c
fsel.c
gfx.c
glyph.c
graphics.c
gsprite.c
gui.c
guiproc.c
inline.c
joynu.c
keybdnu.c
lbm.c
libc.c
lzss.c
math.c
math3d.c
memory.c
midi.c
mixer.c
modesel.c
mouse.c
pcx.c
poly3d.c
polygon.c
quantize.c
quat.c
readbmp.c
readfont.c
readsmp.c
rle.c
rotate.c
scene3d.c
sound.c
spline.c
stream.c
text.c
tga.c
unicode.c
vtable.c
vtable15.c
vtable16.c
vtable24.c
vtable32.c
vtable8.c
""" ));

context.addFiles('compat/', Split("""
coblit.c
cogfx.c
cojoy.c
cokeybd.c
cotimer.c
""" ));

context.addFiles('misc/', Split("""
vector.c
colconv.c
ccolconv.c
""" ));

if False:
	context.addFiles('c/', Split("""
	cblit16.c
	cblit24.c
	cblit32.c
	cblit8.c
	ccpu.c
	ccsprite.c
	cgfx15.c
	cgfx16.c
	cgfx24.c
	cgfx32.c
	cgfx8.c
	cmisc.c
	cscan15.c
	cscan16.c
	cscan24.c
	cscan32.c
	cscan8.c
	cspr15.c
	cspr16.c
	cspr24.c
	cspr32.c
	cspr8.c
	cstretch.c
	czscan15.c
	czscan16.c
	czscan24.c
	czscan32.c
	czscan8.c
	""" ));


def tools(env,appendDir,buildDir,libDir):
    tools = []
    env.BuildDir(buildDir + 'tools', 'tools', duplicate = 0)
    def addTool(name,files):
        tool = env.Program('tools/' + name, appendDir(buildDir + '/tools/', files))
        Alias(name, tool)
        tools.append(tool)
    addTool('colormap', [ 'colormap.c' ])
    addTool('dat2c', [ 'dat2c.c' ])
    addTool('exedat', [ 'exedat.c' ])
    addTool('pack', [ 'pack.c' ])
    addTool('rgbmap', [ 'rgbmap.c' ])
    addTool('textconv', [ 'textconv.c' ])

    ## datedit.c references obj/unix/plugins.h which isnt generated by
    ## scons right now so this part is being left out
    if True:
        aldatFiles = Split("""
            datedit.c
            plugins/datalpha.c
            plugins/datfli.c
            plugins/datfname.c
            plugins/datfont.c
            plugins/datgrab.c
            plugins/datgrid.c
            plugins/datimage.c
            plugins/datitype.c
            plugins/datmidi.c
            plugins/datpal.c
            plugins/datsamp.c
            plugins/datworms.c
        """);
	aldatEnv = env.Copy()
	aldatEnv.Append(CPPPATH = buildDir)
        libaldat = aldatEnv.StaticLibrary(libDir + '/aldat', appendDir(buildDir + '/tools/', aldatFiles))
        aldatEnv.Depends(buildDir + '/tools/datedit.o', 'tools/plugins/plugins.h')
        Alias('aldat', libaldat)
        tools.append(libaldat)
        datEnv = env.Copy()
        # datEnv.Append(LIBPATH = '.')
        datEnv.Prepend(LIBS = 'aldat')
        def addDatTool(name,files): 
            tool = datEnv.Program('tools/' + name, appendDir(buildDir + '/tools/', files))
            Alias(name, tool)
            tools.append(tool)
        addDatTool('dat', [ 'dat2s.c' ])
        addDatTool('dat2s', [ 'dat2s.c' ])
        addDatTool('grabber', [ 'grabber.c' ])
        addDatTool('pat2dat', [ 'pat2dat.c' ])
    
    Alias('tools', tools)
    return tools

def tests(env,appendDir,buildDir,libDir):
    tests = []
    env.BuildDir(buildDir + 'tests', 'tests', duplicate = 0)
    def addTest(name,files):
        test = env.Program('tests/' + name, appendDir(buildDir + '/tests/', files))
        Alias(name, test)
        tests.append(test)
    addTest('afinfo', [ 'afinfo.c' ])
    addTest('akaitest', [ 'akaitest.c' ])
    addTest('digitest', [ 'digitest.c' ])
    addTest('filetest', [ 'filetest.c' ])
    addTest('gfxinfo', [ 'gfxinfo.c' ])
    addTest('mathtest', [ 'mathtest.c' ])
    addTest('miditest', [ 'miditest.c' ])
    addTest('play', [ 'play.c' ])
    addTest('playfli', [ 'playfli.c' ])
    addTest('test', [ 'test.c' ])
    addTest('vesainfo', [ 'vesainfo.c' ])
    addTest('cpptest', [ 'cpptest.cpp' ])
    Alias('tests', tests)
    return tests

def examples(env,appendDir,buildDir,libDir):
    examples = []
    env.BuildDir(buildDir + 'examples', 'examples', duplicate = 0)
    ## Add an example
    ## name - filename of example and also the alias of the target
    ## files - list of files associated with the example
    def addExample(name, files):
        example = env.Program('examples/' + name, appendDir(buildDir + '/examples/', files))
        Alias(name, example)
        examples.append(example)

    addExample('ex12bit', [ 'ex12bit.c' ])
    addExample('ex3buf', [ 'ex3buf.c' ])
    addExample('ex3d', [ 'ex3d.c' ])
    addExample('exaccel', [ 'exaccel.c' ])
    addExample('exalpha', [ 'exalpha.c' ])
    addExample('exbitmap', [ 'exbitmap.c' ])
    addExample('exblend', [ 'exblend.c' ])
    addExample('excamera', [ 'excamera.c' ])
    addExample('excolmap', [ 'excolmap.c' ])
    addExample('exconfig', [ 'exconfig.c' ])
    addExample('excustom', [ 'excustom.c' ])
    addExample('exdata', [ 'exdata.c' ])
    addExample('exdbuf', [ 'exdbuf.c' ])
    addExample('exexedat', [ 'exexedat.c' ])
    addExample('exfixed', [ 'exfixed.c' ])
    addExample('exflame', [ 'exflame.c' ])
    addExample('exflip', [ 'exflip.c' ])
    addExample('exfont', [ 'exfont.c' ])
    addExample('exgui', [ 'exgui.c' ])
    addExample('exhello', [ 'exhello.c' ])
    addExample('exjoy', [ 'exjoy.c' ])
    addExample('exkeys', [ 'exkeys.c' ])
    addExample('exlights', [ 'exlights.c' ])
    addExample('exmem', [ 'exmem.c' ])
    addExample('exmidi', [ 'exmidi.c' ])
    addExample('exmouse', [ 'exmouse.c' ])
    addExample('expackf', [ 'expackf.c' ])
    addExample('expal', [ 'expal.c' ])
    addExample('expat', [ 'expat.c' ])
    addExample('exquat', [ 'exquat.c' ])
    addExample('exrgbhsv', [ 'exrgbhsv.c' ])
    addExample('exsample', [ 'exsample.c' ])
    addExample('exscale', [ 'exscale.c' ])
    addExample('exscn3d', [ 'exscn3d.c' ])
    addExample('exscroll', [ 'exscroll.c' ])
    addExample('exshade', [ 'exshade.c' ])
    addExample('exspline', [ 'exspline.c' ])
    addExample('exsprite', [ 'exsprite.c' ])
    addExample('exstars', [ 'exstars.c' ])
    addExample('exstream', [ 'exstream.c' ])
    addExample('exswitch', [ 'exswitch.c' ])
    addExample('exsyscur', [ 'exsyscur.c' ])
    addExample('extimer', [ 'extimer.c' ])
    addExample('extrans', [ 'extrans.c' ])
    addExample('extruec', [ 'extruec.c' ])
    addExample('exunicod', [ 'exunicod.c' ])
    addExample('exupdate', [ 'exupdate.c' ])
    addExample('exxfade', [ 'exxfade.c' ])
    addExample('exzbuf', [ 'exzbuf.c' ])
    addExample('exnewapi', [ 'exnewapi.c' ])

    Alias('examples', examples)
    return examples

context.addExtra(examples)
context.addExtra(tools)
context.addExtra(tests)
