import os

Import("baseEnvironment")

env = baseEnvironment.Clone()
env.Append(CPPPATH = ["src"])
env.Append(CPPDEFINES = ["BUILDING_WENDY"])
if env["CC"] == "cl":
	env.Append(CPPFLAGS = ["/Z7", "/W2", "/wd4251", "/EHsc"])
else:
	env.Append(CPPFLAGS = ["-g", "-Wall"])

if os.name == "nt":
	env.Append(CPPPATH = ["$BINARYDEPS/curl/include"])
	env.Append(LIBPATH = ["$BINARYDEPS/curl/lib"])
	env.Append(CPPPATH = ["$BINARYDEPS/cJSON"])
	env.Append(LIBPATH = ["$BINARYDEPS/cJSON"])
	env.Append(CPPDEFINES = ["UNICODE", "_UNICODE"])
	env.Append(LIBS = ["ws2_32"])

if os.name == "posix":
	env.Append(LIBS = ["pthread"])

env.Append(LIBS = ["curl", "cJSON"])
libNode = env.SharedLibrary("lib/wendy", env.Glob("src/wendy/*.cpp"))

if os.name == "nt":
	env.Command("bin/tests/wendy.dll", libNode, Copy("$TARGET", "$SOURCE"))
	env.Command("bin/tests/libcurl.dll", "$BINARYDEPS/curl/lib/libcurl.dll", Copy("$TARGET", "$SOURCE"))
	env.Command("bin/tests/libcJSON.dll", "$BINARYDEPS/cjson/libcJSON.dll", Copy("$TARGET", "$SOURCE"))

testEnv = baseEnvironment.Clone()
testEnv.Append(CPPPATH = ["src"])
testEnv.Append(LIBPATH = ["lib"])
testEnv.Append(LIBS = ["wendy"])
if testEnv["CC"] == "cl":
	testEnv.Append(CPPFLAGS = ["/EHsc", "/Z7"])
testEnv.Program("bin/tests/client", "tests/client.cpp")
testEnv.Program("bin/tests/http", "tests/http.cpp")

distItems = [
	("${SHLIBPREFIX}wendy${SHLIBSUFFIX}", libNode)
]
Return("distItems")

