# The absent Makefile
# You should inspect everything up to the line that says "magic, don't touch"
# and edit it to match your version of the world.
#
#
# patch
PATCH=/usr/local/bin/patch
#
# perl
# this should be the path to the perl installation you'll be using for
# pushweb.
PERL=/usr/local/bin/perl
#
# the C compiler
CC=gcc
#
# path to root of apache _source_ tree.  again, this is because we need
# to muck about a bit with the apache source.
APACHE=../apache_1.3.9
#
# at present, pushweb requires a few paths to be built in at compile time.
# unfortunately, these values can NOT be configured at run time in pushweb.
# we'll fix that, we promise.
#
# MASTER_KEY is the location of the pushweb master key; this key
# is used to generate session keys.  it's very important that this file
# not be exposed; while an exposure of the master key won't permit an intruder
# to read traffic between clients and servers, it could permit an intruder
# to forge requests.  it's best to have the file readable only by the
# user which will run the pushweb daemon.
# see the README file for information on how to generate this file.
MASTER_KEY=/usr/local/pushweb/etc/keys/master_key
#
# USER_DIR is the directory where the database of users, opie keys, and
# personal start pages is kept.  The user who runs pushweb will need to be
# able to write to this directory.
# 
USER_DIR=/usr/local/pushweb/etc/users
#
# The default location for the absentd configuration file; this can be
# overridden on the absent command line, so there's really no reason to
# change it.
ABSENTD_CFILE=/usr/local/absent/absentd.cf
#
# path to the opie tree.  this can be an installed OPIE tree, but you'll
# need to have installed the include and library files if you do that.  the
# structure here assumes this is just a pointer into the source tree; if
# you're working with an installed tree, you'll need to change the values
# of INCOPIE and LIBOPIE.  Otherwise, they'll just be right.
OPIEDIR=../opie-2.32
# ... the opie include files
INCOPIE=${OPIEDIR}
# ... and the location of libopie.a
LIBOPIE=${OPIEDIR}/libopie
# other libraries; mostly platform-related stuff
# For solaris, IRIX(?):
OLIBS=-lnsl -lsocket
# for Linux:
# OLIBS=
#
# feel free to add additional defines here.
DEFS=-DUSER_DIR=\"${USER_DIR}\" -DMASTER_KEY=\"${MASTER_KEY}\" \
	-DABSENTD_CFILE=\"${ABSENTD_CFILE}\"
#
# Other compiler flags.  you can turn on optimization if you want,
# absent would certainly benefit from it.
CFLAGS=-Wall -c -g -I${LOCINC} ${DEFS}
LDFLAGS=-Wall -g -L${LIBRAND}
#
# path to truerand installation.  truerand ships with absent, so unless you've
# already got your own copy, or you've messed around inside this source tree,
# you shouldn't need to change this.
LIBRAND=librand
#
# local include tree (it's probably safe to leave this alone)
LOCINC=include
#
#
#
# magic. don't touch.
# i'm well aware that there are better ways to do this in both GNU and Solaris
# make.  however, i'm not aware of a way that works for both of them.
# i know it's ugly.  frankly, it's still one of the less ugly things in
# the build process, though, so i'm loathe to change it.
MYDIR=`pwd`
FIXPATHS=sed -e s:__PATCH__:${PATCH}:	-e s:__PERL__:${PERL}:	-e s:__LOCINC__:${MYDIR}/${LOCINC}: -e s:__OPIEDIR__:${MYDIR}/${OPIEDIR}: -e s:__INCOPIE__:${MYDIR}/${INCOPIE}: -e s:__LIBOPIE__:${MYDIR}/${LIBOPIE}: -e s:__LIBRAND__:${MYDIR}/${LIBRAND}: -e s:__APACHE__:${MYDIR}/${APACHE}:
#
#
ABSVERS=0.3
#
# the rest is fairly standard...
SUPPORTOBJS=hmac_md5.o keys.o
ABSDOBJS=absentd.o ${SUPPORTOBJS}
INITOBJS=gen_key.o ${SUPPORTOBJS}

ALL: /bin/true
	@echo Please read the INSTALL file before attempting to build absent.

#
# the external absent daemon
absentd:	${ABSDOBJS} ${LIBRAND}/librand.a
		${CC} -o absentd ${LDFLAGS} ${ABSDOBJS} -lrand ${OLIBS}
absentd.o:	absentd.c ${LOCINC}/absentd.h ${LOCINC}/absent.h \
		${LOCINC}/keys.h ${LOCINC}/md5.h ${LOCINC}/global.h
		${CC} ${CFLAGS} absentd.c
