##
##  Makefile -- Build procedure for mod_trigger
##

#   the used tools
APXS=apxs
APACHECTL=apachectl
VERSION = 1.1
DISTNAME = mod_trigger
DISTVNAME = $(DISTNAME)-$(VERSION)

SHELL = /bin/sh
PERL = perl
NOOP = $(SHELL) -c true
RM_RF = rm -rf
SUFFIX = .gz
COMPRESS = gzip --best
TAR  = tar
TARFLAGS = cvf
PREOP = @$(NOOP)
POSTOP = @$(NOOP)
TO_UNIX = @$(NOOP)


#   additional user defines, includes and libraries
#DEF=-Dmy_define=my_value
#INC=-Imy/include/dir
#LIB=-Lmy/lib/dir -lmylib

#   the default target
all: mod_trigger.so

rpm: dist
	cp $(DISTVNAME).tar$(SUFFIX) /usr/src/redhat/SOURCES
	rpm -ba $(DISTNAME).spec
	cp /usr/src/redhat/RPMS/i386/$(DISTVNAME)*.i386.rpm .
	cp /usr/src/redhat/SRPMS/$(DISTVNAME)*.src.rpm .

#   compile the DSO file
mod_trigger.so: mod_trigger.c
	$(APXS) -c $(DEF) $(INC) $(LIB) mod_trigger.c

#   install the DSO file into the Apache installation
#   and activate it in the Apache configuration
install: all
	$(APXS) -i -a -n 'trigger' mod_trigger.so

#   cleanup
clean:
	-rm -f mod_trigger.o mod_trigger.so

#   simple test
test: reload
	lynx -mime_header http://localhost/trigger

#   reload the module by installing and restarting Apache
reload: install stop start

#   the general Apache start/restart/stop procedures
start:
	$(APACHECTL) start
restart:
	$(APACHECTL) restart
stop:
	$(APACHECTL) stop

dist: $(DISTVNAME).tar$(SUFFIX)

version:
	echo $(VERSION) > VERSION
	echo "#define VERSION \"$(VERSION)\"" > version.h
	cat mod_trigger.spec | $(PERL) -e 'while (<STDIN>) { push @file, $$_} open(FILE, ">mod_trigger.spec"); for(@file) { if (/^Version/) { print FILE "Version: ${VERSION}\n" } else { print FILE $$_}}'

$(DISTVNAME).tar$(SUFFIX) : distdir
	$(PREOP)
	$(TO_UNIX)
	$(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
	$(RM_RF) $(DISTVNAME)
	$(COMPRESS) $(DISTVNAME).tar
	$(POSTOP)

distdir :
	$(RM_RF) $(DISTVNAME)
	$(PERL) -MExtUtils::Manifest=manicopy,maniread \
	-e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"

push :
	if [ -F *.gz ] ; then \
		rm *.gz; \
	fi
	make dist
	scp $(DISTVNAME).tar$(SUFFIX) root@www.tangent.org:/usr/local/slash/site/www.tangent.org/htdocs/download
	scp $(DISTVNAME).tar$(SUFFIX) root@ftp.tangent.org:/var/ftp/pub/apache
	scp $(DISTVNAME)*.i386.rpm root@www.tangent.org:/usr/local/slash/site/www.tangent.org/htdocs/download
	scp $(DISTVNAME)*i386.rpm root@ftp.tangent.org:/var/ftp/pub/apache
	scp faq.html root@www.tangent.org:/usr/local/slash/site/www.tangent.org/htdocs/faqs/mod_trigger.html
