# Note: generated file

#
# Variables. Edit to suit.
#
srcdir = .
top_srcdir = .
prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
mandir = ${prefix}/man
etcdir = ${prefix}/etc
cc = cc

install = /usr/bin/install

binown = root
bingroup = wheel

manown = root
mangroup = wheel

shareown = root
sharegroup = wheel

#
# Below here should not need to be edited
#

PROG=		lws
VERSION=	0.2.1
SRCS=		lws_config.c lws_server_subsystem.c lws_tmpl.c  lws_tmpl_auth.c lws_tmpl_config.c lws_tmpl_http.c  lws_tmpl_logs.c lws_tmpl_memstats.c lws_tmpl_misc.c  lws_tmpl_object.c lws_tmpl_passwd.c lws_tmpl_string.c  main.c
CFLAGS=		-O -pipe -DLWS_SERVER_VERSION=\"0.2.1\" -DPREFIX=\"/usr/local\" -I/usr/local/include -Wall -Wbad-function-cast -Wcast-align -Wchar-subscripts -Wformat -Winline -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wunused -Wwrite-strings -include $(srcdir)/linuxhacks.h -DOPENSSL_NO_KRB5
MAN=		lws.1
SFILES=		default-config.xml docroot admin ca

prog=		$(PROG)
objs=		$(SRCS:.c=.o)
cman=		$(foreach m,$(MAN),$(m).gz)
files=		$(SFILES)

all:		$(prog) $(cman)

%.gz:		%
	gzip < $+ > $@

%.o:		%.c
	$(cc) -c -o $@ $(CFLAGS) -I$(srcdir) $+

lws.1:		lws.1.in
	sed 's,@PREFIX@,${prefix},g' < $+ > $@

$(prog):	$(objs)
	$(cc) -o $@ $+ -lpdel -lexpat -lssl -lcrypto -lcrypt -lpthread

clean:
	rm -rf $(objs) $(prog) $(cman) \
	    lws-$(VERSION) lws-$(VERSION).tar.gz lws.1

install:	install-prog install-manpages install-files

uninstall:	uninstall-prog uninstall-manpages uninstall-files

install-prog:	$(prog)
	$(install) -c -o $(binown) -g $(bingroup) -m 755 \
	    $(prog) $(DESTDIR)$(bindir)/$(prog)

uninstall-prog:
	rm -f $(DESTDIR)$(bindir)/$(prog)

install-manpages:	$(cman)
	@for p in $(MAN); do \
		section=`echo $$p | sed 's/^[^.]*.//g'`; \
		f=`basename $$p`; \
		if [ ! -d $(DESTDIR)$(mandir)/man$$section ]; then \
			echo $(install) -d -o $(manown) -g $(mangroup) -m 755 \
			    $(DESTDIR)$(mandir)/man$$section; \
			$(install) -d -o $(manown) -g $(mangroup) -m 755 \
			    $(DESTDIR)$(mandir)/man$$section; \
		fi; \
		echo $(install) -c -o $(manown) -g $(mangroup) -m 444 \
		    $$p.gz $(DESTDIR)$(mandir)/man$$section/$$f.gz; \
		$(install) -c -o $(manown) -g $(mangroup) -m 444 \
		    $$p.gz $(DESTDIR)$(mandir)/man$$section/$$f.gz; \
	done

uninstall-manpages:
	@for p in $(MAN); do \
		section=`echo $$p | sed 's/^[^.]*.//g'`; \
		f=`basename $$p`; \
		echo rm -f $(DESTDIR)$(mandir)/man$$section/$$f.gz; \
		rm -f $(DESTDIR)$(mandir)/man$$section/$$f.gz; \
	done

install-files:	$(files)
	@if [ ! -d $(DESTDIR)$(etcdir)/lws ]; then \
		echo $(install) -d -o $(shareown) -g $(sharegroup) -m 755 \
		    $(DESTDIR)$(etcdir)/lws; \
		$(install) -d -o $(shareown) -g $(sharegroup) -m 755 \
		    $(DESTDIR)$(etcdir)/lws; \
	fi
	cp -R $+ $(DESTDIR)$(etcdir)/lws
	chown -R $(shareown):$(sharegroup) $(DESTDIR)$(etcdir)/lws
	find $(DESTDIR)$(etcdir)/lws -type d | xargs chmod 0755
	find $(DESTDIR)$(etcdir)/lws -type f | xargs chmod 0644
	( cd $(DESTDIR)$(etcdir)/lws/ca && sh check_cert \
	    ../bogus-ssl.key ../bogus-ssl.crt `hostname` )
	chmod 0600 $(DESTDIR)$(etcdir)/lws/bogus-ssl.key
	chmod 0600 $(DESTDIR)$(etcdir)/lws/ca/ca.key

uninstall-files:
	@for p in $(files); do \
		echo rm -rf $(DESTDIR)$(etcdir)/lws/$$p; \
		rm -rf $(DESTDIR)$(etcdir)/lws/$$p; \
	done

