PROG	=	tarsnap
SRCS	=	bsdtar.c cmdline.c getdate.c matching.c read.c siginfo.c subst.c tree.c util.c write.c
MAN1	=	tarsnap.1
MAN5	=	tarsnap.conf.5
WARNS	?=	6
CFLAGS	+=	-DUSERAGENT=\"${PROG}-${TARVERSION}\"
CFLAGS	+=	-DPACKAGE_VERSION=\"${TARVERSION}\"
CFLAGS	+=	-DTSSERVER=\"${TSSERVER}\"
CFLAGS	+=	-DPLATFORM_CONFIG_H=\"config_freebsd.h\"
CFLAGS	+=	-I ${.CURDIR}

# Install sample configuration file
FILESGROUPS	+=	CONFIG
CONFIGDIR	?=	/usr/local/etc
CONFIG		=	tarsnap.conf.sample

# Location of system tarsnap configuration file
CFLAGS	+=	-DETC_TARSNAP_CONF=\"${CONFIGDIR}/tarsnap.conf\"

# Generate tarsnap.1 and tarsnap.conf.5 via sed.
CLEANFILES	+=	tarsnap.1 tarsnap.conf.5
tarsnap.1:	bsdtar.1
	cat bsdtar.1 |					\
	    sed -e 's|@CONFIGDIR@|${CONFIGDIR}|g' > tarsnap.1
tarsnap.conf.5:	tarsnap.conf.5.in
	cat tarsnap.conf.5.in |					\
	    sed -e 's|@CONFIGDIR@|${CONFIGDIR}|g' > tarsnap.conf.5

# Use our own version of libarchive
.if defined(PROFILE)
LDADD	+=	../libarchive/libarchive_p.a
${PROG}	:	../libarchive/libarchive_p.a
.else
LDADD	+=	../libarchive/libarchive.a
${PROG}	:	../libarchive/libarchive.a
.endif
CFLAGS	+=	-I ${.OBJDIR}/../libarchive

# Tarsnap library code
.if defined(PROFILE)
LDADD	+=	../lib/libtarsnap_p.a
${PROG}	:	../lib/libtarsnap_p.a
.else
LDADD	+=	../lib/libtarsnap.a
${PROG}	:	../lib/libtarsnap.a
.endif

# Other libraries used
LDADD	+=	-lz -lbz2 -lcrypto

# Code which interfaces between multiple layers.
.PATH.c	:	./glue
SRCS	+=	archive_multitape.c
SRCS	+=	tape.c
CFLAGS	+=	-I ./glue

# Chunkification cache
.PATH.c	:	./ccache
SRCS	+=	ccache_entry.c
SRCS	+=	ccache_read.c
SRCS	+=	ccache_write.c
CFLAGS	+=	-I ./ccache

# Multitape code
.PATH.c	:	./multitape
SRCS	+=	chunkify.c
SRCS	+=	multitape_write.c
SRCS	+=	multitape_read.c
SRCS	+=	multitape_stats.c
SRCS	+=	multitape_delete.c
SRCS	+=	multitape_recover.c
SRCS	+=	multitape_fsck.c
SRCS	+=	multitape_nuke.c
SRCS	+=	multitape_chunkiter.c
SRCS	+=	multitape_metadata.c
SRCS	+=	multitape_metaindex.c
SRCS	+=	multitape_transaction.c
CFLAGS	+=	-I ./multitape

# Chunk layer
.PATH.c	:	./chunks
SRCS	+=	chunks_write.c
SRCS	+=	chunks_read.c
SRCS	+=	chunks_stats.c
SRCS	+=	chunks_delete.c 
SRCS	+=	chunks_transaction.c
SRCS	+=	chunks_stats_internal.c
SRCS	+=	chunks_directory.c
CFLAGS	+=	-I ./chunks

# Storage layer
.PATH.c	:	./storage
SRCS	+=	storage_write.c
SRCS	+=	storage_read.c
SRCS	+=	storage_delete.c
SRCS	+=	storage_directory.c
SRCS	+=	storage_transaction.c
CFLAGS	+=	-I ./storage

# Client-server protocol layer
CFLAGS	+=	-I ../lib/netpacket

# Packet transport layer
CFLAGS	+=	-I ../lib/netproto

# Network layer
CFLAGS	+=	-I ../lib/network

# Data structures
CFLAGS	+=	-I ../lib/datastruct

# Cryptographic code
CFLAGS	+=	-I ../lib/crypto

# Keyfile handling code
CFLAGS	+=	-I ../lib/keyfile

# Utility code
CFLAGS	+=	-I ../lib/util

# Compiler flags for profiling
.if defined(PROFILE)
CFLAGS	+=	-g -pg -DPROFILE
.endif

# Debugging flags
.if defined(DEBUG)
CFLAGS	+=	-g
CFLAGS	+=	-DDEBUG
CFLAGS	+=	-O1
.endif
.if defined(DEBUG_SELECTSTATS)
CFLAGS	+=	-DDEBUG_SELECTSTATS
.endif

.include <bsd.prog.mk>
