bin_PROGRAMS+= src/or/tor
noinst_LIBRARIES += \
	src/or/libtor.a
if UNITTESTS_ENABLED
noinst_LIBRARIES += \
	src/or/libtor-testing.a
endif
if COVERAGE_ENABLED
noinst_PROGRAMS+= src/or/tor-cov
endif

if BUILD_NT_SERVICES
tor_platform_source=src/or/ntmain.c
else
tor_platform_source=
endif

EXTRA_DIST+= src/or/ntmain.c src/or/Makefile.nmake

LIBTOR_A_SOURCES = \
	src/or/addressmap.c				\
	src/or/bridges.c				\
	src/or/buffers.c				\
	src/or/channel.c				\
	src/or/channeltls.c				\
	src/or/circpathbias.c				\
	src/or/circuitbuild.c				\
	src/or/circuitlist.c				\
	src/or/circuitmux.c				\
	src/or/circuitmux_ewma.c			\
	src/or/circuitstats.c				\
	src/or/circuituse.c				\
	src/or/command.c				\
	src/or/config.c					\
	src/or/confparse.c				\
	src/or/connection.c				\
	src/or/connection_edge.c			\
	src/or/connection_or.c				\
	src/or/control.c				\
	src/or/cpuworker.c				\
	src/or/dircollate.c				\
	src/or/directory.c				\
	src/or/dirserv.c				\
	src/or/dirvote.c				\
	src/or/dns.c					\
	src/or/dnsserv.c				\
	src/or/fp_pair.c				\
	src/or/geoip.c					\
	src/or/hs_intropoint.c          \
	src/or/hs_circuitmap.c          \
	src/or/hs_service.c             \
	src/or/entrynodes.c				\
	src/or/ext_orport.c				\
	src/or/hibernate.c				\
	src/or/hs_cache.c				\
	src/or/hs_common.c				\
	src/or/hs_descriptor.c				\
	src/or/keypin.c					\
	src/or/main.c					\
	src/or/microdesc.c				\
	src/or/networkstatus.c				\
	src/or/nodelist.c				\
	src/or/onion.c					\
	src/or/onion_fast.c				\
	src/or/onion_tap.c				\
	src/or/shared_random.c			\
	src/or/shared_random_state.c		\
	src/or/transports.c				\
	src/or/parsecommon.c			\
	src/or/periodic.c				\
	src/or/protover.c				\
	src/or/policies.c				\
	src/or/reasons.c				\
	src/or/relay.c					\
	src/or/rendcache.c				\
	src/or/rendclient.c				\
	src/or/rendcommon.c				\
	src/or/rendmid.c				\
	src/or/rendservice.c				\
	src/or/rephist.c				\
	src/or/replaycache.c				\
	src/or/router.c					\
	src/or/routerkeys.c				\
	src/or/routerlist.c				\
	src/or/routerparse.c				\
	src/or/routerset.c				\
	src/or/scheduler.c				\
	src/or/statefile.c				\
	src/or/status.c					\
	src/or/torcert.c				\
	src/or/onion_ntor.c				\
	$(tor_platform_source)

src_or_libtor_a_SOURCES = $(LIBTOR_A_SOURCES)
src_or_libtor_testing_a_SOURCES = $(LIBTOR_A_SOURCES)

src_or_tor_SOURCES = src/or/tor_main.c
AM_CPPFLAGS += -I$(srcdir)/src/or -Isrc/or

src/or/tor_main.$(OBJEXT) \
  src/or/src_or_tor_cov-tor_main.$(OBJEXT): micro-revision.i

AM_CPPFLAGS += -DSHARE_DATADIR="\"$(datadir)\""		\
		-DLOCALSTATEDIR="\"$(localstatedir)\""	\
		-DBINDIR="\"$(bindir)\""

src_or_libtor_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
src_or_libtor_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)

# -L flags need to go in LDFLAGS. -l flags need to go in LDADD.
# This seems to matter nowhere but on windows, but I assure you that it
# matters a lot there, and is quite hard to debug if you forget to do it.


src_or_tor_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ @TOR_LDFLAGS_libevent@
src_or_tor_LDADD = src/or/libtor.a src/common/libor.a src/common/libor-ctime.a \
	src/common/libor-crypto.a $(LIBKECCAK_TINY) $(LIBDONNA) \
	src/common/libor-event.a src/trunnel/libor-trunnel.a \
	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ \
	@TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@

