#
# Makefile for a Video Disk Recorder plugin
#
# $Id: Makefile,v 1.6 2004/12/05 18:50:33 lordjaxom Exp $

# 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 = burn

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

VERSION = $(shell grep 'static const char \*VERSION *=' $(PLUGIN).c | awk '{ print $$6 }' | sed -e 's/[";]//g')

### The C++ compiler and options:

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

### 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):

INCLUDES += -I$(VDRDIR)/include -I$(DVBDIR)/include

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

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

OBJS = burn.o i18n.o menuburn.o menuitems.o common.o jobs.o process.o \
       process-dvd.o process-vdr.o config.o setup.o pipe.o render.o xml.o

ifdef DEBUG_OSD
DEFINES += -DDEBUG_OSD
endif

ifdef DEBUG
DEFINES += -DDEBUG
CXXFLAGS += -g
endif

ifdef DVDDEV
DEFINES += -DDVDDEV='"$(DVDDEV)"'
else
DEFINES += -DDVDDEV='"/dev/dvd"'
endif

ifdef ISODIR
DEFINES += -DISODIR='"$(ISODIR)"'
else
DEFINES += -DISODIR=NULL
endif

### Implicit rules:

%.o: %.c
	$(CXX) $(CXXFLAGS) -c $(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-$(PLUGIN).so: $(OBJS)
	$(CXX) $(CXXFLAGS) -shared $(OBJS) -lImlib2 -o $@
	@cp $@ $(LIBDIR)/$@.$(VDRVERSION)

test/render: test/render.o render.o jobs.o common.o i18n.o process.o \
             process-dvd.o process-vdr.o pipe.o menuburn.o config.o \
						 setup.o menuitems.o \
             ../../../tools.o ../../../plugin.o ../../../i18n.o \
						 ../../../recording.o ../../../videodir.o ../../../thread.o \
             ../../../config.o ../../../menu.o ../../../menuitems.o \
						 ../../../interface.o ../../../osd.o ../../../osdbase.o \
						 ../../../keys.o ../../../status.o ../../../font.o \
						 ../../../remote.o ../../../timers.o ../../../channels.o \
						 ../../../device.o ../../../sources.o ../../../audio.o \
						 ../../../transfer.o ../../../receiver.o ../../../svdrp.o \
             ../../../eit.o ../../../player.o ../../../remux.o \
						 ../../../ringbuffer.o ../../../dvbplayer.o ../../../theme.o \
						 ../../../recorder.o ../../../cutter.o ../../../ci.o \
						 ../../../libdtv/libdtv.a
	$(CXX) $(CXXFLAGS) -lImlib2 -lpthread -o $@ $^

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

clean:
	@-rm -f test/render.o $(OBJS) $(DEPFILE) *.so *.tgz core* *~
