PREBUILD_DIR=../3rdparty/prebuild/$(BUILD_TARGET)
CXXFLAGS+= -DVN_SDK_STATIC -Wall -O0 -ggdb -I../src/core/include -I../src/core/impl

ifneq (,$(filter  $(BUILD_TARGET), x86_64-linux))
LDFLAGS+=-lpthread -ldl -lrt -lasound -lz
endif

ifeq (mingw32,  $(findstring mingw32,$(BUILD_TARGET)))
# To avoid unresolved "WinMain": this was caused by SDL defining it's own main function in SDL_main.h.
# To prevent SDL define the main function an SDL_MAIN_HANDLED macro has to be defined before the SDL.h header is included
CXXFLAGS+= -DSDL_MAIN_HANDLED
LDFLAGS+= -static -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lwinpthread ../lib/$(BUILD_TARGET)/VNMediaClient.lib -lgdi32 -lgdiplus
else
LDFLAGS+= ../lib/$(BUILD_TARGET)/libVNMediaClient_static.a -L../3rdparty/prebuild/$(BUILD_TARGET)/libxml2/lib -lxml2
endif

ifneq (,$(filter  $(BUILD_TARGET), x86_64-linux))
LDFLAGS+=-lpthread -ldl -lrt -lasound -lz
endif

ifeq (iphoneos, $(findstring iphoneos,$(BUILD_TARGET)))
LDFLAGS+= -lstdc++ -lc++ -lz -lbz2 -lxml2 -framework CoreFoundation -framework CoreVideo
else
ifeq (darwin, $(findstring darwin,$(BUILD_TARGET)))
LDFLAGS+= -lz -lbz2 -lxml2 -framework CoreFoundation -framework VideoDecodeAcceleration -framework CoreVideo  -framework AVFoundation -framework CoreMedia -framework CoreData -framework CoreGraphics -framework VideoToolbox -framework Foundation -framework CoreAudio -framework AudioToolbox -framework ForceFeedback -framework IOKit -framework Cocoa -framework Carbon -framework Metal -framework CoreHaptics -framework GameController
endif
endif

# stupid android toolchains..
ifeq (android, $(findstring android,$(BUILD_TARGET)))
OLD_LDFLAGS:=$(LDFLAGS)
LDFLAGS=-L$(NDK_PATH)/sources/cxx-stl/gnu-libstdc++/libs/armeabi -lstdc++ $(OLD_LDFLAGS) -lstdc++ -lgcc
endif

ifeq (mingw32, $(findstring mingw32,$(BUILD_TARGET)))
EXE=.exe
endif

ifeq (mingw32, $(findstring mingw32,$(BUILD_TARGET)))
all: simple_play d3d_play sdl_play test_play #capture #login simple_retriever simple_retriever_c
else
all: simple_play sdl_play test_play #test_auth
endif

.cpp.o:
	$(CXX) -c $(CXXFLAGS) $<


simple_retriever: simple_retriever.o
	$(CXX) -o simple_retriever$(EXE) simple_retriever.o $(LDFLAGS)

simple_retriever_c: simple_retriever_c.o
	$(CXX) -o simple_retriever_c$(EXE) simple_retriever_c.o $(LDFLAGS)

login: login.o
	$(CXX) -o login$(EXE) login.o $(LDFLAGS)

login2: login2.o
	$(CXX) -o login2$(EXE) login2.o $(LDFLAGS)

test_auth: test_auth.o
	$(CXX) -o test_auth$(EXE) test_auth.o $(LDFLAGS)

simple_play: simple_play.o
	$(CXX) -o simple_play$(EXE) simple_play.o $(CXXFLAGS) $(LDFLAGS)

d3d_play: d3d_play.o
	$(CXX) -o d3d_play$(EXE) d3d_play.o $(LDFLAGS)

sdl_play: sdl_play.o
	$(CXX) -o sdl_play$(EXE) sdl_play.o $(CXXFLAGS) $(LDFLAGS)

test_play: test_play.o
	$(CXX) -o test_play$(EXE) test_play.o $(CXXFLAGS) $(LDFLAGS)

capture: capture.o
	$(CXX) -o capture$(EXE) capture.o $(LDFLAGS)

clean:
	rm -rf *.o  simple_play$(EXE) sdl_play$(EXE) test_play$(EXE) login$(EXE) simple_retriever_c$(EXE) simple_retriever$(EXE) capture$(EXE)
