## Process this file with automake to produce Makefile.in

ACLOCAL_AMFLAGS = -I m4

AUTOMAKE_OPTIONS = foreign subdir-objects

# When running distcheck, verify that we've included all the files needed by
# the cmake build.
distcheck-hook:
	rm -rf distcheck-cmake
	(mkdir distcheck-cmake && cd distcheck-cmake && cmake ../$(distdir) && make -j6 check)
	rm -rf distcheck-cmake

AM_CXXFLAGS = -I$(srcdir)/src -I$(builddir)/src -DKJ_HEADER_WARNINGS -DCAPNP_HEADER_WARNINGS -DCAPNP_INCLUDE_DIR='"$(includedir)"' $(PTHREAD_CFLAGS)

AM_LDFLAGS = $(PTHREAD_CFLAGS)

EXTRA_DIST =                                                                 \
  README.txt                                                                 \
  LICENSE.txt                                                                \
  $(test_capnpc_inputs)                                                      \
  src/capnp/compiler/capnp-test.sh                                           \
  src/capnp/testdata/segmented-packed                                        \
  src/capnp/testdata/errors.capnp.nobuild                                    \
  src/capnp/testdata/short.txt                                               \
  src/capnp/testdata/flat                                                    \
  src/capnp/testdata/binary                                                  \
  src/capnp/testdata/errors.txt                                              \
  src/capnp/testdata/segmented                                               \
  src/capnp/testdata/packed                                                  \
  src/capnp/testdata/pretty.txt                                              \
  CMakeLists.txt                                                             \
  cmake/FindCapnProto.cmake                                                  \
  src/CMakeLists.txt                                                         \
  src/kj/CMakeLists.txt                                                      \
  src/capnp/CMakeLists.txt

CLEANFILES = $(test_capnpc_outputs) test_capnpc_middleman distcheck-cmake

# Deletes all the files generated by autoreconf.
MAINTAINERCLEANFILES =   \
  aclocal.m4             \
  config.guess           \
  config.sub             \
  configure              \
  depcomp                \
  install-sh             \
  ltmain.sh              \
  Makefile.in            \
  missing                \
  mkinstalldirs          \
  config.h.in            \
  stamp.h.in             \
  m4/ltsugar.m4          \
  m4/libtool.m4          \
  m4/ltversion.m4        \
  m4/lt~obsolete.m4      \
  m4/ltoptions.m4

maintainer-clean-local:
	-rm -rf build-aux

# gmake defines an implicit rule building n from n.o.  Unfortunately, this triggers on our .capnp
# files because they generate .capnp.c++ which is compiled to .capnp.o.  In addition to being
# nonsense, this leads to cyclic dependency issues and could even cause the .capnp files to be
# unexpectedly overwritten!  We need to cancel the implicit rule by declaring an explicit one.
#
# I want the hours of my life back that I spent figuring this out.
%.capnp:
	@:

public_capnpc_inputs =                                         \
  src/capnp/c++.capnp                                          \
  src/capnp/schema.capnp                                       \
  src/capnp/rpc.capnp                                          \
  src/capnp/rpc-twoparty.capnp                                 \
  src/capnp/persistent.capnp                                   \
  src/capnp/compat/json.capnp

capnpc_inputs =                                                \
  $(public_capnpc_inputs)                                      \
  src/capnp/compiler/lexer.capnp                               \
  src/capnp/compiler/grammar.capnp

capnpc_outputs =                                               \
  src/capnp/c++.capnp.c++                                      \
  src/capnp/c++.capnp.h                                        \
  src/capnp/schema.capnp.c++                                   \
  src/capnp/schema.capnp.h                                     \
  src/capnp/rpc.capnp.c++                                      \
  src/capnp/rpc.capnp.h                                        \
  src/capnp/rpc-twoparty.capnp.c++                             \
  src/capnp/rpc-twoparty.capnp.h                               \
  src/capnp/persistent.capnp.c++                               \
  src/capnp/persistent.capnp.h                                 \
  src/capnp/compat/json.capnp.h                                \
  src/capnp/compat/json.capnp.c++                              \
  src/capnp/compiler/lexer.capnp.c++                           \
  src/capnp/compiler/lexer.capnp.h                             \
  src/capnp/compiler/grammar.capnp.c++                         \
  src/capnp/compiler/grammar.capnp.h

