# $Id: Makefile,v 1.13 2001/01/31 17:50:47 rousseau Exp $

CC = gcc
CFLAGS = -O2 -Wall -I.

DESTDIR =
BIN     = $(DESTDIR)/usr/bin
LIB     = $(DESTDIR)/usr/lib
SAMPLES = $(DESTDIR)/usr/share/doc/libtlp-dev/samples

lib_name = libSCreader
version_major = 1
version_minor = 0
version_patch = 4

obj = c2bin.lo bin2c.lo reader.lo tlpreader.lo rftlpreader.lo serial.lo
inc = rftlpreader.h tlpreader.h reader.h ReaderType.h bin2c.h c2bin.h
target = $(lib_name).so.$(version_major).$(version_minor).$(version_patch)


.PHONY: all clean test

all: $(target)
	ln -fs $(target) $(lib_name).so.$(version_major)
	ln -fs $(lib_name).so.$(version_major) $(lib_name).so

test: all
	make -C samples test

$(target): $(obj)
	 $(CC) -shared $^ -ldl -lc  -Wl,-soname \
	 	-Wl,$(lib_name).so.$(version_major) -o $@
 
$(obj): $(inc)

clean: 
	rm -f $(obj) $(lib_name)*
	make -C samples clean
	make -C tools clean

%.lo: %.c
	$(CC) $(CFLAGS) -c -fPIC -DPIC $< -o $@

install: $(target)
	# lib part	
	##########
	install $(target) $(LIB)
	ln -sf $(target) $(LIB)/$(lib_name).so.$(version_major)
	install tools/reset_tlp $(BIN)
	install tools/scsend $(BIN)
	
install-dev:	
	# the dev part
	##############
#	install samples/Makefile $(SAMPLES)
#	install samples/*.c $(SAMPLES)
#	install samples/erase_gpk8k.scsend $(SAMPLES)

	install -m 644 reader.h $(DESTDIR)/usr/include/
	install -m 644 ReaderType.h $(DESTDIR)/usr/include/

	ln -sf $(lib_name).so.$(version_major) $(LIB)/$(lib_name).so

config-dev:
	cp -af $(lib_name)* $(DESTDIR)/lib
	if [ ! $$(grep ^/usr/local/lib$$ /etc/ld.so.conf) ] ; \
	then \
		echo $(target_dir) >> /etc/ld.so.conf ; \
	fi
	ldconfig

serial.c: serial.h
reader.c: reader.h tlpreader.h rftlpreader.h c2bin.h
rftlpreader.c: reader.h rftlpreader.h bin2c.h c2bin.h serial.h
tlpreader.c: reader.h tlpreader.h bin2c.h c2bin.h serial.h

