###############################################################################
# capi20wrapper - Collection of functions and data structures for accessing
#                 a shared library which implements the interface as described
#                 in section 'Linux' in part two of CAPI 2.0
# 
# Written in 2014 by Swen Lünig.
# 
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
# 
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
###############################################################################

# Here some example for how to start the programs:
# LD_LIBRARY_PATH=./:$HOME/lib/ CAPI20_Controller=0x00000005 ./capi20LISTEN_REQ
# LD_LIBRARY_PATH=./:$HOME/lib/ CAPI20_Controller=0x00000005 CAPI20_Called_party_number=01234 ./capi20CONNECT_REQ

CC:=gcc
CFLAGS:=-g

# Adapt the variables to your environment so you find libcapi20.so. If you
# experience a segmentation fault related to pthread-functions then try adding
# -lpthread to LIBS.
CPPFLAGS:=-Isrc/ -I$$HOME/include/
LDFLAGS:=-L./ -L$$HOME/lib/
LIBS:=-lcapi20

all: lib

PROGS:=capi20LISTEN_REQ capi20CONNECT_REQ
progs: $(PROGS)

lib: libcapi20wrapper.so

clean:
	find -name "*.o" -exec rm "{}" ";"
	find -name "*~" -exec rm "{}" ";"

distclean: clean
	rm -f $(PROGS)
	rm -f libcapi20wrapper.so

libcapi20wrapper.so: src/capi20wrapper.o Makefile
	$(CC) -Wall $(CFLAGS) $(LDFLAGS) -shared -o $@ $<

src/capi20wrapper.o: src/capi20wrapper.c src/capi20wrapper.h Makefile
	$(CC) -Wall $(CPPFLAGS) $(CFLAGS) -fpic -c -o $@ $<

$(PROGS): $(PROGS:%=examples/%.c) libcapi20wrapper.so
	$(CC) -Wall $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ examples/$@.c -lcapi20wrapper $(LIBS)

%.o : %.c Makefile
	$(CC) -Wall $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