includecapnpdir = $(includedir)/capnp
includecapnpcompatdir = $(includecapnpdir)/compat
includekjdir = $(includedir)/kj
includekjparsedir = $(includekjdir)/parse
includekjstddir = $(includekjdir)/std
includekjcompatdir = $(includekjdir)/compat

dist_includecapnp_DATA = $(public_capnpc_inputs)

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = capnp.pc capnp-rpc.pc kj.pc kj-async.pc

noinst_HEADERS = \
  src/kj/miniposix.h

includekj_HEADERS =                                            \
  src/kj/common.h                                              \
  src/kj/units.h                                               \
  src/kj/memory.h                                              \
  src/kj/refcount.h                                            \
  src/kj/array.h                                               \
  src/kj/vector.h                                              \
  src/kj/string.h                                              \
  src/kj/string-tree.h                                         \
  src/kj/exception.h                                           \
  src/kj/debug.h                                               \
  src/kj/arena.h                                               \
  src/kj/io.h                                                  \
  src/kj/tuple.h                                               \
  src/kj/one-of.h                                              \
  src/kj/function.h                                            \
  src/kj/mutex.h                                               \
  src/kj/thread.h                                              \
  src/kj/threadlocal.h                                         \
  src/kj/async-prelude.h                                       \
  src/kj/async.h                                               \
  src/kj/async-inl.h                                           \
  src/kj/time.h                                                \
  src/kj/async-unix.h                                          \
  src/kj/async-io.h                                            \
  src/kj/main.h                                                \
  src/kj/test.h                                                \
  src/kj/windows-sanity.h

includekjparse_HEADERS =                                       \
  src/kj/parse/common.h                                        \
  src/kj/parse/char.h

includekjstd_HEADERS =                                         \
  src/kj/std/iostream.h

includekjcompat_HEADERS =                                      \
  src/kj/compat/gtest.h

includecapnp_HEADERS =                                         \
  src/capnp/c++.capnp.h                                        \
  src/capnp/common.h                                           \
  src/capnp/blob.h                                             \
  src/capnp/endian.h                                           \
  src/capnp/layout.h                                           \
  src/capnp/orphan.h                                           \
  src/capnp/list.h                                             \
  src/capnp/any.h                                              \
  src/capnp/message.h                                          \
  src/capnp/capability.h                                       \
  src/capnp/membrane.h                                         \
  src/capnp/schema.capnp.h                                     \
  src/capnp/schema-lite.h                                      \
  src/capnp/schema.h                                           \
  src/capnp/schema-loader.h                                    \
  src/capnp/schema-parser.h                                    \
  src/capnp/dynamic.h                                          \
  src/capnp/pretty-print.h                                     \
  src/capnp/serialize.h                                        \
  src/capnp/serialize-async.h                                  \
  src/capnp/serialize-packed.h                                 \
  src/capnp/serialize-text.h                                   \
  src/capnp/pointer-helpers.h                                  \
  src/capnp/generated-header-support.h                         \
  src/capnp/rpc-prelude.h                                      \
  src/capnp/rpc.h                                              \
  src/capnp/rpc-twoparty.h                                     \
  src/capnp/rpc.capnp.h                                        \
  src/capnp/rpc-twoparty.capnp.h                               \
  src/capnp/persistent.capnp.h                                 \
  src/capnp/ez-rpc.h

includecapnpcompat_HEADERS =                                   \
  src/capnp/compat/json.h                                      \
  src/capnp/compat/json.capnp.h