if COVERAGE_ENABLED
src_or_tor_cov_SOURCES = src/or/tor_main.c
src_or_tor_cov_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
src_or_tor_cov_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
src_or_tor_cov_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ @TOR_LDFLAGS_libevent@
src_or_tor_cov_LDADD = src/or/libtor-testing.a src/common/libor-testing.a \
	src/common/libor-ctime-testing.a \
	src/common/libor-crypto-testing.a $(LIBKECCAK_TINY) $(LIBDONNA) \
	src/common/libor-event-testing.a src/trunnel/libor-trunnel-testing.a \
	@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ \
	@TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@
endif

ORHEADERS = \
	src/or/addressmap.h				\
	src/or/bridges.h				\
	src/or/buffers.h				\
	src/or/channel.h				\
	src/or/channeltls.h				\
	src/or/circpathbias.h				\
	src/or/circuitbuild.h				\
	src/or/circuitlist.h				\
	src/or/circuitmux.h				\
	src/or/circuitmux_ewma.h			\
	src/or/circuitstats.h				\
	src/or/circuituse.h				\
	src/or/command.h				\
	src/or/config.h					\
	src/or/confparse.h				\
	src/or/connection.h				\
	src/or/connection_edge.h			\
	src/or/connection_or.h				\
	src/or/control.h				\
	src/or/cpuworker.h				\
	src/or/dircollate.h				\
	src/or/directory.h				\
	src/or/dirserv.h				\
	src/or/dirvote.h				\
	src/or/dns.h					\
	src/or/dns_structs.h				\
	src/or/dnsserv.h				\
	src/or/ext_orport.h				\
	src/or/fallback_dirs.inc			\
	src/or/fp_pair.h				\
	src/or/geoip.h					\
	src/or/entrynodes.h				\
	src/or/hibernate.h				\
	src/or/hs_cache.h				\
	src/or/hs_common.h				\
	src/or/hs_descriptor.h				\
	src/or/hs_intropoint.h          \
	src/or/hs_circuitmap.h          \
	src/or/hs_service.h             \
	src/or/keypin.h					\
	src/or/main.h					\
	src/or/microdesc.h				\
	src/or/networkstatus.h				\
	src/or/nodelist.h				\
	src/or/ntmain.h					\
	src/or/onion.h					\
	src/or/onion_fast.h				\
	src/or/onion_ntor.h				\
	src/or/onion_tap.h				\
	src/or/or.h					\
	src/or/shared_random.h			\
	src/or/shared_random_state.h		\
	src/or/transports.h				\
	src/or/parsecommon.h			\
	src/or/periodic.h				\
	src/or/policies.h				\
	src/or/protover.h				\
	src/or/reasons.h				\
	src/or/relay.h					\
	src/or/rendcache.h				\
	src/or/rendclient.h				\
	src/or/rendcommon.h				\
	src/or/rendmid.h				\
	src/or/rendservice.h				\
	src/or/rephist.h				\
	src/or/replaycache.h				\
	src/or/router.h					\
	src/or/routerkeys.h				\
	src/or/routerlist.h				\
	src/or/routerkeys.h				\
	src/or/routerset.h				\
	src/or/routerparse.h				\
	src/or/scheduler.h				\
	src/or/statefile.h				\
	src/or/status.h					\
	src/or/torcert.h

noinst_HEADERS+= $(ORHEADERS) micro-revision.i

micro-revision.i: FORCE
	$(AM_V_at)rm -f micro-revision.tmp; \
	if test -r "$(top_srcdir)/.git" && \
			test -x "`which git 2>&1;true`"; then \
		HASH="`cd "$(top_srcdir)" && git rev-parse --short=16 HEAD`"; \
		echo \"$$HASH\" > micro-revision.tmp; \
	fi; \
	if test ! -f micro-revision.tmp; then \
		if test ! -f micro-revision.i; then \
			echo '""' > micro-revision.i; \
		fi; \
	elif test ! -f micro-revision.i || \
			test x"`cat micro-revision.tmp`" != x"`cat micro-revision.i`"; then \
		mv micro-revision.tmp micro-revision.i; \
	fi; \
	rm -f micro-revision.tmp; \
	true

CLEANFILES+= micro-revision.i src/or/micro-revision.i micro-revision.tmp

FORCE:
