# -*- make -*-
#
# Makefile, overall Makefile for CVS sources.
#
# @configure_input@
# 
# $Id: Makefile.in,v 1.15 2002/10/24 19:26:49 jjminer Exp $

@SET_MAKE@


MAKE_LOGIN=@MAKE_LOGIN@$(MAKE)
MAKE_APACHE=@MAKE_APACHE@$(MAKE)

CC=@CC@

prefix=@prefix@
srcdir=@srcdir@
builddir=@builddir@

PUBCOOKIE_DIR=$(prefix)
KEY_DIR=$(PUBCOOKIE_DIR)/keys
TEMPLATE_DIR=$(PUBCOOKIE_DIR)/login_templates
LOGIN_DIR=$(PUBCOOKIE_DIR)/login

INSTALL=@INSTALL@ -p -b
INSTALL_BIN=$(INSTALL) -m 755
INSTALL_OTHER=$(INSTALL) -m 644
INSTALL_DIR=$(INSTALL) -d

RM=@RM@
FORCE_RM=$(RM) -f
RECURSIVE_FORCE_RM=$(RM) -rf
CP=@CP@
RECURSIVE_CP=$(CP) -r
MKDIR=@MKDIR@
MV=@MV@
AWK=@AWK@
SED=@SED@
TAR=@TAR@
GZIP=@GZIP@

LIBS=@LIBS@
CPPFLAGS=@CPPFLAGS@ @DEFS@ -I$(builddir)/src
CFLAGS=@CFLAGS@ $(CPPFLAGS)
LDFLAGS=@LDFLAGS@ $(LIBS)
LOGINLIBS=@LOGINLIBS@ -lcgic

APXS=@APXS@

CONFIGURE_TMP_FILES=$(builddir)/config.status \
					$(builddir)/config.log \
					$(builddir)/src/config.h \
					$(builddir)/Makefile \
					$(builddir)/src/pbc_path.h \
					$(builddir)/stamp-h

CONFIGURE_TMP_DIRS=$(srcdir)/autom4te.cache

CONFIGURE_FILES=$(srcdir)/configure \
				$(srcdir)/configure.ac \
				$(srcdir)/Makefile.in \
				$(srcdir)/install-sh \
				$(srcdir)/stamp-h.in

SRC_CONFIGURE_FILES=$(srcdir)/src/config.h.in \
					$(srcdir)/src/pbc_path.h.in

TEST_SRC=$(srcdir)/src/pbc_create.c \
		 $(srcdir)/src/pbc_verify.c \
		 $(srcdir)/src/candv.c \
		 $(srcdir)/src/dtest.c \
		 $(srcdir)/src/make_crypted_blob.c \
		 $(srcdir)/src/check_crypted_blob.c

TEST_FILES=pbc_create pbc_verify candv dtest make_crypted_blob check_crypted_blob \
		   verify what_is_my_ip

UTIL_SRC=$(srcdir)/src/pbc_key_local.c \
		 $(srcdir)/src/pbc_key_generic.c \
		 $(srcdir)/src/keyserver.c \
		 $(srcdir)/src/keyclient.c

VERIFIERS=$(builddir)/src/verify_alwaystrue.o \
		  $(builddir)/src/verify_kerberos4.o \
		  $(builddir)/src/verify_kerberos5.o \
		  $(builddir)/src/verify_shadow.o \
		  $(builddir)/src/verify_ldap.o \
		  $(builddir)/src/verify.o

VERIFY_SRC=$(srcdir)/src/verify.c \
		   $(srcdir)/src/verify_alwaystrue.c \
		   $(srcdir)/src/verify_kerberos4.c \
		   $(srcdir)/src/verify_kerberos5.c \
		   $(srcdir)/src/verify_shadow.c \
		   $(srcdir)/src/verify_ldap.c

FLAVOR_SRC=$(srcdir)/src/flavor.c \
		   $(srcdir)/src/flavor_basic.c \
		   $(srcdir)/src/flavor_getcred.c

INDEX_OBJ=$(builddir)/src/index.cgi.o $(builddir)/src/flavor.o \
		  $(builddir)/src/flavor_basic.o $(builddir)/src/flavor_getcred.o \
		  $(VERIFIERS)

