#!/usr/bin/make -f

default: all


PACKAGE_VERSION = 2004.09.25
PACKAGE_NAME = libs11n_sigslot

include basics.make
include doxy.make

INCLUDES_INSTALL_SUBDIR = include/s11n.net/sigslot
INSTALL_HEADERS_DEST = $(INSTALL_ROOT)/$(INCLUDES_INSTALL_SUBDIR)
INSTALL_HEADERS = sigslot.hpp sigslot.*.hpp


GENERATOR = generatesigslots

DIST_FILES += Makefile README \
	configure $(GENERATOR) \
	sigslot.hpp test.cpp


########################################################################
# SLOT_ARG_COUNT = Number of args to generate signals/slots for.
# Adjust this to whatever you feel is reasonable.
SLOT_ARG_COUNT ?= 6
########################################################################

GEND_CODE = sigslot.generated.hpp
$(GEND_CODE): $(GENERATOR) Makefile sigslot.hpp
	@echo "Generating $@..."
	@echo '// auto-generated' > $@
	@c=2; while test $$c -le $(SLOT_ARG_COUNT); do \
		out=sigslot.$$c.hpp; \
		echo "Generating $$out..."; \
		./$(GENERATOR) $$c > $$out || exit; \
		echo "#include \"$$out\"" >> $@; \
		c=$$(($$c + 1)); \
	done

install: $(GEND_CODE) install-HEADERS
uninstall: uninstall-HEADERS

CLEAN_FILES += *~ \
	$(wildcard sigslot.*.hpp stest globallock locallock *.o) 

all: $(GEND_CODE)
	@echo -e "This source tree needs to special building.\n\
Run one of these targets to make a test app:\n\
\tstest = single-threaded\n\
\tlocallock = with posix threads, local locking\n\
\tgloballock = with posix threads, global locking\n\
Run 'make test' to build and run all test apps.\n\
To install it run:\n\
\t${MAKE} install [prefix=/some/prefix] [DESTDIR=/alternate/root]\n\
The header(s) will be installed to {DESTDIR}/{prefix}/$(INCLUDES_INSTALL_SUBDIR)\n\
Defaults:\n\
\tDESTDIR=$(DESTDIR)\n\
\tprefix=$(prefix)\n\
"
ifneq (,$(DOXYGEN_BIN))
	@echo "To build the API docs using doxygen run 'make doxygen'."
else
	@echo "If you will install doxygen in your PATH you may build the API docs by running 'make doxygen'"
endif


PTHREAD_DEFINES = \
	-DSIGSLOT_USE_POSIX_THREADS=1 \
	-lpthread

TEST_DEPS = $(GEND_CODE) Makefile sigslot.hpp basics.make

bin_CFLAGS = -g
bin_LDADD = -lstdc++
locallock_SOURCES = test.cpp
locallock_CFLAGS = $(PTHREAD_DEFINES) \
	-DSIGSLOT_DEBUG=1 \
	-DSIGSLOT_PTHREAD_CLASS=pthread_local -lpthread

globallock_SOURCES = test.cpp
globallock_CFLAGS = $(PTHREAD_DEFINES) \
	-DSIGSLOT_DEBUG=1 \
	-DSIGSLOT_PTHREAD_CLASS=pthread_global -lpthread
globallock_DEPS = $(TEST_DEPS)
stest_SOURCES = test.cpp
ltest_SOURCES = list.cpp


SUBMAKE = ${MAKE} --no-print-directory
stest: $(TEST_DEPS) test.cpp
	@${SUBMAKE} bin-$@
locallock: $(TEST_DEPS) test.cpp
	@${SUBMAKE} bin-$@
globallock: $(TEST_DEPS) test.cpp
	@${SUBMAKE} bin-$@

ltest: $(TEST_DEPS) list.cpp
	@${SUBMAKE} bin-$@

bins: stest locallock globallock
test: bins
	@echo "No locking:";
	./stest
	@echo "Multi-threaded, global-mutex locking:";
	./globallock
	@echo "Multi-threaded, local-mutex locking:";
	./locallock
