#
# $Id: Makefile,v 1.45 2004/07/03 21:08:07 rousseau Exp $
#

# set this path to where you installed pcsc-lite
INCS = `pkg-config libpcsclite --cflags`

# use a correct default CFLAGS
ifeq ($(CFLAGS),)
CFLAGS = -O2 -g -Wall -fPIC -I. -I../common -DGEMPC=410 $(INCS)
else
CFLAGS += -Wall -fPIC -I. -I../common -DGEMPC=410 $(INCS)
endif

# by default install in /usr/local
ifeq ($(DESTDIR),)
DESTDIR=/usr/local
endif

# /home/rousseau/sc/pcsc/i/ifd-gempc-0.5.10/GemPC410 -> 0.5.10
version=$(shell expr `pwd` : '.*-\([0-9.]*\)')
# /home/rousseau/sc/pcsc/i/ifd-gempc-0.5.10/GemPC410 -> 0
version_major=$(shell expr `pwd` : '.*-\([0-9]*\).[0-9.]*')

targets = GCGBPTransport.o gbpserial.o GemPC410Utils.o

common_targets = ../common/ifdhandler.o ../common/GCCmds.o ../common/GCUtils.o

all: check expert

check: check_stamp
check_stamp:
	CFLAGS="$(INCS)" ../check 410
	touch check_stamp

expert: ifd-GemPC410 resetGemPC410 libGemPC410.so

common:
	$(MAKE) -C ../common CFLAGS="$(CFLAGS) -I../GemPC410" all

ifd-GemPC410: common $(targets) main.o ../common/GCdebug.o
	$(CC) -o $@ $(targets) $(common_targets) main.o ../common/GCdebug.o

resetGemPC410: resetGemPC410.o
	$(CC) -o $@ $^

libGemPC410.so: common $(targets)
	rm -f $@
	$(CC) -shared $(targets) $(common_targets) -o $@
	chmod -x $@
	strip --strip-unneeded $@
	mv $@ $@.$(version)
	ln -sf $@.$(version) $@.$(version_major)
	ln -sf $@.$(version_major) $@

clean:
	rm -f .dependencies
	touch .dependencies
	rm -f $(targets)
	rm -f ifd-GemPC410 main.o
	rm -f libGemPC410.so*
	rm -f resetGemPC410.o resetGemPC410
	$(MAKE) -C ../common clean
	rm -f Makefile.bak
	rm -f config.log

distclean: clean
	rm -f tags
	rm -f check_stamp dep_stamp

install: all
	if [ ! -d $(DESTDIR)/pcsc/drivers/serial ] ; then install -d $(DESTDIR)/pcsc/drivers/serial ; fi
	cp -R libGemPC410.so* $(DESTDIR)/pcsc/drivers/serial

dep: dep_stamp
dep_stamp:
	@echo "Making dependencies..."
	makedepend -f - -I. -I../common -DGEMPC=410 *.c > .dependencies || true
	$(MAKE) -C ../common dep
	touch dep_stamp

.dependencies: dep

ctags:
	ctags-exuberant *.h *.c ../common/*.h ../common/*.c

.PHONY: all common clean distclean dep ctags expert check

include .dependencies