INDEX_FILES=$(builddir)/index.cgi

INDEX_SRC=$(srcdir)/src/index.cgi.c \
		  $(VERIFY_SRC) \
		  $(FLAVOR_SRC)

KEYMGT_FILES=keyclient keyserver

KEYMGT_SRC=$(srcdir)/src/keyclient.c $(srcdir)/src/keyserver.c

INDEX_HEAD=$(srcdir)/src/index.cgi.h \
		   $(srcdir)/src/flavor.h \
		   $(srcdir)/src/verify.h

LIB_HEAD=$(srcdir)/src/pbc_config.h \
		 $(srcdir)/src/pubcookie.h \
		 $(srcdir)/src/libpubcookie.h \
		 $(srcdir)/src/pbc_version.h \
		 $(srcdir)/src/pbc_myconfig.h \
		 $(srcdir)/src/security.h \
		 $(srcdir)/src/pbc_logging.h \
		 $(srcdir)/src/strlcpy.h

LIB_SRC=$(srcdir)/src/libpubcookie.c \
		$(srcdir)/src/base64.c \
		$(srcdir)/src/strlcpy.c \
		$(srcdir)/src/pbc_myconfig.c \
		$(srcdir)/src/security_legacy.c \
		$(srcdir)/src/pbc_logging.c \
		$(srcdir)/src/capture_cmd_output.c

LIB_OBJ=$(builddir)/src/libpubcookie.o \
		$(builddir)/src/base64.o \
		$(builddir)/src/strlcpy.o \
		$(builddir)/src/pbc_myconfig.o \
		$(builddir)/src/security_legacy.o \
		$(builddir)/src/pbc_logging.o \
		$(builddir)/src/capture_cmd_output.o

MOD_SRC=$(srcdir)/src/mod_pubcookie.c

LIB_TESTS=base64 pbc_myconfig myconf

LOGIN_TEMPLATES=$(srcdir)/src/login_templates.generic/login_part1 \
			    $(srcdir)/src/login_templates.generic/login_part2 \
			    $(srcdir)/src/login_templates.generic/nonpost_redirect \
			    $(srcdir)/src/login_templates.generic/notok_part1 \
			    $(srcdir)/src/login_templates.generic/notok_part2 \
				$(srcdir)/src/login_templates.generic/logout_postscript_still_weblogin \
				$(srcdir)/src/login_templates.generic/logout_still_weblogin \
				$(srcdir)/src/login_templates.generic/notok_need_ssl \
				$(srcdir)/src/login_templates.generic/status_part1 \
				$(srcdir)/src/login_templates.generic/status_part2 \
				$(srcdir)/src/login_templates.generic/logout_time_remaining

DOCS=$(srcdir)/doc/CHANGES.login.txt \
	 $(srcdir)/doc/CHANGES.mod_pubcookie.txt \
	 $(srcdir)/doc/config.html \
	 $(srcdir)/doc/CREDITS.txt \
	 $(srcdir)/doc/LICENSE.txt \
	 $(srcdir)/doc/NEW_SITE.txt \
	 $(srcdir)/doc/README.txt \
	 $(srcdir)/doc/config.sample \
	 $(srcdir)/doc/install-mod_pubcookie-3.0.html \
	 $(srcdir)/doc/mod_pubcookie-directives.html \
	 $(srcdir)/doc/mod_pubcookie_dev_notes.txt \
	 $(srcdir)/doc/pubcookie_style_guide.txt \
	 $(srcdir)/doc/install-login.html

CGIC_FILES=$(srcdir)/cgic/Makefile.in \
		   $(srcdir)/cgic/capture.c \
		   $(srcdir)/cgic/cgic.c \
		   $(srcdir)/cgic/cgic.h \
		   $(srcdir)/cgic/cgic.html \
		   $(srcdir)/cgic/cgic.txt \
		   $(srcdir)/cgic/cgictest.c \
		   $(srcdir)/cgic/license.txt \
		   $(srcdir)/cgic/readme.txt \
		   $(srcdir)/cgic/support.txt \
		   $(srcdir)/cgic/testform.html \
		   $(srcdir)/cgic/CHANGES

VERSION := `$(AWK) -F\" '/PBC_VERSION_STRING/{print $$2}' $(srcdir)/src/pbc_version.h | $(SED) "s/ /-/g" `

