global_cflags = ARGUMENTS.get('CFLAGS', '-Wall -Wextra -O2 -fomit-frame-pointer')
global_cxxflags = ARGUMENTS.get('CXXFLAGS', global_cflags + ' -fno-exceptions -fno-rtti')
global_defines = ' -DHAVE_STDINT_H'
vars = Variables()
vars.Add('CC')
vars.Add('CXX')

env = Environment(CPPPATH = ['src', 'include', '../common'],
                  CFLAGS = global_cflags + global_defines,
                  CXXFLAGS = global_cxxflags + global_defines,
                  variables = vars)

sourceFiles = Split('''
			src/bitmap_font.cpp
			src/cpu.cpp
			src/gambatte.cpp
			src/initstate.cpp
			src/interrupter.cpp
			src/interruptrequester.cpp
			src/loadres.cpp
			src/memory.cpp
			src/sound.cpp
			src/state_osd_elements.cpp
			src/statesaver.cpp
			src/tima.cpp
			src/video.cpp
			src/mem/cartridge.cpp
			src/mem/memptrs.cpp
			src/mem/pakinfo.cpp
			src/mem/rtc.cpp
			src/sound/channel1.cpp
			src/sound/channel2.cpp
			src/sound/channel3.cpp
			src/sound/channel4.cpp
			src/sound/duty_unit.cpp
			src/sound/envelope_unit.cpp
			src/sound/length_counter.cpp
			src/video/ly_counter.cpp
			src/video/lyc_irq.cpp
			src/video/next_m0_time.cpp
			src/video/ppu.cpp
			src/video/sprite_mapper.cpp
		   ''')

conf = env.Configure()

if conf.CheckHeader('zlib.h'):
	sourceFiles.append('src/file/unzip/unzip.c')
	sourceFiles.append('src/file/unzip/ioapi.c')
	sourceFiles.append('src/file/file_zip.cpp')
else:
	sourceFiles.append('src/file/file.cpp')

conf.Finish()

env.Library('gambatte', sourceFiles)
