#
# gstreamer Makefile
#
CC  = cl.exe
LIB = lib.exe

BASE_DIR = ../../..
GSTREAMER_LITE = gstreamer-lite
OBJBASE_DIR = $(BUILD_DIR)/obj/$(GSTREAMER_LITE)
SRCBASE_DIR = $(BASE_DIR)/$(GSTREAMER_LITE)

DIRLIST = gstreamer/gst/ \
          gstreamer/libs/gst/base/ \
          gstreamer/libs/gst/controller/ \
          gst-plugins-base/gst-libs/gst/app/ \
          gst-plugins-base/gst-libs/gst/audio/ \
          gst-plugins-base/gst-libs/gst/fft/ \
          gst-plugins-base/gst-libs/gst/interfaces/ \
          gst-plugins-base/gst-libs/gst/pbutils/ \
          gst-plugins-base/gst-libs/gst/riff/ \
          gst-plugins-base/gst-libs/gst/tag/

DEP_DIRS = $(BUILD_DIR) $(addprefix $(OBJBASE_DIR)/,$(DIRLIST))

C_SOURCES = gstreamer/gst/gst.c \
			gstreamer/gst/gstbin.c \
			gstreamer/gst/gstbuffer.c \
			gstreamer/gst/gstbufferlist.c \
			gstreamer/gst/gstbus.c \
			gstreamer/gst/gstcaps.c \
			gstreamer/gst/gstchildproxy.c \
			gstreamer/gst/gstclock.c \
			gstreamer/gst/gstdatetime.c \
			gstreamer/gst/gstdebugutils.c \
			gstreamer/gst/gstelement.c \
			gstreamer/gst/gstelementfactory.c \
			gstreamer/gst/gstenumtypes.c \
			gstreamer/gst/gsterror.c \
			gstreamer/gst/gstevent.c \
			gstreamer/gst/gstfilter.c \
			gstreamer/gst/gstformat.c \
			gstreamer/gst/gstghostpad.c \
			gstreamer/gst/gstindex.c \
			gstreamer/gst/gstindexfactory.c \
			gstreamer/gst/gstinfo.c \
			gstreamer/gst/gstinterface.c \
			gstreamer/gst/gstiterator.c \
			gstreamer/gst/gstmarshal.c \
			gstreamer/gst/gstmessage.c \
			gstreamer/gst/gstminiobject.c \
			gstreamer/gst/gstobject.c \
			gstreamer/gst/gstpad.c \
			gstreamer/gst/gstpadtemplate.c \
			gstreamer/gst/gstparamspecs.c \
			gstreamer/gst/gstparse.c \
			gstreamer/gst/gstpipeline.c \
			gstreamer/gst/gstplugin.c \
			gstreamer/gst/gstpluginfeature.c \
			gstreamer/gst/gstpluginloader.c \
			gstreamer/gst/gstpoll.c \
			gstreamer/gst/gstquark.c \
			gstreamer/gst/gstquery.c \
			gstreamer/gst/gstregistry.c \
			gstreamer/gst/gstregistrybinary.c \
			gstreamer/gst/gstregistrychunks.c \
			gstreamer/gst/gstsegment.c \
			gstreamer/gst/gststructure.c \
			gstreamer/gst/gstsystemclock.c \
			gstreamer/gst/gsttaglist.c \
			gstreamer/gst/gsttagsetter.c \
			gstreamer/gst/gsttask.c \
			gstreamer/gst/gsttaskpool.c \
			gstreamer/gst/gsttrace.c \
			gstreamer/gst/gsttypefind.c \
			gstreamer/gst/gsttypefindfactory.c \
			gstreamer/gst/gsturi.c \
			gstreamer/gst/gstutils.c \
			gstreamer/gst/gstvalue.c \
			gstreamer/libs/gst/base/gstadapter.c \
			gstreamer/libs/gst/base/gstbaseparse.c \
			gstreamer/libs/gst/base/gstbasesink.c \
			gstreamer/libs/gst/base/gstbasesrc.c \
			gstreamer/libs/gst/base/gstbasetransform.c \
			gstreamer/libs/gst/base/gstbytereader.c \
			gstreamer/libs/gst/base/gstcollectpads.c \
			gstreamer/libs/gst/base/gstpushsrc.c \
			gstreamer/libs/gst/base/gsttypefindhelper.c \
			gstreamer/libs/gst/controller/gstcontroller.c \
			gstreamer/libs/gst/controller/gstcontrolsource.c \
			gstreamer/libs/gst/controller/gsthelper.c \
			gstreamer/libs/gst/controller/gstinterpolation.c \
			gstreamer/libs/gst/controller/lib.c \
			gst-plugins-base/gst-libs/gst/app/gstappbuffer.c \
			gst-plugins-base/gst-libs/gst/app/gstappsink.c \
			gst-plugins-base/gst-libs/gst/audio/audio.c \
			gst-plugins-base/gst-libs/gst/audio/audio-enumtypes.c \
			gst-plugins-base/gst-libs/gst/audio/gstaudioclock.c \
			gst-plugins-base/gst-libs/gst/audio/gstaudiofilter.c \
			gst-plugins-base/gst-libs/gst/audio/gstaudiosink.c \
			gst-plugins-base/gst-libs/gst/audio/gstaudiosrc.c \
			gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosink.c \
			gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.c \
			gst-plugins-base/gst-libs/gst/audio/gstringbuffer.c \
			gst-plugins-base/gst-libs/gst/audio/mixerutils.c \
			gst-plugins-base/gst-libs/gst/audio/multichannel.c \
			gst-plugins-base/gst-libs/gst/fft/gstfft.c \
			gst-plugins-base/gst-libs/gst/fft/gstfftf32.c \
			gst-plugins-base/gst-libs/gst/fft/gstfftf64.c \
			gst-plugins-base/gst-libs/gst/fft/gstffts16.c \
			gst-plugins-base/gst-libs/gst/fft/gstffts32.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fft_f32.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fft_f64.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fft_s16.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fft_s32.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fftr_f32.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fftr_f64.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fftr_s16.c \
			gst-plugins-base/gst-libs/gst/fft/kiss_fftr_s32.c \
			gst-plugins-base/gst-libs/gst/interfaces/interfaces-enumtypes.c \
			gst-plugins-base/gst-libs/gst/interfaces/interfaces-marshal.c \
			gst-plugins-base/gst-libs/gst/interfaces/mixer.c \
			gst-plugins-base/gst-libs/gst/interfaces/mixeroptions.c \
			gst-plugins-base/gst-libs/gst/interfaces/mixertrack.c \
			gst-plugins-base/gst-libs/gst/interfaces/navigation.c \
			gst-plugins-base/gst-libs/gst/interfaces/propertyprobe.c \
			gst-plugins-base/gst-libs/gst/interfaces/videoorientation.c \
			gst-plugins-base/gst-libs/gst/pbutils/codec-utils.c \
			gst-plugins-base/gst-libs/gst/pbutils/descriptions.c \
			gst-plugins-base/gst-libs/gst/pbutils/missing-plugins.c \
			gst-plugins-base/gst-libs/gst/pbutils/pbutils.c \
			gst-plugins-base/gst-libs/gst/pbutils/pbutils-enumtypes.c \
			gst-plugins-base/gst-libs/gst/riff/riff.c \
			gst-plugins-base/gst-libs/gst/riff/riff-media.c \
			gst-plugins-base/gst-libs/gst/riff/riff-read.c \
			gst-plugins-base/gst-libs/gst/tag/gstid3tag.c \
			gst-plugins-base/gst-libs/gst/tag/gsttagdemux.c \
			gst-plugins-base/gst-libs/gst/tag/lang.c \
			gst-plugins-base/gst-libs/gst/tag/tags.c

COMPILER_FLAGS = -nologo -W3 -WX- -EHsc -GS -fp:precise -Gm- \
                 -Zc:wchar_t -Zc:forScope -Gd -analyze- -errorReport:queue \
                 -wd"4018" -wd"4244" -wd"4005" -wd"4018" -wd"4101" -wd"4146" -wd"4244" -wd"4996"

INCLUDES = $(addprefix -I$(SRCBASE_DIR)/,$(DIRLIST)) \
           -I$(BASE_DIR)/plugins/ \
           -I$(SRCBASE_DIR)/projects/build/win32/common/ \
           -I$(SRCBASE_DIR)/projects/plugins/ \
           -I$(SRCBASE_DIR)/gstreamer/ \
           -I$(SRCBASE_DIR)/gstreamer/libs/ \
           -I$(SRCBASE_DIR)/gst-plugins-base/ \
           -I$(SRCBASE_DIR)/gst-plugins-base/gst-libs/ \
           -I$(SRCBASE_DIR)/gst-plugins-base/win32/common/ \
           -I$(GLIB_DIR)/ \
           -I$(GLIB_DIR)/glib/ \
           -I$(GLIB_DIR)/gmodule/ \
           -I$(GLIB_DIR)/build/win32/vs100/

CFLAGS =   -DWIN32 \
           -D_WINDOWS \
           -DLIBGSTREAMER_EXPORTS \
           -DHAVE_CONFIG_H \
           -DHAVE_WIN32 \
           -DLIBDSHOW_EXPORTS \
           -DGSTREAMER_LITE \
           -DGST_REMOVE_DEPRECATED \
           -DGST_REMOVE_DISABLED \
           -DGST_DISABLE_GST_DEBUG \
           -DGST_DISABLE_LOADSAVE \
           -D_USE_MATH_DEFINES \
           -D_USRDLL \
           -D_WINDLL \
           -D_MBCS \
	   $(INCLUDES) \
           $(COMPILER_FLAGS)

LIBFLAGS = -out:$(shell cygpath -ma $(TARGET)) -nologo

ifeq ($(BUILD_TYPE), Release)
    CFLAGS += -DNDEBUG -DG_DISABLE_DEPRECATED -DG_DISABLE_ASSERT -DG_DISABLE_CHECKS -O1 -Oy -MD -Gy -GF
else # debug
    CFLAGS += -D_DEBUG -Od -Oy- -RTC1 -MDd -Zi -Fd$(PDB)
endif

ifeq ($(ARCH), x32)
    LIBFLAGS += -MACHINE:x86
else
    CFLAGS += -D_WIN64
    LIBFLAGS += -MACHINE:x64
endif

OBJECTS = $(patsubst %.c,$(OBJBASE_DIR)/%.obj,$(C_SOURCES))

.PHONY: default

default: $(TARGET)

$(TARGET): $(OBJECTS) 
	$(LIB) $(LIBFLAGS) $(foreach object,$(OBJECTS),$(shell cygpath -ma $(object)))

$(OBJECTS): | $(DEP_DIRS)

$(DEP_DIRS):
	@mkdir -p $(DEP_DIRS)

$(OBJBASE_DIR)/%.obj: $(SRCBASE_DIR)/%.c
	$(CC) $(CFLAGS) -TC -c -Fo$(shell cygpath -ma $@) $<
