# Makefile for mini_httpd

# CONFIGURE: If you are using a SystemV-based operating system, such as
# Solaris, you will need to uncomment this definition.
#SYSV_LIBS =    -lnsl -lsocket

# CONFIGURE: If you want to compile in support for https, uncomment these
# definitions.  You will need to have already built OpenSSL, available at
# http://www.openssl.org/  Make sure the SSL_TREE definition points to the
# tree with your OpenSSL installation - depending on how you installed it,
# it may be in /usr/local instead of /usr/local/ssl.
#SSL_TREE =	/usr/local/ssl
#SSL_DEFS =	-DUSE_SSL
#SSL_INC =	-I$(SSL_TREE)/include
#SSL_LIBS =	-L$(SSL_TREE)/lib -lssl -lcrypto

# CONFIGURE: If you want to try building an IPv6-enabled version of
# mini_httpd, uncomment these definitions.  Of course this will only
# succeed if your system supports IPv6.
#IPV6_DEFS =	-DUSE_IPV6
#IPV6_LIBS =	-L/usr/local/v6/lib -linet6


BINDIR =	/usr/local/bin
MANDIR =	/usr/local/man

CDEFS =		$(SSL_DEFS) $(SSL_INC) $(IPV6_DEFS)
ifdef DEBUG
CFLAGS =        -g -save-c -pp $(CDEFS) $(EXTRACFLAGS)
LDFLAGS =       -g 
else
CFLAGS =        -O3 $(CDEFS) $(EXTRACFLAGS)
LDFLAGS =       -s 
endif
LDLIBS =	$(SSL_LIBS) $(IPV6_LIBS) $(SYSV_LIBS)

all:		mini_httpd$(EXE) htpasswd$(EXE)
build:		all

mini_httpd$(EXE):	mini_httpd.o tdate_parse.o
	${CC} ${CFLAGS} ${LDFLAGS} mini_httpd.o tdate_parse.o -lcrypt ${LDLIBS} -o mini_httpd$(EXE)

mini_httpd.o:	mini_httpd.c version.h port.h mime_types.h
	${CC} ${CFLAGS} -c mini_httpd.c

tdate_parse.o:	tdate_parse.c
	${CC} ${CFLAGS} -c tdate_parse.c

mime_types.h: mime_types.txt
	rm -f mime_types.h
	sed < mime_types.txt > mime_types.h \
	  -e 's/#.*//' -e 's/[ 	]*$$//' -e '/^$$/d' \
	  -e 's/[ 	][ 	]*/", "/' -e 's/^/{ "/' -e 's/$$/" },/'


htpasswd$(EXE):	htpasswd.o
	${CC} ${CFLAGS} htpasswd.o ${LDFLAGS} -lcrypt -o htpasswd$(EXE)

htpasswd.o:	htpasswd.c
	${CC} ${CFLAGS} -c htpasswd.c


install:	all
	rm -f ${BINDIR}/mini_httpd$(EXE) ${BINDIR}/htpasswd$(EXE)
	cp mini_httpd$(EXE) htpasswd$(EXE) ${BINDIR}
	rm -f ${MANDIR}/man8/mini_httpd.8 ${MANDIR}/man1/htpasswd.1
	cp mini_httpd.8 ${MANDIR}/man8
	cp htpasswd.1 ${MANDIR}/man1

clean:
	rm -f mini_httpd$(EXE) mime_types.h htpasswd$(EXE) *.o core core.* *.core

tar:
	@name=`sed -n -e '/SERVER_SOFTWARE/!d' -e 's,.*mini_httpd/,mini_httpd-,' -e 's, .*,,p' version.h` ; \
	  rm -rf $$name ; \
	  mkdir $$name ; \
	  tar cf - `cat FILES` | ( cd $$name ; tar xfBp - ) ; \
	  chmod 644 $$name/Makefile $$name/mime_types.txt ; \
	  chmod 755 $$name/contrib $$name/contrib/redhat-rpm ; \
	  tar cf $$name.tar $$name ; \
	  rm -rf $$name ; \
	  gzip $$name.tar