#
# gen_key is just a front end to the key generation routines
gen_key:	${INITOBJS} ${LIBRAND}/librand.a
		${CC} -o gen_key ${LDFLAGS} ${INITOBJS} -lrand ${OLIBS}
gen_key.o:	gen_key.c ${LOCINC}/absent.h ${LOCINC}/keys.h
		${CC} ${CFLAGS} gen_key.c
#
# pushweb, the modified apache
# this rule doesn't actually BUILD pushweb, it just sets up the build tree.
pushweb:	gen_key \
		keys.o hmac_md5.o user_table.o otp.o \
		mod_pushweb/mod_pushweb.c \
		${LIBRAND}/librand.a ${LIBOPIE}/libopie.a
		cp keys.o hmac_md5.o user_table.o otp.o mod_pushweb
		${AR} rc mod_pushweb/libmod_pushweb.a \
			mod_pushweb/keys.o \
			mod_pushweb/hmac_md5.o \
			mod_pushweb/user_table.o \
			mod_pushweb/otp.o
		@echo copying mod_pushweb directory...
		cp -r mod_pushweb ${APACHE}/src/modules
		@echo fixing up paths...
		${FIXPATHS} \
		<${APACHE}/src/modules/mod_pushweb/libmod_pushweb.module.pre \
		>${APACHE}/src/modules/mod_pushweb/libmod_pushweb.module
		${FIXPATHS} \
		<${APACHE}/src/modules/mod_pushweb/Makefile.tmpl.pre \
		>${APACHE}/src/modules/mod_pushweb/Makefile.tmpl
		${FIXPATHS} \
		<${APACHE}/src/modules/mod_pushweb/Otp/Makefile.PL.pre \
		>${APACHE}/src/modules/mod_pushweb/Otp/Makefile.PL
		@echo
		@echo All done.  Now go configure, patch, and build apache.
		@echo
		@echo To do that, do the following:
		@echo
		@echo cd ${APACHE}
		@echo ./configure --args...
		@echo \ \(see the absent INSTALL file for configure args\)
		@echo cd src/modules/mod_pushweb
		@echo make patch
		@echo cd ../..
		@echo make
#
# support functions.  we really should just put these in a library.
keys.o:		keys.c ${LOCINC}/absent.h \
		${LOCINC}/keys.h ${LOCINC}/md5.h ${LOCINC}/global.h
		${CC} ${CFLAGS} keys.c
hmac_md5.o:	hmac_md5.c ${LOCINC}/absent.h \
		${LOCINC}/keys.h ${LOCINC}/md5.h ${LOCINC}/global.h
		${CC} ${CFLAGS} hmac_md5.c
otp.o:		otp.c \
		${INCOPIE}/opie.h ${LOCINC}/user_table.h ${LOCINC}/keys.h
		${CC} -c ${CFLAGS} -I${INCOPIE} -I${LOCINC} otp.c
user_table.o:	user_table.c ${LOCINC}/user_table.h
		${CC} -c ${CFLAGS} -I${INCOPIE} -I${LOCINC} user_table.c

#
# jack lacy's truerand library
${LIBRAND}/librand.a:	/bin/true
			cd librand && ${MAKE}
#
# just catch obvious bogosity
${LIBOPIE}/libopie.a:	/bin/true
			@echo
			@echo Couldn't find libopie.a in ${LIBOPIE}
			@echo Either the path is wrong in the Makefile
			@echo or OPIE hasn't been built yet.
			@echo
			@echo You didn't read the INSTALL file, did you?
#
# other randomness
clean:		clean-librand clean-modpushweb
		rm -f *.o absentd pushweb gen_key
clean-librand:	/bin/true
		-cd librand && make clean
clean-modpushweb:	/bin/true
		rm -f mod_pushweb/*.o
		rm -f mod_pushweb/*.a
dist:		/bin/true
		cat ../MANIFEST | xargs -l dirname | sort | uniq \
		 | grep -v '^\.$$'| sed "s/^/tmp\/absent-${ABSVERS}\//" \
		 | xargs mkdir -p
		for FOO in `cat ../MANIFEST`; \
		do cp ../$$FOO tmp/absent-${ABSVERS}/`dirname $$FOO`; done
		chmod -R u+w tmp/absent-${ABSVERS}
		cd tmp && \
		 tar cf - absent-${ABSVERS} | gzip -9 > \
		  ../../absent-${ABSVERS}.tar.gz
