# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
# 
# The Original Code is Freedom code.
# 
# The Initial Developer of the Original Code is Zero-Knowledge Systems,
# Inc.  Portions created by Zero-Knowledge are Copyright (C) 2000
# Zero-Knowledge Systems, Inc.  All Rights Reserved.
# 
# Contributor(s):

# 
# Default target
#

default:: exes

# Get the variables definition
include $(ZK_ROOT)/freedom/makefiles/Makefile.vars

# Override and define new variables
ZK_INCS := \
	-I$(ZK_CWDDIR)/..$(/)src \
	-I$(ZK_FREEDOM_ROOT)libs$(/)frent$(/)include \
	-I$(ZK_FREEDOM_ROOT)libs$(/)frsec$(/)include \
	-I$(ZK_FREEDOM_ROOT)libs$(/)frcrypt$(/)include \
	-I$(ZK_ROOT)libzkrand$(/)include \
	-I$(ZK_FREEDOM_ROOT)libs$(/)frmailaccount$(/)include \
	-I$(ZK_FREEDOM_ROOT)libs$(/)frmailblocklist$(/)include \
	-I$(ZK_ROOT)libzk$(/)include \
	-I$(ZK_ROOT)lib3rd$(/)openssl$(/)include \
	-I. \
	$(ZK_INCS) \
	$(END_OF_LIST)

ZK_ALL_SRCFILES := \
	auth-common.cpp \
	qmail-getpw.cpp \
	entry.cpp \
	checkpassword.cpp \
	ensure-user.cpp \
	genpasswd.cpp \
	genMacKey.cpp \
	examine-mailcert.cpp \
	$(END_OF_LIST)

ZK_CPUBEXES_ERROR := \
	$(END_OF_LIST)

ZK_CXXPUBEXES := \
	checkpassword \
	qmail-getpw \
	ensure-user \
	genpasswd \
	genMacKey \
	examine-mailcert \
	$(END_OF_LIST)

PKG_EXES = $(ZK_CXXPUBEXES) 

ZK_LDFLAGS += -L$(ZK_FREEDOM_ROOT)/popmail$(/)cdb

# Get the target rules
include $(ZK_ROOT)/freedom/makefiles/Makefile.targs

# Add new targets or complement default target using :: rules
package:: default
	@$(ZK_SCRIPTDIR)/promoteFiles.pl $(ZK_BUILDDIR_PUBBIN) \
	$(ZK_PKG_QMAIL_ROOT)/bin $(PKG_EXES) 

# dependencies

$(ZK_BUILDDIR_PUBBIN)/checkpassword: $(addprefix $(ZK_BUILDDIR_PROJ)/, \
	auth-common.o checkpassword.o) \
	-lfrmailauth -lfrmailaccount \
	-lfrmailblocklist_server -lfrmailblocklist_client \
	-lcdb -lcdbbuffer -lcdballoc -lcdbbyte -lcdbunix \
	-lfrcrypt -lfrent -lzkrand -lzk -lcrypto

$(ZK_BUILDDIR_PUBBIN)/genpasswd: $(addprefix $(ZK_BUILDDIR_PROJ)/, \
	auth-common.o genpasswd.o) \
	-lfrmailauth -lfrcrypt -lzkrand  -lfrent -lzk -lcrypto -lfrmailaccount

$(ZK_BUILDDIR_PUBBIN)/ensure-user: $(addprefix $(ZK_BUILDDIR_PROJ)/, \
	auth-common.o entry.o ensure-user.o) \
	-lfrmailauth -lfrcrypt -lzkrand  -lfrent -lzk -lcrypto -lfrmailaccount

$(ZK_BUILDDIR_PUBBIN)/qmail-getpw: $(addprefix $(ZK_BUILDDIR_PROJ)/, \
	auth-common.o entry.o qmail-getpw.o)  \
	-lfrmailauth -lfrcrypt -lzkrand  -lfrent -lzk -lcrypto -lfrmailaccount

$(ZK_BUILDDIR_PUBBIN)/genMacKey: $(addprefix $(ZK_BUILDDIR_PROJ)/, \
	genMacKey.o)  \
	-lfrmailauth -lfrcrypt -lzkrand  -lfrent -lzk -lcrypto 

$(ZK_BUILDDIR_PUBBIN)/examine-mailcert: $(addprefix $(ZK_BUILDDIR_PROJ)/, \
	auth-common.o examine-mailcert.o) \
	-lfrmailauth -lfrcrypt -lzkrand  -lfrent -lzk -lcrypto -lfrmailaccount

$(ZK_FREEDOM_ROOT)/popmail/cdb/libcdb.a \
$(ZK_FREEDOM_ROOT)/popmail/cdb/libcdbbuffer.a \
$(ZK_FREEDOM_ROOT)/popmail/cdb/libcdballoc.a \
$(ZK_FREEDOM_ROOT)/popmail/cdb/libcdbbyte.a \
$(ZK_FREEDOM_ROOT)/popmail/cdb/libcdbunix.a:
	cd $(ZK_FREEDOM_ROOT)/popmail/cdb \
	&& $(MAKE) \
	&& /bin/rm -f libcdb* \
	&& ln -sf cdb.a libcdb.a \
	&& ln -sf buffer.a libcdbbuffer.a \
	&& ln -sf alloc.a libcdballoc.a \
	&& ln -sf byte.a libcdbbyte.a \
	&& ln -sf unix.a libcdbunix.a

# Copy files to the floppy disk that will store the
# shared, secret MAC key.  Ensure the disk is mounted
# before doing this.

mkfloppy:
	set -eu ; fl=/mnt/floppy ; \
	cp frgenshmackey $$fl/ ; \
	cp frcpyshmackey $$fl/ ; \
	cp frshmackeyfns.sh $$fl/.fns.sh ; \
	chmod 555 $$fl/frgenshmackey $$fl/frcpyshmackey ; \
	chmod 444 $$fl/.fns.sh
