### The C++ compiler and options:

CXX      ?= g++
CXXFLAGS ?= -g -march=pentium3 -O2 -Wall -Woverloaded-virtual

### The directory environment:

DVBDIR = ../../../../../DVB
VDRDIR = ../../../..

### Includes and Defines

INCLUDES = -I.. -I$(VDRDIR)/include -I$(DVBDIR)/include
DEFINES  = -D_GNU_SOURCE -DCRYPTO_AES -DCRYPTO_DES -DCRYPTO_IDEA -DOPENSSL

SHAREDOBJS = compat.o ../misc.o ../data.o ../crypto.o ../parse.o ../system.o \
             ../system-common.o $(VDRDIR)/tools.o $(VDRDIR)/thread.o

SHAREDLIBS = -lpthread -lcrypto

### Implicit rules:

$(VDRDIR)/%.o: $(VDRDIR)/%.c
	make -C $(VDRDIR) $(@F)

../%.o: ../%.c
	make -C .. $(@F)

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

### Targets:

all: testNagraEmu testNagraDisasm testNagraDES testDES testCCEMM testSecaECM testNagraECM

testNagraDisasm: testNagraDisasm.o
	$(CXX) $(CXXFLAGS) $^ -o $@

testNagraEmu.o: testNagraEmu.c ../system-nagra.c
testNagraEmu: testNagraEmu.o $(SHAREDOBJS)
	$(CXX) $(CXXFLAGS) $^ $(SHAREDLIBS) -o $@

testNagraDES.o: testNagraDES.c ../system-nagra.c
testNagraDES: testNagraDES.o $(SHAREDOBJS)
	$(CXX) $(CXXFLAGS) $^ $(SHAREDLIBS) -o $@

testDES: testDES.o $(SHAREDOBJS)
	$(CXX) $(CXXFLAGS) $^ $(SHAREDLIBS) -o $@

testCCEMM.o: testCCEMM.c ../network.o ../system-cc.o ../system-cc-camd.o ../system-cc-radegast.o ../system-cc-aroureos.o ../system-cc-newcamd.o ../system-viaccess.o ../system-irdeto.o ../system-seca.o
testCCEMM: testCCEMM.o $(SHAREDOBJS) ../network.o ../system-cc.o ../system-cc-camd.o ../system-cc-radegast.o ../system-cc-aroureos.o ../system-cc-newcamd.o ../system-viaccess.o ../system-irdeto.o ../system-seca.o
	$(CXX) $(CXXFLAGS) $^ $(SHAREDLIBS) -lcrypt -lz -o $@

testSecaECM.o: testSecaECM.c ../system-seca.c
testSecaECM: testSecaECM.o $(SHAREDOBJS) ../system-viaccess.o ../system-irdeto.o
	$(CXX) $(CXXFLAGS) $^ $(SHAREDLIBS) -o $@

testNagraECM.o: testNagraECM.c ../system-nagra.c
testNagraECM: testNagraECM.o $(SHAREDOBJS) ../system-seca.o ../system-viaccess.o ../system-irdeto.o ../system-conax.o
	$(CXX) $(CXXFLAGS) $^ $(SHAREDLIBS) -o $@

clean:
	@-rm -f *.o core* *~
	@-rm -f testNagraEmu testNagraDES testNagraDisasm testDES
	@-rm -f testNagraECM testSecaECM testCCEMM
