Import('*')

#######################################
# ENVIRONMENT
#######################################
env = env.Copy();

env.Append(LIBS = [ 'z', 'm', 'jpeg', 'png', 'GL', 'GLU', 'gefetch' ]);
env.Append(CPPPATH = [ '../libgefetch' ]);
env.Append(LIBPATH = [ '../libgefetch' ]);
env.ParseConfig('sdl-config --cflags --libs');
env.ParseConfig('curl-config --cflags --libs');

if int(env['gpsd']):
	env.Append( LIBS = [ 'gps' ], CCFLAGS = [ '-DWITH_GPSD' ], CXXFLAGS = [ '-DWITH_GPSD' ] )

#######################################
# CHECKS
#######################################
if not env.GetOption('clean'):
	config = env.Configure(log_file = '/dev/null')
	config_ok = True
   
	if not config.CheckHeader('SDL.h'):
		print "You need to install the SDL development libraries"
		config_ok = False

	if not config.CheckHeader( [ 'stdio.h', 'jpeglib.h' ] ):
		print "You need to install the jpeg development libraries"
		config_ok = False

	if not config.CheckHeader( [ 'GL/gl.h' ] ):
		print "You need to install the GL development libraries"
		config_ok = False

	if not config.CheckHeader('png.h'):
		print "You need to install the png development libraries"
		config_ok = False

	if not config.CheckHeader('curl/curl.h'):
		print "You need to install the curl development libraries"
		config_ok = False

	if int(env['gpsd']) and not config.CheckHeader('gps.h'):
		print "You need to install libgps from gpsd package (http://gpsd.berlios.de/), or use turn off gpsd support with `gpsd=0' option (you'll still be able to use GPS)"
		config_ok = False

	if not config_ok:
		Exit(1)

#######################################
# TARGETS
#######################################
srcs = Split("""main.cc
		Viewpoint.cc
		Timer.cc
		RawBuffer.cc
		EarthView.cc
		FlatEarthView.cc
		SphereEarthView.cc
		MasterLayer.cc
		TestMasterLayer.cc
		GoogleLayer.cc
		SlaveLayer.cc
		TestSlaveLayer.cc
		GridLayer.cc
		GPSLayer.cc
		Texture.cc
		SimpleTileStorage.cc
		KeyholeConnection.cc
		FilesystemStorage.cc
		TileManager.cc
		Tile.cc
		TextureTile.cc
		PreloadedTextureManager.cc
		global.cc
		glutil.cc
		GPSSourceNMEA.cc
		GPSSourceTest.cc
		Hud.cc
		HudObject.cc
		HudIcon.cc""")

if int(env['gpsd']):
	srcs += ['GPSSourceGPSD.cc']

env.Program('../gaia', [libgefetch, srcs])