# " ` (Satisfying Vim)

BASENAME := pubcookie
DISTNAME := $(BASENAME)-$(VERSION)

.PHONY: all clean install dist login_server apache_module ver

all: $(builddir)/Makefile @login_server@ @apache_module@

$(srcdir)/configure: $(srcdir)/configure.ac
	cd $(srcdir) && $(RECURSIVE_FORCE_RM) $(CONFIGURE_TMP_DIRS)
	cd $(srcdir) && autoconf

# autoheader might not change config.h.in, so touch a stamp file.
$(srcdir)/src/config.h.in: $(srcdir)/stamp-h.in
$(srcdir)/stamp-h.in: $(srcdir)/configure.ac
	cd $(srcdir) && autoheader
	echo timestamp > $(srcdir)/stamp-h.in

$(builddir)/src/config.h: $(builddir)/stamp-h
$(builddir)/stamp-h: $(srcdir)/src/config.h.in $(builddir)/config.status
	$(builddir)/config.status

$(builddir)/Makefile: $(srcdir)/Makefile.in $(builddir)/config.status
	$(builddir)/config.status

$(builddir)/config.status: $(srcdir)/configure
	$(builddir)/config.status --recheck

$(builddir)/src/%.o: $(srcdir)/src/%.c
	$(CC) $(CFLAGS) -o $@ -c $<

login_server: l_ver $(INDEX_FILES) $(KEYMGT_FILES)

l_ver:
	@echo Making $(DISTNAME) login server;

candv:	$(builddir)/src/candv.o $(LIB_OBJ)
	$(CC) $(CFLAGS) -o $@ $(builddir)/src/candv.o $(LIB_OBJ) $(LDFLAGS)

dtest:	$(builddir)/src/dtest.o $(LIB_OBJ)
	$(CC) $(CFLAGS) -o $@ $(builddir)/src/dtest.o $(LIB_OBJ) $(LDFLAGS)

vtest: $(VERIFIERS) $(LIB_OBJ)
	$(CC) ${CFLAGS} -DTEST_VERIFY -o $@ $(VERIFIERS) $(LIB_OBJ) $(LDFLAGS) $(EXTRA_LIBS)

ntmpl_test: $(srcdir)/src/ntmpl.c $(LIB_OBJ)
	$(CC) ${CFLAGS} -DTEST_NTMPL -o $@ $(srcdir)/src/ntmpl.c $(LIB_OBJ) $(LDFLAGS) $(EXTRA_LIBS)

check_crypted_blob:	$(builddir)/src/check_crypted_blob.o $(LIB_OBJ)
	$(CC) ${CFLAGS} -o $@ $(builddir)/src/check_crypted_blob.o $(LIB_OBJ) $(LDFLAGS)

pbc_create:	$(builddir)/src/pbc_create.o $(LIB_OBJ)
	$(CC) ${CFLAGS} -o $@ $(builddir)/src/pbc_create.o $(LIB_OBJ) $(LDFLAGS)

pbc_verify:	$(builddir)/src/pbc_verify.o $(LIB_OBJ)
	$(CC) ${CFLAGS} -o $@ $(builddir)/src/pbc_verify.o $(LIB_OBJ) $(LDFLAGS)

pbc_key_generic: $(builddir)/src/pbc_key_generic.o $(LIB_OBJ)
	$(CC) ${CFLAGS} -o $@ $(builddir)/src/pbc_key_generic.o $(LIB_OBJ) $(LDFLAGS)

pbc_key_local: $(builddir)/src/pbc_key_local.o $(LIB_OBJ)
	$(CC) ${CFLAGS} -o $@ $(builddir)/src/pbc_key_local.o $(LIB_OBJ) $(LDFLAGS)

make_crypted_blob: $(builddir)/src/make_crypted_blob.o $(LIB_OBJ)
	$(CC) ${CFLAGS} -o $@ $(builddir)/src/make_crypted_blob.o $(LIB_OBJ) $(LDFLAGS)

what_is_my_ip: $(builddir)/src/what_is_my_ip.o $(LIB_OBJ)
	$(CC) ${CFLAGS} -o $@ $(builddir)/src/what_is_my_ip.o $(LIB_OBJ) $(LDFLAGS)

