# Makefile for mohawk

# for coverity
# cov-configure --compiler /usr/bin/cc --comptype clangcc -- -O2 -O2 -std=gnu99 -fstack-protector

PROG= mohawk
SRCS= main.c parse.y token.l dump.c
LDADD= -lutil
CFLAGS+= -W -Wall -Werror
YFLAGS= -d
TODAY!= date '+%Y%m%d'
SUBDIR= examples man5 man8
WORKDIR!= basename ${.CURDIR}
NO_OBJ=
CLEANFILES+= parse.h typescript *.core .depend*
MAN=

USE_DEBUG?= 0
.if ${USE_DEBUG}
WARNS?= 6
CFLAGS+= -O0 -g -DUSE_DEBUG
.else
CFLAGS+= -O2
.endif

.include "Makefile.inc"
CFLAGS+= -DMOHAWK_VERSION=\"${MOHAWK_VERSION}\"

EXCLUDE= -type f -and -not -path '*_FOSSIL_*' -and -not -name '*.swp'
tgz: clean
	(cd .. && find ${WORKDIR}/ ${EXCLUDE} -print | tar czvf ${WORKDIR}-${TODAY}.tgz -I -)

upload: tgz
	(cp ../${WORKDIR}-${TODAY}.tgz /tmp && cd /tmp && ln -f ${WORKDIR}-${TODAY}.tgz ${WORKDIR}-current.tgz)

prereq:
	@echo "CHROOT=${CHROOT}" > regression/vars.inc
	@echo "UNPRIVILIGED_PORT=${UNPRIVILIGED_PORT}" >> regression/vars.inc
	@mkdir -p ${CHROOT}/document_root
	@mkdir -p ${CHROOT}/empty
	@mkdir -p ${CHROOT}/more_secure
	@mkdir -p ${CHROOT}/secure
	@mkdir -p ${CHROOT}/virtual/default
	@mkdir -p ${CHROOT}/virtual/default/admin
	@mkdir -p ${CHROOT}/virtual/default/root
	@mkdir -p ${CHROOT}/virtual/secure.example.com
	@mkdir -p ${CHROOT}/virtual/no_secure.example.com
	@mkdir -p ${CHROOT}/virtual/w1.example.com
	@mkdir -p ${CHROOT}/virtual/w2.example.com
	@mkdir -p ${CHROOT}/virtual/www
	@mkdir -p ${CHROOT}/etc
	@mkdir -p ${CHROOT}/\ with\ space\ s
	@cp prereq/index.html ${CHROOT}/document_root/
	@cp prereq/print_env.sh ${CHROOT}/document_root/
	@cp -r prereq/utf8 ${CHROOT}/
	@cp prereq/index.html ${CHROOT}/virtual/default/
	@cp prereq/private.html ${CHROOT}/virtual/default/admin/
	@cp prereq/private.html ${CHROOT}/virtual/default/root/
	@cp prereq/secure.html ${CHROOT}/virtual/secure.example.com/
	@cp prereq/no_secure.html ${CHROOT}/virtual/no_secure.example.com/
	@./chroot.sh /bin/sh ${CHROOT}
	@./chroot.sh /usr/bin/env ${CHROOT}
	@/bin/sh ./mhtpasswd.sh -b -c ${CHROOT}/secure/.htpasswd foo bar
	@/bin/sh ./mhtpasswd.sh -b -c ${CHROOT}/more_secure/.htpasswd foo barbar

.PHONY: prereq

.if ${OPSYS} == "NetBSD"
.include <bsd.subdir.mk>
.endif
.include <bsd.prog.mk>
