# @configure_input@
SRCDIR=@srcdir@
VPATH=@srcdir@
prefix=@prefix@

@SET_MAKE@

INSTALL=@INSTALL@

CC=@CC@
CPPFLAGS=@CPPFLAGS@
CFLAGS=@REALCFLAGS@
JOINEDCFLAGS=@CFLAGS@
LDFLAGS=$(CFLAGS) @LDFLAGS@

all:	@MAKE_GMP@ @MAKE_GDBM@ @MAKE_ZLIB@ pike extern

pike: force
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS) @LINKFORSHARED@")

extern: force
	@(cd extern;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" all)

gmp: force
	-@(cd gmp;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" all)

gdbm: force
	-@(cd gdbm;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" all)

zlib: force
	-@(cd zlib;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" libz.a)

force:

# These are here for compatibility with the easy-start makefile
easy: all
hard: all

depend:
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" depend)
	echo "You need to run configure once again."

verify: all verify_other
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" verify)

verbose_verify: all verify_other
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" verbose_verify)

verify_other:
	@if test "@MAKE_ZLIB@" = "zlib"; then \
	  $(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" verify_zlib; \
	fi
	@if test "@MAKE_GMP@" = "gmp"; then \
	  $(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" verify_gmp; \
	fi

verify_zlib:
	@(cd zlib;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" test)

verify_gmp:
	@(cd gmp;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" check)

new_peep_engine:
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" new_peep_engine)

check: verify

clean:
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" clean)
	@(cd extern;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" clean)

install_all: install_pike install

install: all
	$(SRCDIR)/mkdir -p $(prefix)/roxen/
	@if test -d $(prefix)/roxen/server.old/.; then \
	  if test -d $(prefix)/roxen/server.older/.; then \
	    echo; \
	    echo "Warning, deleting old server \"$(prefix)/roxen/server.older\""; \
	    echo; \
	    rm -rf $(prefix)/roxen/server.older; \
	  fi; \
	  mv -f $(prefix)/roxen/server.old $(prefix)/roxen/server.older; \
	fi
	@if test -d $(prefix)/roxen/server/.; then \
	  mv -f $(prefix)/roxen/server $(prefix)/roxen/server.old ; \
	fi
	cp -r $(SRCDIR)/server $(prefix)/roxen/
	@rm -rf	$(prefix)/roxen/server/CVS $(prefix)/roxen/server/*/CVS\
		$(prefix)/roxen/server/*/*/CVS
	cp pike/src/pike $(prefix)/roxen/server/bin
	-@rm -f $(prefix)/roxen/server/bin/roxen >/dev/null 2>&1
	ln $(prefix)/roxen/server/bin/pike $(prefix)/roxen/server/bin/roxen
	cp $(SRCDIR)/pike/bin/feature_list $(prefix)/roxen/server/bin
	test -d $(prefix)/roxen/local/. || mkdir $(prefix)/roxen/local
	test -d $(prefix)/roxen/local/modules/. || mkdir $(prefix)/roxen/local/modules
	test -d $(prefix)/roxen/local/nfonts/. || mkdir $(prefix)/roxen/local/nfonts
	test -d $(prefix)/roxen/server/lib/. || mkdir $(prefix)/roxen/server/lib
	test -d $(prefix)/roxen/server/lib/pike/. || mkdir $(prefix)/roxen/server/lib/pike
	cp -r pike/src/lib/* $(prefix)/roxen/server/lib/pike/
	test -d $(prefix)/roxen/server/include/. || mkdir $(prefix)/roxen/server/include
	test -d $(prefix)/roxen/server/include/pike/. || mkdir $(prefix)/roxen/server/include/pike
	for a in $(SRCDIR)/pike/src/*.h ./pike/src/*.h; do $(INSTALL) $$a $(prefix)/roxen/server/include/pike; done
	-@(cd extern;$(MAKE) install "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)";cd ../)
	-@$(SRCDIR)/mkdir -p $(prefix)/roxen/logs
	-@$(SRCDIR)/mkdir -p $(prefix)/roxen/configurations
	-chmod a+x $(prefix)
	-chmod a+x $(prefix)/roxen
	-chmod a+x $(prefix)/roxen/server
	-@for d in fonts nfonts modules etc bin base_server more_modules \
		   config_actions server_templates \
	           languages roxen-images protocols unfinishedmodules; do \
	  echo Modifying permissions for directory $(prefix)/roxen/server/$$d... ; \
	  find $(prefix)/roxen/server/$$d -type d -exec chmod a+x '{}' \; ; \
	  chmod -R a+r $(prefix)/roxen/server/$$d ;\
	done
	@echo Roxen installed.

install_pike: all
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" install)

localinstall: all
	cp pike/src/pike $(SRCDIR)/server/bin/
	-@rm -f $(SRCDIR)/server/bin/roxen >/dev/null 2>&1
	ln $(SRCDIR)/server/bin/pike $(SRCDIR)/server/bin/roxen
	(cd extern; $(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" localinstall)

spotless:  clean
	@(cd extern;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" spotless)
	@(cd pike/src;$(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" spotless)
	rm -f server/bin/selfdir server/bin/roxen_hostname pike/src/pike\
	pike/src/pike.old server/bin/proxygarb 
	find . '(' -name '#*#' -o -name '*~' -o -name '.*~' -o -name '*.bak'\
        -o -name '.pine-debug*' -o -name '.*.bak' -o -name core -o -name \
	config.cache -o -name config.status -o -name config.log -o -name \
	"*.a" ')'  -print -exec /bin/rm '{}'  ';'
	rm -rf server/logs
	rm -rf logs


distribute:	spotless
	@(cd extern; $(MAKE) "prefix=$(prefix)" "CC=$(CC)" "LDFLAGS=$(LDFLAGS)" distribute)
