#
# $Id: Makefile,v 1.6 2005/12/20 13:41:18 jonasw Exp $
#
# Bootstrap Makefile
#

VPATH=.
prefix=/usr/local
OS=`uname -srm|sed -e 's/ /-/g'|tr '[A-Z]' '[a-z]'|tr '/' '_'`
BUILDDIR=build/$(OS)

# Used to avoid make compatibility problems.
BIN_TRUE=":"

easy : blurb all
	-@$(BIN_TRUE)

.noway:
	-@$(BIN_TRUE)

hard : configure
	@grep Bootstrap Makefile >/dev/null 2>&1 && mv Makefile Makefile.boot
	if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$MAKE"; \
	fi; \
	export MAKE; \
	./configure --prefix=$(prefix)
	@echo
	@echo 'Please run make again.'
	@exit 1

blurb :
	@echo '	 Roxen 4.5 -- Easy Build '
	@echo '	-------------------------'
	@echo
	@echo 'This will attempt to build Roxen 4.5 in a directory'
	@echo 'specific for this architecture. This allows for building'
	@echo 'Roxen 4.5 for several operating systems at the same time.'
	@echo 'Unfortunately this requires a make which understands VPATH.'
	@echo 'If make reports strange errors about missing files, your'
	@echo 'make probably does not understand VPATH. If this is the'
	@echo 'case try running:'
	@echo '	make hard; make'
	@echo
	@echo
	@sleep 10

all : configure_all
	builddir="$(BUILDDIR)"; \
	cd "$$builddir"; \
	if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$(MAKE)"; \
	fi; \
	export MAKE; \
	"$$MAKE" "prefix=$(prefix)"
	@echo
	@echo Roxen successfully compiled.
	@echo

configure : configure.in
	@echo Rebuilding the configure-scripts...
	@echo
	@runauto=`echo pike/src/run_autoconfig|tr ' ' '\n'|tail -1`; \
	  $$runauto . 2>&1 | grep -v warning
	@echo
	@test -f "$(BUILDDIR)"/stamp-h && rm -f "$(BUILDDIR)"/stamp-h || :

configure_all : 
	@builddir="$(BUILDDIR)"; \
	if test "$(MAKE)" = ""; then :; else \
	  MAKE="$(MAKE)"; \
	  export MAKE; \
	fi; \
	srcdir=`pwd`; \
	./mkdir -p "$$builddir/pike/src" && \
	cd "$$builddir" && \
	test -f stamp-h || ( \
	  echo "Configuring Roxen 4.5 in $$builddir ..."; \
	  echo; \
	  CONFIG_SITE=x $$srcdir/configure --prefix=$(prefix) \
	)

install :
	@if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$(MAKE)"; \
	fi; \
	export MAKE; \
	"$$MAKE" "MAKE=$$MAKE" "prefix=$(prefix)" "OS=$(OS)" "BUILDDIR=$(BUILDDIR)" install_low

#        We can't do this anymore since Mysql needs to be installed.
#
#	 @echo
#	 @echo Starting the install program...
#	 @echo
#	 @cd $(prefix)/roxen/server-* ; ./create_configinterface
#	 @cd $(prefix)/roxen ; ./start

install_low : configure_all
	@builddir="$(BUILDDIR)"; \
	srcdir=`pwd`; \
	echo "Installing Roxen 4.5 from $$builddir ..."; \
	echo; \
	if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$(MAKE)"; \
	fi; \
	export MAKE; \
	cd "$$builddir" && \
	"$$MAKE" install "prefix=$(prefix)"
	@echo
	@echo Roxen successfully installed.
	@echo

localinstall :
	@if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$(MAKE)"; \
	fi; \
	export MAKE; \
	"$$MAKE" "MAKE=$$MAKE" "prefix=`pwd`/server" "OS=$(OS)" "BUILDDIR=$(BUILDDIR)" localinstall_low

localinstall_low : configure_all
	@builddir="$(BUILDDIR)"; \
	srcdir=`pwd`; \
	echo "Installing Roxen 4.5 locally from $$builddir ..."; \
	echo; \
	if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$(MAKE)"; \
	fi; \
	export MAKE; \
	cd "$$builddir" && \
	"$$MAKE" localinstall;
	@echo
	@echo Roxen successfully installed locally.
	@echo

install_all : configure_all
	@builddir="$(BUILDDIR)"; \
	srcdir=`pwd`; \
	test -f "$$builddir"/stamp-h && pikeversion=`cat "$$builddir"/stamp-h`; \
	echo "Installing Roxen 4.5 and Pike $$pikeversion from $$builddir ..."; \
	echo; \
	if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$(MAKE)"; \
	fi; \
	export MAKE; \
	cd "$$builddir" && \
	"$$MAKE" install_all "prefix=$(prefix)"

#        We can't do this anymore since Mysql needs to be installed.
#
#	 @echo
#	 @echo Roxen and Pike successfully installed.
#	 @echo
#	 @echo Starting the install program...
#	 @echo
#	 @cd $(prefix)/roxen/server-* ; ./create_configinterface
#	 @cd $(prefix)/roxen ; ./start

install_pike : configure_all
	@builddir="$(BUILDDIR)"; \
	srcdir=`pwd`; \
	test -f "$$builddir"/stamp-h && pikeversion=`cat "$$builddir"/stamp-h`; \
	echo "Installing Pike $$pikeversion from $$builddir ..."; \
	echo; \
	if test "$(MAKE)" = ""; then \
	  if test "$$MAKE" = ""; then \
	    MAKE="make"; \
	  else :; fi; \
	else \
	  MAKE="$(MAKE)"; \
	fi; \
	export MAKE; \
	cd "$$builddir" && \
	"$$MAKE" install_pike "prefix=$(prefix)"
	@echo
	@echo Pike successfully installed.
	@echo
