#
# Makefile for a Video Disk Recorder plugin
#
# Christian Wieninger cwieninger at gmx.de

# 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.
#

### uncomment one of this line, if you don't want the addon epgsearchonly
#WITHOUT_EPGSEARCHONLY=1

PLUGIN = epgsearch
PLUGIN2 = epgsearchonly

# comment this out if you want to use Perl compatible regular expressions (PCRE)
#HAVE_PCREPOSIX=1

### 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 ?= -Wall -O2 -Woverloaded-virtual -Wno-format-y2k -fPIC

### The directory environment:

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

### Allow user defined options to overwrite defaults:

-include $(VDRDIR)/Make.config

ALL = libvdr-$(PLUGIN).so createcats
ifndef WITHOUT_EPGSEARCHONLY
  ALL += libvdr-$(PLUGIN2).so
endif

### 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')
APIVERSION = $(shell grep 'define APIVERSION ' $(VDRDIR)/config.h | awk '{ print $$3 }' | sed -e 's/"//g')
ifeq ($(strip $(APIVERSION)),)
   APIVERSION = $(VDRVERSION)
endif

### 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
#INCLUDES += -I$(VDRDIR)/include

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

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

OBJS = afuzzy.o blacklist.o changrp.o distance.o $(PLUGIN).o epgsearchcats.o epgsearchcfg.o epgsearchext.o epgsearchsetup.o  i18n.o  menu_blacklistedit.o menu_blacklists.o menu_commands.o menu_dirselect.o menu_event.o menu_main.o menu_myedittimer.o menu_recsdone.o menu_search.o menu_searchactions.o menu_searchedit.o menu_searchresults.o menu_searchtemplate.o menu_switchtimers.o menu_templateedit.o menu_whatson.o rcfile.o  recdone.o recstatus.o searchtimer_thread.o switchtimer.o switchtimer_thread.o templatefile.o timer_thread.o tools.o  

ifdef HAVE_PCREPOSIX
LIBS += -lpcreposix
DEFINES += -DHAVE_PCREPOSIX
endif

OBJS2    = epgsearchonly.o
LIBS2    =

### Implicit rules:

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

# Dependencies:

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

-include $(DEPFILE)

### Targets:

all: $(ALL) 

libvdr-$(PLUGIN).so: $(OBJS)
	$(CXX) $(CXXFLAGS) -shared $(OBJS) $(LIBS) -o $@
	@cp $@ $(LIBDIR)/$@.$(APIVERSION)

libvdr-$(PLUGIN2).so: $(OBJS2)
	$(CXX) $(CXXFLAGS) -shared $(OBJS2) $(LIBS2) -o $@
	@cp $@ $(LIBDIR)/$@.$(APIVERSION)

createcats: createcats.o Makefile
	$(CXX) $(CXXFLAGS) createcats.o -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)
	@-rm -rf $(TMPDIR)/$(ARCHIVE)
	@echo Distribution package created as $(PACKAGE).tgz

clean:
	@-rm -f $(OBJS) $(OBJS2) $(DEPFILE) *.so *.tgz core* *~ createcats createcats.o
