# 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
CC =		cyclone
CDEFS =		$(SSL_DEFS) $(SSL_INC) $(IPV6_DEFS)
ifdef DEBUG
CFLAGS =        -g -save-c -pp $(CDEFS) $(EXTRACFLAGS)
LDFLAGS =       -g 
else
CFLAGS =        -O3 -nogc  $(EXTRACFLAGS)
LDFLAGS =       -s 
endif
LDLIBS =	$(SSL_LIBS) $(IPV6_LIBS) $(SYSV_LIBS)
CYCC=cyclone 

HDRS= mime_types.h port.h version.h 
OBJS=mini_httpd.o tdate_parse.o
NC_OBJS = $(addprefix nc_,$(OBJS))

build:		mini_httpd$(EXE)
build-nocheck: mini_httpd-nochk$(EXE)

nc_%.o: %.cyc $(HDRS)
	$(CYCC) --nochecks $(CFLAGS) -c $< -o $@
%.o: %.cyc $(HDRS)
	$(CYCC) $(CFLAGS) -c $< -o $@

mini_httpd$(EXE):	$(OBJS)
	$(CYCC) $(CFLAGS) $^ $(LDFLAGS) -o $@  -lcrypt
mini_httpd-nochk$(EXE):	$(NC_OBJS)
	$(CYCC) $(CFLAGS) $^ $(LDFLAGS) -o $@ -lcrypt



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.cyc
	${CC} ${CFLAGS} -c htpasswd.cyc


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) mini_httpd-nochk$(EXE) mime_types.h htpasswd$(EXE) *.o core core.* *.core *.c

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