if LITE_MODE
lib_LTLIBRARIES = libkj.la libkj-test.la libcapnp.la
else
lib_LTLIBRARIES = libkj.la libkj-test.la libkj-async.la libcapnp.la libcapnp-rpc.la libcapnp-json.la libcapnpc.la
endif

# Don't include security release in soname -- we want to replace old binaries
# in this case.
SO_VERSION = $(shell echo $(VERSION) | sed -e 's/^\([0-9]*[.][0-9]*[.][0-9]*\)\([.][0-9]*\)*\(-.*\)*$$/\1\3/g')

libkj_la_LIBADD = $(PTHREAD_LIBS)
libkj_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libkj_la_SOURCES=                                              \
  src/kj/common.c++                                            \
  src/kj/units.c++                                             \
  src/kj/memory.c++                                            \
  src/kj/refcount.c++                                          \
  src/kj/array.c++                                             \
  src/kj/string.c++                                            \
  src/kj/string-tree.c++                                       \
  src/kj/exception.c++                                         \
  src/kj/debug.c++                                             \
  src/kj/arena.c++                                             \
  src/kj/io.c++                                                \
  src/kj/mutex.c++                                             \
  src/kj/thread.c++                                            \
  src/kj/main.c++                                              \
  src/kj/parse/char.c++

libkj_test_la_LIBADD = libkj.la $(PTHREAD_LIBS)
libkj_test_la_LDFLAGS = -release $(VERSION) -no-undefined
libkj_test_la_SOURCES = src/kj/test.c++

if !LITE_MODE
libkj_async_la_LIBADD = libkj.la $(PTHREAD_LIBS)
libkj_async_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libkj_async_la_SOURCES=                                        \
  src/kj/async.c++                                             \
  src/kj/async-unix.c++                                        \
  src/kj/async-io.c++                                          \
  src/kj/time.c++
endif !LITE_MODE

if !LITE_MODE
heavy_sources =                                                \
  src/capnp/schema.c++                                         \
  src/capnp/schema-loader.c++                                  \
  src/capnp/dynamic.c++                                        \
  src/capnp/stringify.c++
endif !LITE_MODE

libcapnp_la_LIBADD = libkj.la $(PTHREAD_LIBS)
libcapnp_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libcapnp_la_SOURCES=                                           \
  src/capnp/c++.capnp.c++                                      \
  src/capnp/blob.c++                                           \
  src/capnp/arena.h                                            \
  src/capnp/arena.c++                                          \
  src/capnp/layout.c++                                         \
  src/capnp/list.c++                                           \
  src/capnp/any.c++                                            \
  src/capnp/message.c++                                        \
  src/capnp/schema.capnp.c++                                   \
  src/capnp/serialize.c++                                      \
  src/capnp/serialize-packed.c++                               \
  $(heavy_sources)

if !LITE_MODE

libcapnp_rpc_la_LIBADD = libcapnp.la libkj-async.la libkj.la $(PTHREAD_LIBS)
libcapnp_rpc_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libcapnp_rpc_la_SOURCES=                                       \
  src/capnp/serialize-async.c++                                \
  src/capnp/capability.c++                                     \
  src/capnp/membrane.c++                                       \
  src/capnp/dynamic-capability.c++                             \
  src/capnp/rpc.c++                                            \
  src/capnp/rpc.capnp.c++                                      \
  src/capnp/rpc-twoparty.c++                                   \
  src/capnp/rpc-twoparty.capnp.c++                             \
  src/capnp/persistent.capnp.c++                               \
  src/capnp/ez-rpc.c++

libcapnp_json_la_LIBADD = libcapnp.la libkj-async.la libkj.la $(PTHREAD_LIBS)
libcapnp_json_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libcapnp_json_la_SOURCES=                                      \
  src/capnp/compat/json.c++                                    \
  src/capnp/compat/json.capnp.c++

