############################################################################
# Tino Reichardt <milky dash squidwall at mcmilk dot de>
#
# 1. type 'make' for building
# 2. type 'make install' for installing
# 3. type 'make install-cache'
#    - for installing an empty sqlite3 database (cache.db)
#    - only needed, if sqlite support is wanted
############################################################################

DIET	= diet
X	= .diet

LIBOWFAT= ../libowfat$(X)

# destination of squidwall and its manpage
SBINDIR	= ${DESTDIR}/usr/sbin
MAN8DIR	= ${DESTDIR}/usr/share/man/man8

# your squiduser or squidgroup needs read/write access here:
LOGDIR	= ${DESTDIR}/var/log/squid
CACHEDIR= ${DESTDIR}/var/cache/squidwall

CC	= $(DIET) gcc
CFLAGS	= -Os -Wall -pipe -I$(LIBOWFAT)
CFLAGS += -pthread -D_REENTRANT
LDFLAGS	= $(LIBOWFAT)/libowfat.a -lpthread

############################################################################
# uncomment the following two lines for experimental squidwall caching
#SQLITE3= ../sqlite$(X)
#CFLAGS  += -DWANT_SQLITE -I$(SQLITE3)
#LDFLAGS += $(SQLITE3)/.libs/libsqlite3.a
############################################################################

# extraflags
CFLAGS += -W
#CFLAGS += -g -pg
#CFLAGS += -Wpointer-arith
#CFLAGS += -Wswitch
#CFLAGS += -Wchar-subscripts
#CFLAGS += -Wmissing-declarations -Wredundant-decls -Wunused -Wmissing-prototypes

# strip
STRIP	= strip -R .note -R .comment
STRIP	= echo

SRC	= $(shell ls *.c)
OBJS	= $(SRC:.c=.o)

#OBJS	= cache_content.o cache_init.o cache_sqlite3.o case_strstr.o \
#	  check_banner.o check_blist.o check_clamav.o check_cont.o \
#	  check_globals.o check_host.o check_redirect.o check_user.o \
#	  check_wlist.o control_readint.o control_readline.o debug.o env.o \
#	  fmt_blob.o hextab.o log.o log_info.o log_panic.o md5.o memcache.o \
#	  read_acls.o read_controls.o read_filters.o redir_site.o scan_url.o \
#	  sha1.o squidwall.o stralloc_cat_uint.o timestamp.o

PRGS	= squidwall

all:	dep $(PRGS)
setup:	install
it:	all
again:	all install

squidwall: $(OBJS)
	$(CC) -o $@ $(OBJS) $(LDFLAGS)
	$(STRIP) $@

dep:
	$(CC) $(CFLAGS) -MM *.c > .depend

clean:
	rm -f $(OBJS) $(PRGS)

.c.o:
	$(CC) $(CFLAGS) -c $< -o $@

install:
	mkdir -p $(SBINDIR) $(MAN8DIR) $(LOGDIR)
	rm -f $(SBINDIR)/squidwall && cp -f squidwall $(SBINDIR)
	rm -f $(MAN8DIR)/squidwall.8 && cp -f squidwall.8 $(MAN8DIR)
	touch $(LOGDIR)/squidwall.log
	@echo
	@echo Please adjust the permissions for the log directory by hand:
	@echo chown -R proxyuser:proxygroup $(LOGDIR)
	@echo
	@echo for help, contact the mailinglist \"squidwall at mcmilk dot de\"

install-cache:
	mkdir -p $(CACHEDIR)
	touch $(CACHEDIR)/cache.db
	@echo
	@echo Please adjust the permissions for the cache directory by hand:
	@echo chown -R proxyuser:webgroup $(CACHEDIR)
	@echo chmod 660 $(CACHEDIR)/cache.db
	@echo
	@echo for help, contact the mailinglist \"squidwall at mcmilk dot de\"

include .depend
