# Apache makefile template (well, suffix).

# This is combined with the information in the "Configuration" file
# by the configure script to make the actual Makefile.

CFLAGS=$(OPTIM) $(CFLAGS1) $(EXTRA_CFLAGS)
LIBS=$(EXTRA_LIBS) $(LIBS1)
INCLUDES=$(INCLUDES1) $(EXTRA_INCLUDES)
LFLAGS=$(LFLAGS1) $(EXTRA_LFLAGS)

OBJS= alloc.o http_main.o http_core.o http_config.o http_request.o \
  http_log.o http_protocol.o rfc1413.o util.o util_script.o modules.o buff.o\
  md5c.o util_md5.o explain.o http_bprintf.o util_date.o util_snprintf.o\
  gcacheclient.o gcachecommon.o\
  $(MODULES)

.c.o:
	$(CC) -c $(INCLUDES) $(CFLAGS) $(SPACER) $(SSL_CFLAGS) $<
all: @@Configuration@@ $(TARGET) gcache

@@Configuration@@: Configuration.tmpl
	@echo "@@Configuration@@ older than Configuration.tmpl, or doesn't exist."
	@echo "Consider copying Configuration.tmpl to @@Configuration@@, editing and rerunning"
	@echo "Configure."
	@echo "If not, you will at least have to touch @@Configuration@@."
	@false

httpd: $(REGLIB) $(OBJS)
	$(CC) $(LFLAGS)  -o httpd $(OBJS) $(REGLIB) $(LIBS)

httpsd: $(REGLIB) $(OBJS)
	$(CC) $(LFLAGS) -o httpsd $(OBJS) $(REGLIB) $(SSL_LIBS) $(LIBS)

gcache.o gcachecommon.o gcacheclient.o apache_ssl.o: gcache.h

gcache: gcache.o gcachecommon.o
	$(CC) $(LFLAGS) -o gcache gcache.o gcachecommon.o $(LIBS)

certificate:
	$(SSL_APP_DIR)/ssleay req -config $(SSL_APP_DIR)/ssleay.cnf \
	-new -x509 -nodes -out ../SSLconf/conf/httpsd.pem \
	-keyout ../SSLconf/conf/httpsd.pem; \
	ln -sf ../SSLconf/conf/httpsd.pem ../SSLconf/conf/`$(SSL_APP_DIR)/ssleay \
	x509 -noout -hash < ../SSLconf/conf/httpsd.pem`.0

regex/libregex.a:
	(cd regex; $(MAKE) lib CC='$(CC)' AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)')

modules/last-built:
	(cd modules; \
	$(MAKE) CC=$(CC) AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)' \
	SSL_BASE='$(SSL_BASE)' SSL_INCLUDE='$(SSL_INCLUDE)' \
	SSL_CFLAGS='$(SSL_CFLAGS)' SSL_LIB_DIR='$(SSL_LIB_DIR)' \
	SSL_LIBS='$(SSL_LIBS)' SSL_APP_DIR='$(SSL_APP_DIR)' \
	)

clean:
	rm -f httpd httpsd *.o core
	cd regex; $(MAKE) clean
	cd modules; $(MAKE) clean

	rm -f $(DYNAMODS) modules/proxy/libproxy.a

.PHONY: modules

modules: $(DYNAMODS)

%.so: %.c
	$(CC) -shared -lm $(MODLFLAGS) -o $@ $< $(DYNAMIC_CFLAGS) $(CFLAGS)

mod_proxy.so:
	cd modules/proxy && $(MAKE) \
		CC='$(CC)' \
		AUX_CFLAGS='$(DYNAMIC_CFLAGS) $(CFLAGS)' \
		RANLIB='$(RANLIB)'
	$(CC) $(MODLFLAGS) -shared -o $@ modules/proxy/*.o

mod_auth_db.so: mod_auth_db.c
	$(CC) -I/usr/include/db -ldb $(MODLFLAGS) \
		-shared -o $@ $< $(DYNAMIC_CFLAGS) $(CFLAGS)

mod_auth_dbm.so: mod_auth_dbm.c
	$(CC) -ldbm $(MODLFLAGS) -shared -o $@ $< $(DYNAMIC_CFLAGS) $(CFLAGS)

mod_auth_msql.so: mod_auth_msql.c
	$(CC) -I/usr/include/msql -lmsql $(MODLFLAGS) \
		-shared -o $@ $< $(DYNAMIC_CFLAGS) $(CFLAGS)

modules_install: $(DYNAMODS)
	mkdir -p ../modules
	cp $(DYNAMODS) ../modules
	awk < Configuration \
		'/^DynamicModule/ { print "LoadModule",$$2,"modules/"$$3 }' \
		| sed -e 's/\.o/.so/g' > ../conf/dynamic_modules

dist.tar: 
	# Assure a semi-sensible configuration going out...
	cp Makefile.orig Makefile
	cp modules.c.orig modules.c
	tar cvf dist.tar README INSTALL CHANGES TODO API.html \
		Configuration Configure Makefile.tmpl Makefile *.h *.c

# Work around broken compilers
http_bprintf.o: http_bprintf.c
	$(CC) -c $(INCLUDES) $(CFLAGS) $(BROKEN_BPRINTF_FLAGS) $(SSL_CFLAGS) http_bprintf.c

# We really don't expect end users to use this rule.  It works only with
# gcc, and rebuilds Makefile.tmpl.  You have to re-run Configure after
# using it.
depend:
	sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \
	    && $(CC) -MM $(INCLUDES) $(CFLAGS) *.c >> Makefile.new \
	    && mv Makefile.tmpl Makefile.tmpl.bak \
	    && mv Makefile.new Makefile.tmpl


PERL=/usr/bin/perl
PERL_LD_OPTS=`$(PERL) modules/ldopts`

modules/libmodperl.a:
	(cd modules && $(MAKE) -f Makefile.mod_perl CC='$(CC)' \
	AUX_CFLAGS='$(CFLAGS)' RANLIB='$(RANLIB)' PERL=$(PERL);)


#Dependencies

$(OBJS): Makefile
$(DYNAMODS): Makefile

# DO NOT REMOVE
alloc.o: alloc.c httpd.h conf.h alloc.h buff.h
apache_ssl.o: apache_ssl.c httpd.h conf.h alloc.h buff.h
buff.o: buff.c conf.h alloc.h buff.h
explain.o: explain.c explain.h
http_bprintf.o: http_bprintf.c conf.h alloc.h buff.h
http_config.o: http_config.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h http_log.h http_request.h \
 http_conf_globals.h explain.h
http_core.o: http_core.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_core.h http_protocol.h http_conf_globals.h http_main.h \
 http_log.h rfc1413.h util_md5.h md5.h scoreboard.h
http_log.o: http_log.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_core.h http_log.h
http_main.o: http_main.c httpd.h conf.h alloc.h buff.h http_main.h \
 http_log.h http_config.h http_protocol.h http_request.h \
 http_conf_globals.h http_core.h scoreboard.h explain.h
http_protocol.o: http_protocol.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h http_protocol.h http_main.h http_log.h \
 util_date.h
http_request.o: http_request.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_request.h http_core.h http_protocol.h http_log.h \
 http_main.h scoreboard.h
md5c.o: md5c.c md5.h
mod_access.o: mod_access.c httpd.h conf.h alloc.h buff.h http_core.h \
 http_config.h http_log.h http_request.h
mod_actions.o: mod_actions.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_request.h http_core.h http_protocol.h http_main.h \
 http_log.h util_script.h
mod_alias.o: mod_alias.c httpd.h conf.h alloc.h buff.h http_config.h
mod_asis.o: mod_asis.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_protocol.h http_log.h util_script.h http_main.h http_request.h
mod_auth.o: mod_auth.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_core.h http_log.h http_protocol.h
mod_auth_anon.o: mod_auth_anon.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h http_log.h http_protocol.h
mod_auth_db.o: mod_auth_db.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h http_log.h http_protocol.h
mod_auth_dbm.o: mod_auth_dbm.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h http_log.h http_protocol.h
mod_auth_msql.o: mod_auth_msql.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h http_log.h http_protocol.h
mod_browser.o: mod_browser.c httpd.h conf.h alloc.h buff.h \
 http_config.h
mod_cern_meta.o: mod_cern_meta.c httpd.h conf.h alloc.h buff.h \
 http_config.h util_script.h http_log.h http_request.h
mod_cgi.o: mod_cgi.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_request.h http_core.h http_protocol.h http_main.h http_log.h \
 util_script.h http_conf_globals.h
mod_digest.o: mod_digest.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_core.h http_log.h http_protocol.h util_md5.h md5.h
mod_dir.o: mod_dir.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_core.h http_request.h http_protocol.h http_log.h http_main.h \
 util_script.h
mod_dld.o: mod_dld.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_conf_globals.h
mod_env.o: mod_env.c httpd.h conf.h alloc.h buff.h http_config.h
mod_expires.o: mod_expires.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_log.h
mod_headers.o: mod_headers.c httpd.h conf.h alloc.h buff.h \
 http_config.h
mod_imap.o: mod_imap.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_request.h http_core.h http_protocol.h http_main.h http_log.h \
 util_script.h
mod_include.o: mod_include.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_request.h http_core.h http_protocol.h http_log.h \
 http_main.h util_script.h
mod_info.o: mod_info.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_core.h http_log.h http_main.h http_protocol.h util_script.h
mod_log_agent.o: mod_log_agent.c httpd.h conf.h alloc.h buff.h \
 http_config.h
mod_log_config.o: mod_log_config.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h
mod_log_referer.o: mod_log_referer.c httpd.h conf.h alloc.h buff.h \
 http_config.h
mod_mime.o: mod_mime.c httpd.h conf.h alloc.h buff.h http_config.h
mod_negotiation.o: mod_negotiation.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_request.h http_core.h http_log.h util_script.h
mod_rewrite.o: mod_rewrite.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_request.h http_core.h http_log.h mod_rewrite.h
mod_status.o: mod_status.c httpd.h conf.h alloc.h buff.h http_config.h \
 http_core.h http_protocol.h http_main.h util_script.h scoreboard.h \
 http_log.h
mod_userdir.o: mod_userdir.c httpd.h conf.h alloc.h buff.h \
 http_config.h
mod_usertrack.o: mod_usertrack.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_core.h
mod_dlopen.o: httpd.h http_config.h
modules.o: modules.c httpd.h conf.h alloc.h buff.h http_config.h
rfc1413.o: rfc1413.c httpd.h conf.h alloc.h buff.h http_log.h \
 rfc1413.h
util.o: util.c httpd.h conf.h alloc.h buff.h http_conf_globals.h
util_date.o: util_date.c util_date.h
util_md5.o: util_md5.c httpd.h conf.h alloc.h buff.h util_md5.h md5.h
util_script.o: util_script.c httpd.h conf.h alloc.h buff.h \
 http_config.h http_conf_globals.h http_main.h http_log.h \
 http_protocol.h http_core.h http_request.h util_script.h
util_snprintf.o: util_snprintf.c conf.h
