#
# Makefile for a Video Disk Recorder plugin
#
# $Id: Makefile,v 1.18 2004/05/11 20:05:44 dom Exp $
#


# Uncomment these if you have the appropriate libraries
HAVE_MAGICK = 1
# Set this to the version of ImageMagick that you have
MAGICK_VERSION = 5
HAVE_LIBJPEG = 1
#HAVE_LIBXML2 = 1
#HAVE_LIBID3TAG = 1


# Uncomment this if you only have a single device in your vdr machine
#SINGLE_DEVICE = 1


# The official name of this plugin.
# This name will be used in the '-P...' option of VDR to load the plugin.
# By default the main source file also carries this name.
#
PLUGIN = mediamvp
PLUGIN2 = mvp

### The version number of this plugin (taken from the main source file):

VERSION = $(shell grep 'SERVER_VERSION' mvp/config.h | awk '{ print $$3 }' | sed -e 's/[";]//g')

### The C++ compiler and options:

CXX      ?= g++
CXXFLAGS ?= -g -O2 -Wall -Woverloaded-virtual  -D_GNU_SOURCE 

### The directory environment:

DVBDIR = ../../../../DVB
VDRDIR = ../../..
LIBDIR = ../../lib
TMPDIR = /tmp

### Allow user defined options to overwrite defaults:

-include $(VDRDIR)/Make.config

### The version number of VDR (taken from VDR's "config.h"):

VDRVERSION = $(shell grep 'define VDRVERSION ' $(VDRDIR)/config.h | awk '{ print $$3 }' | sed -e 's/"//g')

### The name of the distribution archive:

ARCHIVE = $(PLUGIN)-$(VERSION)
PACKAGE = vdr-$(ARCHIVE)

### Includes and Defines (add further entries here):

LIBS += -Lrender/ -lmvprender -Lmvp/ -lmvp -levent -lz -lm
LIBS2 += -Lmvp/ -lmvp -levent -lz -lm

INCLUDES += -I$(VDRDIR)/include -I$(DVBDIR)
INCLUDES += -Iconsole/ -Imvp/ -Irender/ -Iimage/ -I. -Iremux/ 

INCLUDES2 += -I$(VDRDIR)/include -I$(DVBDIR)
INCLUDES2 += -Imvp/ -I. -Idev/

DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DVDR_PLUGIN 

### The object files (add further files here):

OBJS = $(PLUGIN).o setup.o i18n.o server.o console/program.o console/menuapp.o console/menu.o \
	transceiver.o vdrurl.o vdrrecurl.o misc.o \
	remux/tsremux.o remux/ts2ps.o remux/ts2es.o 

OBJS2 = dev/$(PLUGIN2).o dev/setup.o i18n.o dev/mvposd.o dev/mvpprog.o dev/mvpremote.o dev/mvpwrap.o dev/mvplive.o

ifdef HAVE_LIBXML2
INCLUDES += -I/usr/include/libxml2
DEFINES += -DHAVE_LIBXML2
LIBS += -lxml2
endif
ifdef HAVE_LIBXML2
DEFINES += -DHAVE_LIBJPEG
LIBS += -Limage/ -lmvpimage -ljpeg
endif
ifdef HAVE_LIBID3TAG
DEFINES += -DHAVE_LIBID3TAG
LIBS += -lid3
endif
ifdef SINGLE_DEVICE
DEFINES += -DHAVE_LIBJPEG
endif


### Implicit rules:

%.o: %.c
	$(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) -o $@  $<

%.i: %.c
	$(CXX) -E $(CXXFLAGS) $(DEFINES) $(INCLUDES)  -o $@ $<

# Dependencies:

MAKEDEP = g++ -MM -MG
DEPFILE = .dependencies
$(DEPFILE): Makefile
	@$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@

-include $(DEPFILE)

### Targets:

all: libvdr-$(PLUGIN).so libvdr-$(PLUGIN2).so

ifdef HAVE_LIBJPEG
libvdr-$(PLUGIN).so: $(OBJS) mvp/libmvp.a render/libmvprender.a image/libmvpimage.a
else
libvdr-$(PLUGIN).so: $(OBJS) mvp/libmvp.a render/libmvprender.a 
endif
	$(CXX) $(CXXFLAGS) -shared $(OBJS) -o $@ $(LIBS)
	@cp $@ $(LIBDIR)/$@.$(VDRVERSION)

libvdr-$(PLUGIN2).so: $(OBJS2) mvp/libmvp.a 
	$(CXX) $(CXXFLAGS) -shared $(OBJS2) -o $@ $(LIBS2)
	@cp $@ $(LIBDIR)/$@.$(VDRVERSION)

mvp/libmvp.a:
	$(MAKE) -C mvp HAVE_LIBID3TAG=$(HAVE_LIBID3TAG) 

render/libmvprender.a:
	$(MAKE) -C render 

image/libmvpimage.a:
	$(MAKE) -C image HAVE_LIBJPEG=$(HAVE_LIBJPEG) HAVE_MAGICK=$(HAVE_MAGICK) MAGICK_VERSION=$(MAGICK_VERSION)

dist: clean
	@-rm -rf $(TMPDIR)/$(ARCHIVE)
	@mkdir $(TMPDIR)/$(ARCHIVE)
	@cp -a * $(TMPDIR)/$(ARCHIVE)
	@tar czf $(PACKAGE).tgz -C $(TMPDIR) $(ARCHIVE)
	@-rm -rf $(TMPDIR)/$(ARCHIVE)
	@echo Distribution package created as $(PACKAGE).tgz

clean:
	$(MAKE) -C console clean
	@-rm -f $(OBJS) $(OBJS2) $(DEPFILE) *.so *.tgz core* *~
