# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@



UKSRCS=nsafs.h nsafs.c securehash.c

#
# Targets for Apache AFS Web Secure
#
APACHE_AFS_LIB=libapacheafs.a
APACHE_AFS_COMMON_LIB=libcommon.a

BINARIES=weblog weblog_starter
SRC_MODULE=afs_module.c
## This module is made compatible with Apache 1.3.1 by including a file called
## ap_compat.h provided by Apache (basically all they do is #define all the old API calls
## as the new ones with ap_ prepended to the old API calls. The makefile takes care of this
## while building afs_module.c and adding the AFS_component_version_number.c file's contents 
## in comments. 

APACHEAFS_DOC=README
APACHE_INSTALL_SCRIPT=afswsApache_config.sh 
NETSCAPE_INSTALL_SCRIPT=afswsNetscape_config.sh

system apache_afs_web_secure:
	case "${SYS_NAME}" in \
		rs_aix* ) \
			echo Clean, make, and install the lib for 1.2 ; \
			$(MAKE) libclean ; \
			$(MAKE) AUX_CFLAGS=-DAIX $(APACHE_AFS_LIB) ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.2 ; \
			${INSTALL_DATA} ${APACHE_AFS_LIB} ${DEST}/root.afsweb/lib/apache_1.2/${APACHE_AFS_LIB} ; \
			echo Make and install source for 1.2 ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG=-DAPACHE_1_2 ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.2 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.2/$(SRC_MODULE) ; \
			echo Make and install the lib for 1.3.1 ; \
			$(MAKE) libclean ; \
			$(MAKE) AUX_CFLAGS=-DAIX $(APACHE_AFS_LIB) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_1" ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.3.1 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.3.1/$(APACHE_AFS_LIB) ; \
			echo Make and install source for 1.3.1 ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_1" ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.3.1 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.3.1/$(SRC_MODULE) ; \
			echo Clean, make, and install the lib for 1.3.6 ; \
			$(MAKE) libclean ; \
			$(MAKE) AUX_CFLAGS=-DAIX $(APACHE_AFS_LIB) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_6"; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.3.6 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.3.6/$(APACHE_AFS_LIB) ; \
			/bin/rm -f $(SRC_MODULE) ; \
			echo Make and install source for 1.3.1 ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_6" ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.3.6 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.3.6 ; \
			echo Do the binaries ; \
			$(MAKE) AUX_CFLAGS=-DAIX $(BINARIES) ;; \
		sun*) \
			$(MAKE) libclean ; \
			$(MAKE) AUX_FLAGS=-DSOLARIS $(APACHE_AFS_LIB) ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.2 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.2/$(APACHE_AFS_LIB) ; \
			$(MAKE) libclean ; \
			$(MAKE) AUX_FLAGS=-DSOLARIS $(APACHE_AFS_LIB) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_1" ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.3.1 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.3.1/$(APACHE_AFS_LIB) ; \
			$(MAKE) libclean ; \
			$(MAKE) AUX_FLAGS=-DSOLARIS $(APACHE_AFS_LIB) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_6" ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.3.6 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.3.6/$(APACHE_AFS_LIB) ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG=-DAPACHE_1_2 ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.2 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.2/$(SRC_MODULE) ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_1" ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.3.1 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.3.1/$(SRC_MODULE) ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_6" ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.3.6 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.3.6/$(SRC_MODULE) ; \
			$(MAKE) AUX_CFLAGS=-DSOLARIS "XLIBS=-lsocket -lnsl" $(BINARIES) ;; \
		*linux*) \
			$(MAKE) libclean ; \
			$(MAKE) AUX_FLAGS=-DLINUX $(APACHE_AFS_LIB) ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.2 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.2/$(APACHE_AFS_LIB) ; \
			$(MAKE) libclean ; \
			$(MAKE) AUX_FLAGS=-DLINUX $(APACHE_AFS_LIB) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_1" ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.3.1 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.3.1/$(APACHE_AFS_LIB) ; \
			$(MAKE) libclean ; \
			$(MAKE) AUX_FLAGS=-DLINUX $(APACHE_AFS_LIB) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_6" ; \
			${INSTALL} -d ${DEST}/root.afsweb/lib/apache_1.3.6 ; \
			${INSTALL_DATA} $(APACHE_AFS_LIB) ${DEST}/root.afsweb/lib/apache_1.3.6/$(APACHE_AFS_LIB) ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG=-DAPACHE_1_2 ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.2 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.2/$(SRC_MODULE) ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_1" ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.3.1 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.3.1/$(SRC_MODULE) ; \
			/bin/rm -f $(SRC_MODULE) ; \
			$(MAKE) $(SRC_MODULE) VERSION_CFLAG="-DAPACHE_1_3 -DAPACHE_1_3_6" ; \
			${INSTALL} -d ${DEST}/root.afsweb/src/apache_1.3.6 ; \
			${INSTALL_DATA} $(SRC_MODULE) ${DEST}/root.afsweb/src/apache_1.3.6/$(SRC_MODULE) ; \
			$(MAKE) AUX_CFLAGS=-DLINUX "XLIBS=-lnsl" $(BINARIES) ;; \
		* ) \
			 echo "NOT BUILT FOR ${SYS_NAME}"; ;; \
	esac
	${INSTALL} -d ${DEST}/root.afsweb/doc
	${INSTALL_DATA} ${APACHEAFS_DOC} ${DEST}/root.afsweb/doc/${APACHEAFS_DOC}
	${INSTALL} -d ${DEST}/root.afsweb/install
	${INSTALL_SCRIPT} ${APACHE_INSTALL_SCRIPT} ${DEST}/root.afsweb/install/${APACHE_INSTALL_SCRIPT}
	${INSTALL} -d ${DEST}/root.afsweb/bin
	${INSTALL_PROGRAM} $(BINARIES) ${DEST}/root.afsweb/bin