index.cgi: $(builddir)/cgic/libcgic.a $(LIB_OBJ) $(INDEX_OBJ)
	$(CC) ${CFLAGS} -o $@ $(INDEX_OBJ) $(LIB_OBJ) $(LDFLAGS) $(LOGINLIBS)

$(builddir)/cgic/libcgic.a:
	(cd $(builddir)/cgic; make)

$(INDEX_OBJ): $(LIB_HEAD) $(INDEX_HEAD) $(builddir)/src/config.h

keyserver: $(builddir)/src/keyserver.o $(LIB_OBJ)
	$(CC) $(CFLAGS) -o $@ $(builddir)/src/keyserver.o $(LIB_OBJ) $(LDFLAGS) $(LIBS)

keyclient: $(builddir)/src/keyclient.o $(LIB_OBJ)
	$(CC) $(CFLAGS) -o $@ $(builddir)/src/keyclient.o $(LIB_OBJ) $(LDFLAGS) $(LIBS)

# Installation Targets

install: $(KEY_DIR) @install_login@ @install_apache@

install-login: $(LOGIN_DIR) $(TEMPLATE_DIR) $(LOGIN_TEMPLATES) login_server
	$(INSTALL_BIN) $(KEYMGT_FILES) $(PUBCOOKIE_DIR)
	$(INSTALL_BIN) $(INDEX_FILES) $(LOGIN_DIR)
	$(INSTALL_OTHER) $(LOGIN_TEMPLATES) $(TEMPLATE_DIR)

install-apache: apache_module
	$(APXS) -i -a -n pubcookie mod_pubcookie.so

$(PUBCOOKIE_DIR):
	$(INSTALL_DIR) $(PUBCOOKIE_DIR)

$(KEY_DIR): $(PUBCOOKIE_DIR)
	$(INSTALL_DIR) $(KEY_DIR)

$(LOGIN_DIR): $(PUBCOOKIE_DIR)
	$(INSTALL_DIR) $(LOGIN_DIR)

$(TEMPLATE_DIR): $(PUBCOOKIE_DIR)
	$(INSTALL_DIR) $(TEMPLATE_DIR)

$(LIB_OBJ): $(LIB_HEAD)

# Test Targets

test:: verify
	./verify alwaystrue nobody nothing

verify: $(VERIFY_SRC) $(LIB_OBJ) $(builddir)/cgic/libcgic.a
	$(CC) $(CFLAGS) -g -o verify -DTEST_VERIFY $(VERIFY_SRC) $(LDFLAGS) $(LOGINLIBS) $(LIB_OBJ)

tests: $(TEST_FILES)

test:: base64 myconf pbc_myconfig
	cat base64 | ./base64
	./pbc_myconfig

myconf:
	echo "foo: hi hi2" > myconf

base64: $(srcdir)/src/base64.c
	$(CC) $(CFLAGS) -o base64 -DTEST_BASE64 $(srcdir)/src/base64.c $(LDFLAGS) $(LOGINLIBS)

pbc_myconfig: $(srcdir)/src/pbc_myconfig.c
	$(CC) $(CFLAGS) -o pbc_myconfig -DTEST_MYCONFIG $(srcdir)/src/pbc_myconfig.c $(LDFLAGS) $(LOGINLIBS)

# Cleanup targets

