# Don't edit Makefile!  Use conf-* for configuration.
#
# Generated by spac see http://untroubled.org/spac/

SHELL=/bin/sh

DEFAULT: all

all: libraries programs docs

backend.a: makelib backend.o copy.o list.o messagefile.o path.o retr.o socket.o stat.o statmod.o state.o store.o
	./makelib backend.a backend.o copy.o list.o messagefile.o path.o retr.o socket.o stat.o statmod.o state.o store.o

backend.o: compile backend.c twoftpd.h backend.h
	./compile backend.c

banner.o: compile banner.c twoftpd.h
	./compile banner.c

clean: TARGETS
	rm -f `cat TARGETS`

clean-spac: clean AUTOFILES
	rm -f `cat AUTOFILES`

compile: conf-cc conf-bgincs
	( bgincs=`head -n 1 conf-bgincs`; \
	  echo '#!/bin/sh'; \
	  echo 'source=$$1; shift'; \
	  echo 'base=`echo "$$source" | sed -e s:\\\\.c$$::`'; \
	  echo exec `head -n 1 conf-cc` -I. "-I'$${bgincs}'" '-o $${base}.o -c $$source $${1+"$$@"}'; \
	) >compile
	chmod 755 compile

conf.o: compile conf.c conf.h
	./compile conf.c

conf_bin.c: conf-bin
	head -n 1 conf-bin | \
	  sed -e 's/"/\\"/g' \
	      -e 's/^/const char conf_bin[] = "/' \
	      -e 's/$$/";/' >conf_bin.c

copy.o: compile copy.c backend.h
	./compile copy.c

docs: twoftpd-switch.1.html twoftpd-xfer.1.html twoftpd-auth.1.html

install: INSTHIER conf-bin conf-man
	bg-installer -v <INSTHIER
	bg-installer -c <INSTHIER

libraries: backend.a main.a

list.o: compile list.c twoftpd.h backend.h
	./compile list.c

load: conf-ld conf-bglibs
	( bglibs=`head -n 1 conf-bglibs`; \
	  echo '#!/bin/sh';\
	  echo 'main="$$1"; shift';\
	  echo exec `head -n 1 conf-ld` -L. "-L'$${bglibs}'" "-Wl,-R'$${bglibs}'" '-o "$$main" "$$main.o" $${1+"$$@"}' -lbg-sysdeps; \
	) >load
	chmod 755 load

log.o: compile log.c log.h
	./compile log.c

main.a: makelib banner.o log.o main.o respond.o responses.o strtou.o
	./makelib main.a banner.o log.o main.o respond.o responses.o strtou.o

main.o: compile main.c twoftpd.h log.h
	./compile main.c

makelib: 
	( echo '#!/bin/sh'; \
	  echo 'main="$$1"; shift';\
	  echo 'rm -f "$$main"';\
	  echo 'ar cr "$$main" $${1+"$$@"}';\
	  echo 'ranlib "$$main"';\
	) >makelib
	chmod 755 makelib

messagefile.o: compile messagefile.c twoftpd.h backend.h
	./compile messagefile.c

path.o: compile path.c twoftpd.h backend.h
	./compile path.c

programs: twoftpd-anon-conf twoftpd-bind-port twoftpd-anon twoftpd-drop twoftpd-switch twoftpd-auth twoftpd-conf twoftpd-xfer

respond.o: compile respond.c twoftpd.h log.h
	./compile respond.c

responses.o: compile responses.c twoftpd.h
	./compile responses.c

retr.o: compile retr.c twoftpd.h backend.h
	./compile retr.c

socket.lib: compile load
	@echo -n 'Checking for socket libraries: '
	@echo 'main() { ; }' >trylib-lsocket.c
	@{ ./compile trylib-lsocket.c && ./load trylib-lsocket -lsocket -lnsl; } >/dev/null 2>&1 \
	  && { echo -lsocket -lnsl >socket.lib; echo -lsocket -lnsl; } \
	  || { : >socket.lib; echo no; }
	@rm -f trylib-lsocket.c trylib-lsocket.o trylib-lsocket

socket.o: compile socket.c twoftpd.h backend.h
	./compile socket.c

stat.o: compile stat.c twoftpd.h backend.h
	./compile stat.c

state.o: compile state.c twoftpd.h backend.h
	./compile state.c

statmod.o: compile statmod.c twoftpd.h backend.h
	./compile statmod.c

store.o: compile store.c twoftpd.h backend.h
	./compile store.c

strtou.o: compile strtou.c twoftpd.h
	./compile strtou.c

twoftpd-anon: twoftpd-anon.o load backend.a main.a socket.lib
	./load twoftpd-anon backend.a main.a -lbg `cat socket.lib`

twoftpd-anon-conf: twoftpd-anon-conf.o load conf.o
	./load twoftpd-anon-conf conf.o -lbg 

twoftpd-anon-conf.o: compile twoftpd-anon-conf.c conf.h conf_bin.c
	./compile twoftpd-anon-conf.c

twoftpd-anon.o: compile twoftpd-anon.c twoftpd.h backend.h
	./compile twoftpd-anon.c

twoftpd-auth: twoftpd-auth.o load main.a socket.lib
	./load twoftpd-auth main.a -lcvm-v2client -lbg `cat socket.lib`

twoftpd-auth.1.html: twoftpd-auth.1
	man2html twoftpd-auth.1 >twoftpd-auth.1.html

twoftpd-auth.o: compile twoftpd-auth.c twoftpd.h
	./compile twoftpd-auth.c

twoftpd-bind-port: twoftpd-bind-port.o load respond.o log.o
	./load twoftpd-bind-port respond.o log.o -lbg 

twoftpd-bind-port.o: compile twoftpd-bind-port.c twoftpd.h
	./compile twoftpd-bind-port.c

twoftpd-conf: twoftpd-conf.o load conf.o
	./load twoftpd-conf conf.o -lbg 

twoftpd-conf.o: compile twoftpd-conf.c conf.h conf_bin.c
	./compile twoftpd-conf.c

twoftpd-drop: twoftpd-drop.o load backend.a main.a socket.lib
	./load twoftpd-drop backend.a main.a -lbg `cat socket.lib`

twoftpd-drop.o: compile twoftpd-drop.c twoftpd.h backend.h
	./compile twoftpd-drop.c

twoftpd-switch: twoftpd-switch.o load respond.o log.o
	./load twoftpd-switch respond.o log.o -lbg 

twoftpd-switch.1.html: twoftpd-switch.1
	man2html twoftpd-switch.1 >twoftpd-switch.1.html

twoftpd-switch.o: compile twoftpd-switch.c twoftpd.h conf_bin.c
	./compile twoftpd-switch.c

twoftpd-xfer: twoftpd-xfer.o load backend.a main.a socket.lib
	./load twoftpd-xfer backend.a main.a -lbg `cat socket.lib`

twoftpd-xfer.1.html: twoftpd-xfer.1
	man2html twoftpd-xfer.1 >twoftpd-xfer.1.html

twoftpd-xfer.o: compile twoftpd-xfer.c twoftpd.h backend.h
	./compile twoftpd-xfer.c