netscape_afs_web_secure:
	${INSTALL} -d ${DEST}/root.afsweb/install
	${INSTALL} -m 755 ${NETSCAPE_INSTALL_SCRIPT} ${DEST}/root.afsweb/install

all: 

install:  

##
## For Apache Afs Web Secure libraries and binaries
## NOTE: APACHE_INCLUDES should point to the Apache src directory where 
## httpd.h and all it's included files reside which right now is src/afsweb/include
## and we have Apache versions as subdirectories but these are taken care of by the
## code. Be sure to compile with the VERSION_CFLAG=-DAPACHE_1_3 option for Apache 1.3
##
APACHE_INCLUDES=-Iapache_includes

XLIBS=
DEFINES=-DSTATUS
OPTF=
DEBUG_FLAG=
AUX_CFLAGS=
VERSION_CFLAG=
AFS_INCL=-I${TOP_INCDIR} -I.. -I../config
CFLAGS=$(OPTF) $(DEFINES) -I. -I.. $(VERSION_CFLAG) $(DEBUG_FLAG)
INCLS=${TOP_INCDIR}/ubik.h \
             ${TOP_INCDIR}/lwp.h \
             ${TOP_INCDIR}/lock.h  \
             ${TOP_INCDIR}/rx/rx.h \
             ${TOP_INCDIR}/rx/xdr.h \
             ${TOP_INCDIR}/rx/rxkad.h \
             ${TOP_INCDIR}/afs/com_err.h \
	     weblog_errors.h $(DCE_DLOG_INCLUDES)
deslib=${TOP_LIBDIR}/libdes.a
rxkadlib=${TOP_LIBDIR}/librxkad.a
authlib=${TOP_LIBDIR}/libauth.a
cmdlib=${TOP_LIBDIR}/libcmd.a
utilib=${TOP_LIBDIR}/util.a
auditlib=${TOP_LIBDIR}/libaudit.a
kauthlib=${TOP_LIBDIR}/libkauth.a

LIBS=${kauthlib} ${TOP_LIBDIR}/libubik.a ${TOP_LIBDIR}/libprot.a \
       ${authlib} ${rxkadlib} ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/librx.a \
       ${TOP_LIBDIR}/libsys.a  \
       ${TOP_LIBDIR}/liblwp.a ${deslib} ${cmdlib} \
       ${TOP_LIBDIR}/libafscom_err.a ${utilib} \
       $(DBM) $(XLIBS)

AR=ar
ARFLAGS=rv
LIBCOMMON_OBJS=apache_afs_utils.o apache_afs_cache.o
LIBAPACHE_OBJS=apache_afs_client.o apache_afs_plugin.o
LIBOBJS=$(LIBCOMMON_OBJS) $(LIBAPACHE_OBJS)
OBJS=$(LIBOBJS) apache_afs_weblog.o weblog.o

.c.o:
	$(CCOBJ) -c $(CFLAGS) $(AFS_INCL) $(AUX_CFLAGS) $<


weblog: weblog.o $(APACHE_AFS_COMMON_LIB)
	$(CC) -o $@ weblog.o $(APACHE_AFS_COMMON_LIB) $(LIBS) $(XLIBS)

weblog_starter: apache_afs_weblog.o weblog_errors.h 
	$(CC) -o $@ apache_afs_weblog.o 

$(APACHE_AFS_COMMON_LIB):$(LIBCOMMON_OBJS)
	- /bin/rm -f $@
	$(AR) $(ARFLAGS) $@ $(LIBCOMMON_OBJS)

$(APACHE_AFS_LIB): $(LIBOBJS) AFS_component_version_number.o
	- /bin/rm -f $@
	$(AR) $(ARFLAGS) $@ $(LIBOBJS) 

afs_module.c: apache_afs_module.c 
	-/bin/rm -f afs_module.c \
	; echo "/*" > afs_module.c \
	; cat AFS_component_version_number.c >> afs_module.c \
	; echo "*/" >> afs_module.c \
	; case "${VERSION_CFLAG}" in \
		-DAPACHE_1_3*)	echo '#include "ap_compat.h"' >> afs_module.c ;; \
	  esac \
	; cat apache_afs_module.c >> afs_module.c

##
##Dependencies
##

$(OBJS): Makefile

apache_afs_weblog.o: apache_afs_weblog.c weblog_errors.h AFS_component_version_number.o
apache_afs_utils.o: apache_afs_utils.c apache_afs_utils.h
apache_afs_cache.o: apache_afs_cache.c apache_afs_cache.h
weblog.o: weblog.c weblog_errors.h $(APACHE_AFS_COMMON_LIB)
apache_afs_client.o: apache_api.h apache_afs_client.c apache_afs_utils.o apache_afs_cache.o AFS_component_version_number.o
	$(CC) -c $(CFLAGS) $(AFS_INCL) $(APACHE_INCLUDES) $(AUX_CFLAGS) apache_afs_client.c
apache_afs_plugin.o: apache_api.h apache_afs_plugin.c apache_afs_client.o apache_afs_utils.o apache_afs_cache.o
	$(CC) -c $(CFLAGS) $(APACHE_INCLUDES) $(AUX_CFLAGS) apache_afs_plugin.c


clean:
	-/bin/rm -f *.o $(BINARIES) $(APACHE_AFS_LIB) $(APACHE_AFS_COMMON_LIB)

libclean:
	-/bin/rm -f $(APACHE_AFS_LIB) $(LIBOBJS)

include ../config/Makefile.version

dest:  