libcapnpc_la_LIBADD = libcapnp.la libkj.la $(PTHREAD_LIBS)
libcapnpc_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libcapnpc_la_SOURCES=                                          \
  src/capnp/compiler/md5.h                                     \
  src/capnp/compiler/md5.c++                                   \
  src/capnp/compiler/error-reporter.h                          \
  src/capnp/compiler/error-reporter.c++                        \
  src/capnp/compiler/lexer.capnp.h                             \
  src/capnp/compiler/lexer.capnp.c++                           \
  src/capnp/compiler/lexer.h                                   \
  src/capnp/compiler/lexer.c++                                 \
  src/capnp/compiler/grammar.capnp.h                           \
  src/capnp/compiler/grammar.capnp.c++                         \
  src/capnp/compiler/parser.h                                  \
  src/capnp/compiler/parser.c++                                \
  src/capnp/compiler/node-translator.h                         \
  src/capnp/compiler/node-translator.c++                       \
  src/capnp/compiler/compiler.h                                \
  src/capnp/compiler/compiler.c++                              \
  src/capnp/schema-parser.c++                                  \
  src/capnp/serialize-text.c++

bin_PROGRAMS = capnp capnpc-capnp capnpc-c++

capnp_LDADD = libcapnpc.la libcapnp.la libkj.la $(PTHREAD_LIBS)
capnp_SOURCES =                                                \
  src/capnp/compiler/module-loader.h                           \
  src/capnp/compiler/module-loader.c++                         \
  src/capnp/compiler/capnp.c++

capnpc_capnp_LDADD = libcapnp.la libkj.la $(PTHREAD_LIBS)
capnpc_capnp_SOURCES = src/capnp/compiler/capnpc-capnp.c++

capnpc_c___LDADD = libcapnp.la libkj.la $(PTHREAD_LIBS)
capnpc_c___SOURCES = src/capnp/compiler/capnpc-c++.c++

# Symlink capnpc -> capnp.  The capnp binary will behave like the old capnpc
# binary (i.e. like "capnp compile") when invoked via this symlink.
#
# Also attempt to run ldconfig, because otherwise users get confused.  If
# it fails (e.g. because the platform doesn't have it, or because the
# user doesn't have root privileges), don't worry about it.
install-exec-hook:
	ln -sf capnp $(DESTDIR)$(bindir)/capnpc
	ldconfig < /dev/null > /dev/null 2>&1 || true

uninstall-hook:
	rm -f $(DESTDIR)$(bindir)/capnpc

else LITE_MODE

install-exec-hook:
	ldconfig < /dev/null > /dev/null 2>&1 || true

endif LITE_MODE

# Source files intentionally not included in the dist at this time:
#  src/capnp/serialize-snappy*
#  src/capnp/benchmark/...
#  src/capnp/compiler/...

# Tests ==============================================================

test_capnpc_inputs =                                           \
  src/capnp/test.capnp                                         \
  src/capnp/test-import.capnp                                  \
  src/capnp/test-import2.capnp

test_capnpc_outputs =                                          \
  src/capnp/test.capnp.c++                                     \
  src/capnp/test.capnp.h                                       \
  src/capnp/test-import.capnp.c++                              \
  src/capnp/test-import.capnp.h                                \
  src/capnp/test-import2.capnp.c++                             \
  src/capnp/test-import2.capnp.h

if USE_EXTERNAL_CAPNP

test_capnpc_middleman: $(test_capnpc_inputs)
	$(CAPNP) compile --src-prefix=$(srcdir)/src -o$(CAPNPC_CXX):src -I$(srcdir)/src $^
	touch test_capnpc_middleman

else

test_capnpc_middleman: capnp$(EXEEXT) capnpc-c++$(EXEEXT) $(test_capnpc_inputs)
	echo $^ | (read CAPNP CAPNPC_CXX SOURCES && ./$$CAPNP compile --src-prefix=$(srcdir)/src -o./$$CAPNPC_CXX:src -I$(srcdir)/src $$SOURCES)
	touch test_capnpc_middleman

endif

$(test_capnpc_outputs): test_capnpc_middleman

