################################################################################
#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
#  Read the zproject/README.md for information about making permanent changes. #
################################################################################
program_libs = src/libczmq.la ${project_libs}

# Programs need to link the c++ runtime if everything was compiled statically.
if !ENABLE_SHARED
program_libs += -lstdc++ -lm
endif

lib_LTLIBRARIES += src/libczmq.la
pkgconfig_DATA = src/libczmq.pc

src_libczmq_la_SOURCES = \
    src/zactor.c \
    src/zarmour.c \
    src/zcert.c \
    src/zcertstore.c \
    src/zchunk.c \
    src/zclock.c \
    src/zconfig.c \
    src/zdigest.c \
    src/zdir.c \
    src/zdir_patch.c \
    src/zfile.c \
    src/zframe.c \
    src/zhash.c \
    src/zhashx.c \
    src/ziflist.c \
    src/zlist.c \
    src/zlistx.c \
    src/zloop.c \
    src/zmsg.c \
    src/zpoller.c \
    src/zsock.c \
    src/zstr.c \
    src/zsys.c \
    src/zuuid.c \
    src/zauth.c \
    src/zbeacon.c \
    src/zgossip.c \
    src/zgossip_engine.inc \
    src/zmonitor.c \
    src/zproxy.c \
    src/zrex.c \
    src/zgossip_msg.c \
    src/zsock_option.inc \
    src/zgossip_engine.inc \
    src/zhash_primes.inc \
    src/foreign/sha1/sha1.inc_c \
    src/foreign/sha1/sha1.h \
    src/foreign/slre/slre.inc_c \
    src/foreign/slre/slre.h \
    src/foreign/slre/readme.txt \
    src/platform.h

if ENABLE_DRAFTS
src_libczmq_la_SOURCES += \
    src/zargs.c \
    src/zproc.c \
    src/ztimerset.c \
    src/ztrie.c \
    src/zhttp_client.c \
    src/zhttp_server.c \
    src/zhttp_server_options.c \
    src/zhttp_request.c \
    src/zhttp_response.c

endif

if ENABLE_DRAFTS
src_libczmq_la_SOURCES += \
    src/czmq_private_selftest.c
endif

src_libczmq_la_CPPFLAGS = ${AM_CPPFLAGS}

src_libczmq_la_LDFLAGS = \
    -version-info @LTVER@ \
    $(LIBTOOL_EXTRA_LDFLAGS)

if ON_MINGW
src_libczmq_la_LDFLAGS += \
    -no-undefined \
    -avoid-version
endif

if ON_CYGWIN
src_libczmq_la_LDFLAGS += \
    -no-undefined \
    -avoid-version
endif

src_libczmq_la_LIBADD = ${project_libs}

if ENABLE_ZMAKECERT
bin_PROGRAMS += src/zmakecert
src_zmakecert_CPPFLAGS = ${AM_CPPFLAGS}
src_zmakecert_LDADD = ${program_libs}
src_zmakecert_SOURCES = src/zmakecert.c
endif #ENABLE_ZMAKECERT

if ENABLE_ZSP
noinst_PROGRAMS += src/zsp
src_zsp_CPPFLAGS = ${AM_CPPFLAGS}
src_zsp_LDADD = ${program_libs}
src_zsp_SOURCES = src/zsp.c
endif #ENABLE_ZSP

if ENABLE_TEST_RANDOF
noinst_PROGRAMS += src/test_randof
src_test_randof_CPPFLAGS = ${AM_CPPFLAGS}
src_test_randof_LDADD = ${program_libs}
src_test_randof_SOURCES = src/test_randof.c
endif #ENABLE_TEST_RANDOF

if ENABLE_CZMQ_SELFTEST
check_PROGRAMS += src/czmq_selftest
noinst_PROGRAMS += src/czmq_selftest
src_czmq_selftest_CPPFLAGS = ${AM_CPPFLAGS}
src_czmq_selftest_LDADD = ${program_libs}
src_czmq_selftest_SOURCES = src/czmq_selftest.c
endif #ENABLE_CZMQ_SELFTEST

# Install api files into /usr/local/share/zproject
apidir = @datadir@/zproject/czmq
dist_api_DATA = \
    api/python_cffi.slurp \
    api/zactor.api \
    api/zargs.api \
    api/zarmour.api \
    api/zcert.api \
    api/zcertstore.api \
    api/zchunk.api \
    api/zclock.api \
    api/zconfig.api \
    api/zdigest.api \
    api/zdir.api \
    api/zdir_patch.api \
    api/zfile.api \
    api/zframe.api \
    api/zhash.api \
    api/zhashx.api \
    api/ziflist.api \
    api/zlist.api \
    api/zlistx.api \
    api/zloop.api \
    api/zmsg.api \
    api/zpoller.api \
    api/zproc.api \
    api/zsock_option.api \
    api/zsock.api \
    api/zstr.api \
    api/zsys.api \
    api/ztimerset.api \
    api/ztrie.api \
    api/zuuid.api \
    api/zhttp_client.api \
    api/zhttp_server.api \
    api/zhttp_server_options.api \
    api/zhttp_request.api \
    api/zhttp_response.api \
    api/zgossip_msg.api

# define custom target for all products of /src
src: \
		src/zmakecert \
		src/zsp \
		src/test_randof \
		src/czmq_selftest \
		src/libczmq.la

# Produce generated code from models in the src directory
code:
	cd $(srcdir)/src; gsl -topdir:.. -zproject:1 -q sockopts.xml
	cd $(srcdir)/src; gsl -topdir:.. -zproject:1 -q zgossip.xml
	cd $(srcdir)/src; gsl -topdir:.. -zproject:1 -private:1 -q zgossip_msg.xml
	cd $(srcdir); gsl -target:- project.xml

# Directories with test fixtures optionally provided by the project,
# and with volatile RW data possibly created by a selftest program.
# It is up to the project authors to populate the RO directory with
# filenames called from the selftest methods, if any. They will be
# EXTRA_DISTed by the recipes generated with with zproject, however,
# and copied into builddir (if different from srcdir) to simplify
# the "distcheck" and similar tests (so selftest can use same paths).
# Note that the RO directory must exist to fulfill EXTRA_DIST, so we
# add a stub file that can be committed to SCM by project developers.
# The RW directory will be automatically wiped by "make distclean".
SELFTEST_DIR_RO = src/selftest-ro
SELFTEST_DIR_RW = src/selftest-rw

# This is recreated on every invocation (as a selftest dependency),
# so tests run in a clean environment
$(top_builddir)/$(SELFTEST_DIR_RW):
	rm -rf "$@"
	mkdir -p "$@"

# Note: for some reason "$<" misfired in rule below on Travis, so be explicit
if USING_VPATH
$(abs_top_builddir)/$(SELFTEST_DIR_RO): $(abs_top_srcdir)/$(SELFTEST_DIR_RO)
	@echo "   COPYDIR  $(SELFTEST_DIR_RO)"; \
	rm -rf "$@"; \
	cp -r "$(abs_top_srcdir)/$(SELFTEST_DIR_RO)" "$@"

$(top_builddir)/$(SELFTEST_DIR_RO): $(abs_top_builddir)/$(SELFTEST_DIR_RO)
endif

$(SELFTEST_DIR_RO): $(top_builddir)/$(SELFTEST_DIR_RO)

CLEANFILES += $(top_builddir)/$(SELFTEST_DIR_RW)/*

# Note that this syntax dists the whole directory - including subdirs (if any)
EXTRA_DIST += $(SELFTEST_DIR_RO)

clean-local: clean-local-selftest-ro clean-local-selftest-rw
.PHONY: clean-local-selftest-ro
clean-local-selftest-ro:
	@if test "$(top_builddir)" != "$(top_srcdir)" ; then \
		if test -d "$(top_builddir)/$(SELFTEST_DIR_RO)" ; then \
			chmod -R u+w "$(top_builddir)/$(SELFTEST_DIR_RO)" ; \
			rm -rf "$(top_builddir)/$(SELFTEST_DIR_RO)" ; \
		fi; \
	fi

# Unlike CLEANFILES setting above, this one whould also wipe created subdirs
.PHONY: clean-local-selftest-rw
clean-local-selftest-rw:
	@if test "$(top_builddir)" != "$(top_srcdir)" ; then \
		if test -d "$(top_builddir)/$(SELFTEST_DIR_RW)" ; then \
			chmod -R u+w "$(top_builddir)/$(SELFTEST_DIR_RW)" ; \
			rm -rf "$(top_builddir)/$(SELFTEST_DIR_RW)" ; \
		fi; \
	fi

check-empty-selftest-rw:
	if test -e $(top_builddir)/$(SELFTEST_DIR_RW) ; then \
		if test `find "$(top_builddir)/$(SELFTEST_DIR_RW)" | wc -l` -lt 1 ; then \
			echo "FATAL: selftest did not tidy up the data it wrote" >&2 ; \
			find "$(top_builddir)/$(SELFTEST_DIR_RW)" ; \
			exit 2; \
		else true ; fi; \
	else true ; fi

check-local: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute $(builddir)/src/czmq_selftest
	$(MAKE) check-empty-selftest-rw

check-verbose: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute $(builddir)/src/czmq_selftest -v
	$(MAKE) check-empty-selftest-rw

# Run the selftest binary under valgrind to check for memory leaks
memcheck: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute valgrind --tool=memcheck \
		--leak-check=full --show-reachable=yes --error-exitcode=1 \
		--suppressions=$(srcdir)/src/.valgrind.supp \
		$(VALGRIND_OPTIONS) \
		$(builddir)/src/czmq_selftest
	$(MAKE) check-empty-selftest-rw

memcheck-verbose: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute valgrind --tool=memcheck \
		--leak-check=full --show-reachable=yes --error-exitcode=1 \
		--suppressions=$(srcdir)/src/.valgrind.supp \
		$(VALGRIND_OPTIONS) \
		$(builddir)/src/czmq_selftest -v
	$(MAKE) check-empty-selftest-rw

# Run the selftest binary under valgrind to check for performance leaks
callcheck: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute valgrind --tool=callgrind \
		$(VALGRIND_OPTIONS) \
		$(builddir)/src/czmq_selftest
	$(MAKE) check-empty-selftest-rw

callcheck-verbose: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute valgrind --tool=callgrind \
		$(VALGRIND_OPTIONS) \
		$(builddir)/src/czmq_selftest -v
	$(MAKE) check-empty-selftest-rw

# Run the selftest binary under gdb for debugging
debug: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute gdb -q \
		$(builddir)/src/czmq_selftest
	$(MAKE) check-empty-selftest-rw

debug-verbose: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute gdb -q \
		$(builddir)/src/czmq_selftest -v
	$(MAKE) check-empty-selftest-rw

# Run the selftest binary with verbose switch for tracing
animate: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$(LIBTOOL) --mode=execute $(builddir)/src/czmq_selftest -v
	$(MAKE) check-empty-selftest-rw

animate-verbose: animate

if WITH_GCOV
coverage: src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	@echo "you had called configure --with-gcov"
	lcov --base-directory . --directory . --zerocounters -q
	$(MAKE) check
	lcov --base-directory . --directory . --capture -o coverage.info
	lcov --remove coverage.info "/usr*" -o coverage.info
	lcov --remove coverage.info "czmq_selftest.c" -o coverage.info
	$(RM) -rf coverage/*
	genhtml -o coverage/ -t "czmq test coverage" --num-spaces 4 coverage.info
else
coverage: src/czmq_selftest
	@echo "call make clean && configure --with-gcov to enable code coverage"
	@exit 1
endif

bindings: python-bindings

python-bindings:
if ENABLE_BINDINGS_PYTHON
	-( cd bindings/python && python setup.py install )
else
	@echo "Python Bindings not enabled or missing setup.py... skipping"

endif

# A series of tests that the codebase and recipes are pretty, easy
# to maintain and with predictable behavior. These generally are not
# expected to directly expose functional issues in the code, but
# still - there can be many reasons for failing such tests, and
# many lurking issues uncoverable by making code stylish again.
CHECK_STYLE_DEPS = check-gitignore
if WITH_CLANG_FORMAT
CHECK_STYLE_DEPS += clang-format-check
endif
check-style: $(CHECK_STYLE_DEPS)

if WITH_CLANG_FORMAT
ALL_SOURCE_FILES = $(wildcard \
	$(top_srcdir)/src/*.c \
	$(top_srcdir)/src/*.cc \
	$(top_srcdir)/src/*.cpp \
	$(top_srcdir)/src/*.h \
	$(top_srcdir)/src/*.hpp \
	$(top_srcdir)/tests/*.c \
	$(top_srcdir)/tests/*.cc \
	$(top_srcdir)/tests/*.cpp \
	$(top_srcdir)/tests/*.h \
	$(top_srcdir)/tests/*.hpp \
	$(top_srcdir)/perf/*.c \
	$(top_srcdir)/perf/*.cc \
	$(top_srcdir)/perf/*.cpp \
	$(top_srcdir)/perf/*.h \
	$(top_srcdir)/perf/*.hpp \
	$(top_srcdir)/tools/*.c \
	$(top_srcdir)/tools/*.cc \
	$(top_srcdir)/tools/*.cpp \
	$(top_srcdir)/tools/*.h \
	$(top_srcdir)/tools/*.hpp \
	$(top_srcdir)/include/*.h \
	$(top_srcdir)/include/*.hpp \
 )

# Check if any sources need to be fixed, report the filenames and an error code
clang-format-check: $(ALL_SOURCE_FILES)
	@if test -z "$(CLANG_FORMAT)" ; then \
		echo "FAILURE: CLANG_FORMAT program was not specified or found" >&2 ; \
		exit 1 ; \
	fi
	@FAILED=0 ; IFS=";" ; IDS="`printf '\n\b'`" ; export IFS IDS; \
	 for FILE in $(ALL_SOURCE_FILES) ; do \
		test -s $$FILE || continue ; \
		$(CLANG_FORMAT) -style=file -output-replacements-xml "$$FILE" | grep "<replacement " >/dev/null && \
		{ echo "$$FILE is not correctly formatted" >&2 ; FAILED=1; } ; \
	 done; \
	 if test "$$FAILED" != 0 ; then \
		exit 1 ; \
	 fi

# Change source formatting
clang-format: $(ALL_SOURCE_FILES)
	@if test -z "$(CLANG_FORMAT)" ; then \
		echo "FAILURE: CLANG_FORMAT program was not specified or found" >&2 ; \
		exit 1 ; \
	fi
	$(CLANG_FORMAT) -style=file -i $(ALL_SOURCE_FILES)

# Change source formatting AND report the diff
clang-format-diff: clang-format
	git diff $(ALL_SOURCE_FILES)

# A destructive (will change code in workspace) but informative check; this is
# primarily intended for CI temporary workspaces where mutilation is acceptable.
# The envvar/makearg CI_REQUIRE_GOOD_CLANG_FORMAT manages if this test is fatal.
clang-format-check-CI:
	@echo "CI-checking code style ..." >&2
	@if $(MAKE) clang-format-check ; then \
	   echo "SUCCESS : Style checks have passed" >&2 ; \
	else \
	   echo "" >&2 ; \
	   if test -n "$(CLANG_FORMAT)" ; then \
	     echo "Style mismatches were found by clang-format; detailing below:" >&2 ; \
	     $(MAKE) VERBOSE=1 clang-format-diff ; \
	   fi ; \
	   if test x"$(CI_REQUIRE_GOOD_CLANG_FORMAT)" = xtrue ; then \
	     echo "FAILED : Style checks have failed and CI_REQUIRE_GOOD_CLANG_FORMAT==true" >&2 ; \
	     exit 1 ; \
	   fi ; \
	   echo "WARNING : Style checks have failed, but the result is not-fatal because CI_REQUIRE_GOOD_CLANG_FORMAT!=true" >&2 ; \
	fi

else
clang-format clang-format-check clang-format-diff:
	@echo "Install the clang-format program, reconfigure and re-run this request"
	@exit 1

clang-format-check-CI:
	@echo "Install the clang-format program, reconfigure and re-run this request"
	@if test x"$(CI_REQUIRE_GOOD_CLANG_FORMAT)" = xtrue ; then \
	     echo "FAILED : Style checks have failed and CI_REQUIRE_GOOD_CLANG_FORMAT==true" >&2 ; \
	     exit 1 ; \
	 fi ; \
	 echo "WARNING : Style checks have failed, but the result is not-fatal because CI_REQUIRE_GOOD_CLANG_FORMAT!=true" >&2
endif

# Note: analysis is not a target executed by default, so there is no
# safety-net for the "cppcheck.xml" recipe; there is one for the wrapper.
# A developer is expected to install tools in build environment, if needed.
# The results can be used to produce some statistics how project quality
# changes over many builds (with a relevant Jenkins plugin, for example).
if WITH_CPPCHECK
cppcheck: cppcheck.xml
else
cppcheck:
	@echo "NOT ENABLED: cppcheck static analysis. Please install the toolkit and reconfigure, and/or make cppcheck.xml directly."
endif

cppcheck.xml:
	@echo "Performing cppcheck static analysis..."
	cppcheck --enable=all --inconclusive --xml --xml-version=2 . 2>"$@"
	@echo "The cppcheck static analysis is done"

# Note: this recipe tests that the Git-based workspace reports no changed
# or untracked files - meaning there are no unexpected behaviors in the
# recipes (when checking after a build), and nothing was missed while
# updating the project structure (when checking in the midst of development
# or after regenerating the zproject skeletons), for example. For best
# results, developers are advised to also run this after executing their
# tests, to make sure they are stateless and clean as well. Caller may
# export envvar (or pass make argument) CI_REQUIRE_GOOD_GITIGNORE=false
# to explicitly disable fatality of this check, while still logging it.

# This recipe is "stateless" by itself, not causing any workspace changes:
check-gitignore:
	@(if which git >/dev/null 2>&1 ; then \
	     RES=0; \
	     echo "Checking for untracked and not-ignored files in the workspace (should have no output below)..."; \
	     git status -s | egrep '^\?\? ' && RES=1 ; \
	     echo "Checking for modified tracked files in the workspace (should have no output below)..."; \
	     git status -s | egrep '^ *M ' && RES=1 && git diff | cat ; \
	     if [ "$$RES" = 0 ]; then \
	         echo "PASS: $@"; exit 0 ; \
	     else \
	         if [ x"$(CI_REQUIRE_GOOD_GITIGNORE)" = xfalse ] ; then \
	             echo "WARNING: $@ found newly changed or untracked and not-ignored files (not a test failure due to CI_REQUIRE_GOOD_GITIGNORE==false)"; exit 0 ; \
	         fi; \
	         echo "FAIL: $@ (see workspace checks above)"; exit 1; \
	     fi; \
	   else \
	     echo "SKIP: $@ (no git)"; exit 0 ; \
	   fi )

# This calls the recipe above after building the project products and
# the selftest binary, and preparing the workspace for self-testing:
check-gitignore-all: all src/czmq_selftest $(top_builddir)/$(SELFTEST_DIR_RW) $(top_builddir)/$(SELFTEST_DIR_RO)
	$@$(MAKE) check-gitignore


################################################################################
#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
#  Read the zproject/README.md for information about making permanent changes. #
################################################################################