clean::
	-$(FORCE_RM) $(builddir)/*.so $(builddir)/src/*.so $(builddir)/so_locations
	-$(FORCE_RM) $(INDEX_FILES) $(builddir)/*.o $(builddir)/src/*.o
	-$(FORCE_RM) $(TEST_FILES) $(KEYMGT_FILES)
	-$(FORCE_RM) pbc_myconfig myconf base64
	(cd $(builddir)/cgic; $(MAKE) clean)

distclean:: clean
	$(FORCE_RM) $(CONFIGURE_TMP_FILES)
	$(RECURSIVE_FORCE_RM) $(CONFIGURE_TMP_DIRS)
	(cd $(builddir)/cgic; $(MAKE) distclean)

# APXS Stuff.

APACHE_DEFINES= -DAPACHE1_3

apache_module: a_ver mod_pubcookie.so keyclient

a_ver:
	@echo Making $(DISTNAME) apache module;

mod_pubcookie.so: $(MOD_SRC) $(LIB_SRC) $(LIB_HEAD) $(builddir)/src/config.h
	$(APXS) -c -o mod_pubcookie.so $(CPPFLAGS) $(APACHE_DEFINES) \
			$(LDFLAGS) $(MOD_SRC) $(LIB_SRC)

# Win32 ... Nothing here except the Dist files.

WIN32_SSL_SRC=$(srcdir)/src/Win32/include/openssl/asn1_mac.h \
			  $(srcdir)/src/Win32/include/openssl/asn1.h \
			  $(srcdir)/src/Win32/include/openssl/blowfish.h \
			  $(srcdir)/src/Win32/include/openssl/bio.h \
			  $(srcdir)/src/Win32/include/openssl/buffer.h \
			  $(srcdir)/src/Win32/include/openssl/bn.h \
			  $(srcdir)/src/Win32/include/openssl/conf_api.h \
			  $(srcdir)/src/Win32/include/openssl/cast.h \
			  $(srcdir)/src/Win32/include/openssl/comp.h \
			  $(srcdir)/src/Win32/include/openssl/conf.h \
			  $(srcdir)/src/Win32/include/openssl/obj_mac.h \
			  $(srcdir)/src/Win32/include/openssl/crypto.h \
			  $(srcdir)/src/Win32/include/openssl/des.h \
			  $(srcdir)/src/Win32/include/openssl/dh.h \
			  $(srcdir)/src/Win32/include/openssl/dsa.h \
			  $(srcdir)/src/Win32/include/openssl/dso.h \
			  $(srcdir)/src/Win32/include/openssl/e_os.h \
			  $(srcdir)/src/Win32/include/openssl/e_os2.h \
			  $(srcdir)/src/Win32/include/openssl/ebcdic.h \
			  $(srcdir)/src/Win32/include/openssl/err.h \
			  $(srcdir)/src/Win32/include/openssl/evp.h \
			  $(srcdir)/src/Win32/include/openssl/hmac.h \
			  $(srcdir)/src/Win32/include/openssl/idea.h \
			  $(srcdir)/src/Win32/include/openssl/lhash.h \
			  $(srcdir)/src/Win32/include/openssl/md2.h \
			  $(srcdir)/src/Win32/include/openssl/md4.h \
			  $(srcdir)/src/Win32/include/openssl/md5.h \
			  $(srcdir)/src/Win32/include/openssl/mdc2.h \
			  $(srcdir)/src/Win32/include/openssl/opensslconf.h \
			  $(srcdir)/src/Win32/include/openssl/objects.h \
			  $(srcdir)/src/Win32/include/openssl/safestack.h \
			  $(srcdir)/src/Win32/include/openssl/opensslv.h \
			  $(srcdir)/src/Win32/include/openssl/pem.h \
			  $(srcdir)/src/Win32/include/openssl/pem2.h \
			  $(srcdir)/src/Win32/include/openssl/pkcs12.h \
			  $(srcdir)/src/Win32/include/openssl/pkcs7.h \
			  $(srcdir)/src/Win32/include/openssl/rand.h \
			  $(srcdir)/src/Win32/include/openssl/rc2.h \
			  $(srcdir)/src/Win32/include/openssl/rc4.h \
			  $(srcdir)/src/Win32/include/openssl/rc5.h \
			  $(srcdir)/src/Win32/include/openssl/ripemd.h \
			  $(srcdir)/src/Win32/include/openssl/rsa.h \
			  $(srcdir)/src/Win32/include/openssl/rsaref.h \
			  $(srcdir)/src/Win32/include/openssl/sha.h \
			  $(srcdir)/src/Win32/include/openssl/ssl.h \
			  $(srcdir)/src/Win32/include/openssl/ssl2.h \
			  $(srcdir)/src/Win32/include/openssl/ssl23.h \
			  $(srcdir)/src/Win32/include/openssl/ssl3.h \
			  $(srcdir)/src/Win32/include/openssl/stack.h \
			  $(srcdir)/src/Win32/include/openssl/symhacks.h \
			  $(srcdir)/src/Win32/include/openssl/tls1.h \
			  $(srcdir)/src/Win32/include/openssl/tmdiff.h \
			  $(srcdir)/src/Win32/include/openssl/txt_db.h \
			  $(srcdir)/src/Win32/include/openssl/x509.h \
			  $(srcdir)/src/Win32/include/openssl/x509_vfy.h \
			  $(srcdir)/src/Win32/include/openssl/x509v3.h

WIN32_LIB_SRC=$(srcdir)/src/Win32/lib/libeay32.lib \
			  $(srcdir)/src/Win32/lib/openssl.cnf \
			  $(srcdir)/src/Win32/lib/ssleay32.lib

WIN32_FILTER_SRC=$(srcdir)/src/Win32/PubCookieFilter.cpp \
				 $(srcdir)/src/Win32/PubCookieFilter.def \
				 $(srcdir)/src/Win32/PubCookieFilter.dsp \
				 $(srcdir)/src/Win32/PubCookieFilter.dsw \
				 $(srcdir)/src/Win32/PubCookieFilter.h \
				 $(srcdir)/src/Win32/PubCookieFilter.rc

WIN32_MISC_SRC=$(srcdir)/src/Win32/debug.c \
			   $(srcdir)/src/Win32/debug.h \
			   $(srcdir)/src/Win32/getopt.c \
			   $(srcdir)/src/Win32/getopt.h \
			   $(srcdir)/src/Win32/pbc_w32_myconfig.c \
			   $(srcdir)/src/Win32/resource.h

WIN32_KEYCLIENT_SRC=$(srcdir)/src/Win32/keyclient.dsp \
					$(srcdir)/src/Win32/keyclient.dsw

WIN32_SRC=$(WIN32_SSL_SRC) \
		  $(WIN32_LIB_SRC) \
		  $(WIN32_FILTER_SRC) \
		  $(WIN32_MISC_SRC) \
		  $(WIN32_KEYCLIENT_SRC)

# Dist stuff

dist: a_ver l_ver
	$(MKDIR) $(DISTNAME)
	$(MKDIR) $(DISTNAME)/src
	$(MKDIR) $(DISTNAME)/doc
	$(MKDIR) $(DISTNAME)/cgic
	-$(RECURSIVE_CP) $(srcdir)/src/contrib $(DISTNAME)
	$(MKDIR) $(DISTNAME)/src/login_templates.generic
	$(CP) $(LOGIN_TEMPLATES) $(DISTNAME)/src/login_templates.generic
	$(CP) $(DOCS) $(DISTNAME)/doc
	$(CP) $(CONFIGURE_FILES) $(DISTNAME)/
	$(CP) $(SRC_CONFIGURE_FILES) $(DISTNAME)/src
	$(CP) $(TEST_SRC) $(UTIL_SRC) $(VERIFY_SRC) $(DISTNAME)/src
	$(CP) $(FLAVOR_SRC) $(INDEX_SRC) $(KEYMGT_SRC) $(LIB_SRC) $(MOD_SRC) \
		  $(DISTNAME)/src
	$(CP) $(INDEX_HEAD) $(LIB_HEAD) $(DISTNAME)/src
	$(CP) $(CGIC_FILES) $(DISTNAME)/cgic
	$(CP) $(srcdir)/src/Makefile.tmpl $(DISTNAME)/src
	$(MKDIR) $(DISTNAME)/src/Win32
	$(MKDIR) $(DISTNAME)/src/Win32/include
	$(MKDIR) $(DISTNAME)/src/Win32/include/openssl
	$(MKDIR) $(DISTNAME)/src/Win32/lib
	$(CP) $(WIN32_SSL_SRC) $(DISTNAME)/src/Win32/include/openssl
	$(CP) $(WIN32_LIB_SRC) $(DISTNAME)/src/Win32/lib
	$(CP) $(WIN32_FILTER_SRC) $(DISTNAME)/src/Win32
	$(CP) $(WIN32_MISC_SRC) $(DISTNAME)/src/Win32
	$(CP) $(WIN32_KEYCLIENT_SRC) $(DISTNAME)/src/Win32
	$(TAR) cf $(DISTNAME).tar $(DISTNAME)/
	$(GZIP) $(DISTNAME).tar
	$(RECURSIVE_FORCE_RM) ./$(DISTNAME)/

# vim: set noet:
