include ../../config.mak

VPATH=$(SRC_PATH)/Applications/MP4Client

# NOTE: -I.. is needed to include config.h
CFLAGS= $(OPTFLAGS) -Wall -I.. -I$(SRC_PATH)/include

ifeq ($(DEBUGBUILD), yes)
CFLAGS+=-g
LDFLAGS+=-g
endif

#common obj
OBJS= main.o 

ifeq ($(BUILD_INSTALL), yes)
INSTALL_FLAGS=-DM4_PLUGIN_PATH=\"$(libdir)\"
else
INSTALL_FLAGS=
endif

LINKFLAGS=-L../../bin/gcc -lm4systems

ifeq ($(CONFIG_JS),no)
else
ifeq ($(CONFIG_JS),local)
LINKFLAGS+= -L../../extra_lib/lib/gcc
endif
LINKFLAGS+= -l$(JS_LIBS)
endif

ifeq ($(CONFIG_WIN32),yes)
EXE=.exe
PROG=MP4Client$(EXE)
else
LDFLAGS+= -lpthread -ldl
EXT=
PROG=MP4Client
endif

SRCS := $(OBJS:.o=.c) 

all: $(PROG)

#I added m4systems twice because gcc has trouble linking with libs using cross references
MP4Client$(EXE): $(OBJS)
	$(CC) $(LDFLAGS) -o ../../bin/gcc/$@ $(OBJS) $(LINKFLAGS) $(EXTRALIBS)

%.o: %.c
	$(CC) $(CFLAGS) $(INSTALL_FLAGS) -c -o $@ $< 

clean: 
	rm -f $(OBJS) ../../bin/gcc/$(PROG)

install: clean
	make -override BUILD_INSTALL=yes all
	install -c -s -m 755 ../../bin/gcc/MP4Client "$(bindir)"

uninstall:
	rm -rf $(bindir)/MP4Client

dep: depend

depend:
	rm -f .depend	
	$(CC) -MM $(CFLAGS) $(SRCS) 1>.depend

distclean: clean
	rm -f Makefile.bak .depend



# include dependency files if they exist
#
ifneq ($(wildcard .depend),)
include .depend
endif