BUILT_SOURCES = $(test_capnpc_outputs)

if LITE_MODE

check_PROGRAMS = capnp-test
compiler_tests =
capnp_test_LDADD = libcapnp.la libkj-test.la libkj.la

else !LITE_MODE

check_PROGRAMS = capnp-test capnp-evolution-test
heavy_tests =                                                  \
  src/kj/async-test.c++                                        \
  src/kj/async-unix-test.c++                                   \
  src/kj/async-io-test.c++                                     \
  src/kj/parse/common-test.c++                                 \
  src/kj/parse/char-test.c++                                   \
  src/kj/std/iostream-test.c++                                 \
  src/capnp/capability-test.c++                                \
  src/capnp/membrane-test.c++                                  \
  src/capnp/schema-test.c++                                    \
  src/capnp/schema-loader-test.c++                             \
  src/capnp/schema-parser-test.c++                             \
  src/capnp/dynamic-test.c++                                   \
  src/capnp/stringify-test.c++                                 \
  src/capnp/serialize-async-test.c++                           \
  src/capnp/serialize-text-test.c++                            \
  src/capnp/rpc-test.c++                                       \
  src/capnp/rpc-twoparty-test.c++                              \
  src/capnp/ez-rpc-test.c++                                    \
  src/capnp/compat/json-test.c++                               \
  src/capnp/compiler/lexer-test.c++                            \
  src/capnp/compiler/md5-test.c++
capnp_test_LDADD = libcapnpc.la                                \
  libcapnp-rpc.la                                              \
  libcapnp-json.la                                             \
  libcapnp.la                                                  \
  libkj-async.la                                               \
  libkj-test.la                                                \
  libkj.la

endif !LITE_MODE

capnp_test_CPPFLAGS = -Wno-deprecated-declarations
capnp_test_SOURCES =                                           \
  src/kj/common-test.c++                                       \
  src/kj/memory-test.c++                                       \
  src/kj/refcount-test.c++                                     \
  src/kj/array-test.c++                                        \
  src/kj/string-test.c++                                       \
  src/kj/string-tree-test.c++                                  \
  src/kj/exception-test.c++                                    \
  src/kj/debug-test.c++                                        \
  src/kj/arena-test.c++                                        \
  src/kj/units-test.c++                                        \
  src/kj/tuple-test.c++                                        \
  src/kj/one-of-test.c++                                       \
  src/kj/function-test.c++                                     \
  src/kj/io-test.c++                                           \
  src/kj/mutex-test.c++                                        \
  src/kj/threadlocal-test.c++                                  \
  src/kj/threadlocal-pthread-test.c++                          \
  src/kj/test-test.c++                                         \
  src/capnp/common-test.c++                                    \
  src/capnp/blob-test.c++                                      \
  src/capnp/endian-test.c++                                    \
  src/capnp/endian-fallback-test.c++                           \
  src/capnp/endian-reverse-test.c++                            \
  src/capnp/layout-test.c++                                    \
  src/capnp/any-test.c++                                       \
  src/capnp/message-test.c++                                   \
  src/capnp/encoding-test.c++                                  \
  src/capnp/orphan-test.c++                                    \
  src/capnp/serialize-test.c++                                 \
  src/capnp/serialize-packed-test.c++                          \
  src/capnp/fuzz-test.c++                                      \
  src/capnp/test-util.c++                                      \
  src/capnp/test-util.h                                        \
  $(heavy_tests)
nodist_capnp_test_SOURCES = $(test_capnpc_outputs)

if !LITE_MODE
capnp_evolution_test_LDADD = libcapnpc.la libcapnp.la libkj.la
capnp_evolution_test_SOURCES = src/capnp/compiler/evolution-test.c++
endif !LITE_MODE

if LITE_MODE
TESTS = capnp-test
else !LITE_MODE
TESTS = capnp-test capnp-evolution-test src/capnp/compiler/capnp-test.sh
endif !LITE_MODE
