#
#  This is the Makefile for EGGDROP (the irc bot)
#  You should never need to edit this.
#

SHELL = /bin/sh
top_srcdir = @top_srcdir@

@SET_MAKE@
prefix = @prefix@
DEST = @DEST@
EGGEXEC = @EGGEXEC@
EGGVERSION = @EGGVERSION@

# things you can put here:
#   -Wall            if you're using gcc and it supports it
#                    (configure usually detects this anyway now)
#   -DEBUG_MEM       to be able to debug memory allocation (.debug)
#                    this can now be set by using 'make debug' or 'make sdebug'
CFLGS =

# configure SHOULD set these...you may need to tweak them to get modules
# to compile .. if you do...let the devel-team know the working settings
# btw to turn STRIP off, do 'STRIP = touch' not 'STRIP ='

# defaults
CC = @CC@
LD = @CC@
STRIP = @STRIP@
RANLIB = @RANLIB@

# make eggmod
MOD_CC = @MOD_CC@
MOD_LD = @MOD_LD@
MOD_STRIP = @MOD_STRIP@

# make modules
SHLIB_CC = @SHLIB_CC@
SHLIB_LD = @SHLIB_LD@
SHLIB_STRIP = @SHLIB_STRIP@

# programs make install uses
LN_S = @LN_S@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

# STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP #
# - - - - - - - - do not edit anything below this line. - - - - - - - - #
# - - - - - - - - -  it's all done by configure now.  - - - - - - - - - #
# STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP #

# stuff for Tcl
XREQS = @TCL_REQS@
XLIBS = @TCL_LIBS@ @LIBS@
TCLLIB = @TCLLIB@
TCLLIBFN = @TCLLIBFN@

CFLAGS = @CFLAGS@ -I.. @DEFS@ $(CFLGS)
DEBCFLAGS = @CFLAGS@ -I.. @DEFS@ $(CFLGS)

MAKE_MODEGG = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(MOD_CC)' 'LD=$(MOD_LD)' \
'STRIP=$(MOD_STRIP)' 'RANLIB=$(RANLIB)' 'CFL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IB=$(RANLIB)' 'CFLAGS=-g3 $(DEBCFLAGS) -DSTATIC' \
'CPPFLAGS=$(CPPFLAGS)' 'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' \
'XREQS=$(XREQS)' 'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' \
'EGGBUILD=(static and debug version)' 'MODOBJS=mod/*.o'

MAKE_DEPEND = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(CC)' 'LD=$(LD)' \
'STRIP=$(STRIP)' 'CFLAGS=$(CFLAGS)' 'CPPFLAGS=$(CPPFLAGS)'

MAKE_INSTALL = $(MAKE) 'MAKE=$(MAKE)' 'DEST=$(DEST)'

all: @DEFAULT_MAKE@

clean:
	@rm -f $(EGGEXEC) *.so *.stamp core DEBUG *~
	@cd doc; $(MAKE) clean
	@cd scripts; $(MAKE) clean
	@cd src; $(MAKE) clean
	@cd src/md5; $(MAKE) clean
	@cd src/mod; $(MAKE) clean

distclean: clean
	@rm -f Makefile doc/Makefile scripts/Makefile src/Makefile src/md5/Makefile src/mod/Makefile
	@rm -f config.cache config.log config.status config.h lush.h

distrib: distclean
	@rm -f `find . \( -name '*~' -o -name '*#' -o -name '*.orig' \
		-o -name '*.rej' -o -name '*.bak' \) -print`
	@rm -rf `find . \( -name 'CVS' \) -print`
	@(echo "all:"; \
	echo "	@echo \"\""; \
	echo "	@echo \"Before you can compile your bot you have to configure it.\""; \
	echo "	@echo \"So please start the configure script now:\""; \
	echo "	@echo \"\""; \
	echo "	@echo \" % ./configure\""; \
	echo "	@echo \"\""; ) > Makefile

depend:
	@cat /dev/null > lush.h
	@cd src; $(MAKE_DEPEND) depend
	@cd src/md5; $(MAKE_DEPEND) depend
	@cd src/mod; $(MAKE_DEPEND) depend

eggdrop: modegg modules

modegg: modtest
	@cd src; $(MAKE_MODEGG) $(EGGEXEC)
	@echo ""
	@./$(EGGEXEC) -v
	@ls -l $(EGGEXEC)

modules: modtest
	@cd src/mod; $(MAKE_MODULES) modules
	@echo ""
	@echo "modules made:"
	@ls -l *.so

static: eggtest
	@echo ""
	@echo "Making module objects for static linking..."
	@echo ""
	@cd src/mod; $(MAKE_STATIC) static
	@echo ""
	@echo "Making core eggdrop for static linking..."
	@echo ""
	@cd src; $(MAKE_STATIC) $(EGGEXEC)
	@echo ""
	@./$(EGGEXEC) -v
	@ls -l $(EGGEXEC)

debug: debegg debmodules

debegg: modtest
	@cd src; $(MAKE_DEBEGG) $(EGGEXEC)
	@echo ""
	@./$(EGGEXEC) -v
	@ls -l $(EGGEXEC)

debmodules: modtest
	@cd src/mod; $(MAKE_DEBMODULES) modules
	@echo ""
	@echo "modules made:"
	@ls -l *.so

sdebug: eggtest
	@echo ""
	@echo "Making module objects for static linking..."
	@echo ""
	@cd src/mod; $(MAKE_SDEBUG) static
	@echo ""
	@echo "Making core eggdrop for static linking..."
	@echo ""
	@cd src; $(MAKE_SDEBUG) $(EGGEXEC)
	@echo ""
	@./$(EGGEXEC) -v
	@ls -l $(EGGEXEC)

eggtest:
	@if [ -f EGGMOD.stamp ]; then \
		echo "You're trying to do a STATIC build of eggdrop when you've";\
		echo "already run 'make' for a module build.";\
		echo "You must first type \"make clean\" before you can build";\
		echo "a static version.";\
		exit 1;\
	fi
	@echo "stamp" >EGGDROP.stamp

modtest:
	@if [ -f EGGDROP.stamp ]; then \
		echo "You're trying to do a MODULE build of eggdrop when you've";\
		echo "already run 'make' for a static build.";\
		echo "You must first type \"make clean\" before you can build";\
		echo "a module version.";\
		exit 1;\
	fi
	@echo "stamp" >EGGMOD.stamp

install: ainstall

dinstall: eggdrop ainstall

sinstall: static ainstall

ainstall: install-start install-bin install-modules install-data \
install-help install-language install-filesys install-doc \
install-scripts install-end

install-start:
	@if test ! -f $(EGGEXEC); then \
		echo ""; \
		echo "You haven't compiled eggdrop yet."; \
		echo "To compile eggdrop use:"; \
		echo "  make <target>"; \
		echo ""; \
		echo "  valid targets: eggdrop static debug sdebug"; \
		echo ""; \
		exit 1; \
	fi
	@if test "x$(DEST)" = "x"; then \
		echo "You must specify a destination directory with DEST="; \
		exit 1; \
	fi
	@echo ""
	@./$(EGGEXEC) -v
	@echo
	@echo "Installing in directory: '$(DEST)'."
	@echo
	@if test ! -d $(DEST); then \
		echo "Creating directory: $(DEST)."; \
		$(top_srcdir)/mkinstalldirs $(DEST); \
	fi

install-bin:
	@if test -f $(DEST)/$(EGGEXEC); then \
		rm -f $(DEST)/o$(EGGEXEC); \
	fi
	@if test -h $(DEST)/$(EGGEXEC); then \
		echo "Removing symlink to archival eggdrop binary."; \
		rm -f $(DEST)/$(EGGEXEC); \
	fi
	@if test -f $(DEST)/$(EGGEXEC); then \
		echo "Renamed the old '$(EGGEXEC)' executable to 'o$(EGGEXEC)'."; \
		mv -f $(DEST)/$(EGGEXEC) $(DEST)/o$(EGGEXEC); \
	fi
	@echo "Copying new '$(EGGEXEC)' executable and creating symlink."
	@$(INSTALL_PROGRAM) $(EGGEXEC) $(DEST)/$(EGGEXEC)-$(EGGVERSION)
	@(cd $(DEST) && $(LN_S) $(EGGEXEC)-$(EGGVERSION) $(EGGEXEC))

install-modules:
	@if test -h $(DEST)/modules; then \
		echo "Removing symlink to archival modules directory."; \
		rm -f $(DEST)/modules; \
	fi
	@if test -d $(DEST)/modules; then \
		echo "Moving old modules into 'modules.old' directory."; \
		rm -rf $(DEST)/modules.old; \
		mv -f $(DEST)/modules $(DEST)/modules.old; \
	fi
	@if test ! "x`echo *.so`" = "x*.so"; then \
		if test ! -d $(DEST)/modules-$(EGGVERSION); then \
			echo "Creating modules-$(EGGVERSION) directory and symlink."; \
			$(top_srcdir)/mkinstalldirs $(DEST)/modules-$(EGGVERSION); \
		fi; \
		(cd $(DEST) && $(LN_S) modules-$(EGGVERSION) modules); \
		echo "Copying new modules."; \
		for i in *.so; do \
			$(INSTALL_PROGRAM) $$i $(DEST)/modules-$(EGGVERSION)/; \
		done; \
	fi

install-data:
	@$(INSTALL_DATA) eggdrop.conf.dist $(DEST)
	@if test ! -f $(DEST)/motd; then \
		$(INSTALL_DATA) motd $(DEST); \
	fi
	@if test ! -f $(DEST)/telnet-banner; then \
		$(INSTALL_DATA) telnet-banner $(DEST); \
	fi

install-help:
	@echo "Copying help files."
	@if test ! "x`echo help/*.help`" = "xhelp/*.help"; then \
		if test ! -d $(DEST)/help; then \
			echo "Creating 'help' subdirectory."; \
			$(top_srcdir)/mkinstalldirs $(DEST)/help; \
		fi; \
		for i in help/*.help; do \
			$(INSTALL_DATA) $$i $(DEST)/help/; \
		done; \
	fi
	@if test ! "x`echo help/msg/*.help`" = "xhelp/msg/*.help"; then \
		if test ! -d $(DEST)/help/msg; then \
			echo "Creating 'help/msg' subdirectory."; \
			$(top_srcdir)/mkinstalldirs $(DEST)/help/msg; \
		fi; \
		for i in help/msg/*.help; do \
			$(INSTALL_DATA) $$i $(DEST)/help/msg/; \
		done; \
	fi
	@if test ! "x`echo help/set/*.help`" = "xhelp/set/*.help"; then \
		if test ! -d $(DEST)/help/set; then \
			echo "Creating 'help/set' subdirectory."; \
			$(top_srcdir)/mkinstalldirs $(DEST)/help/set; \
		fi; \
		for i in help/set/*.help; do \
			$(INSTALL_DATA) $$i $(DEST)/help/set/; \
		done; \
	fi
	@cd src/mod/; $(MAKE_INSTALL) install-help

install-language:
	@echo "Copying language files."
	@if test ! "x`echo language/*.lang`" = "xlanguage/*.lang"; then \
		if test ! -d $(DEST)/language; then \
			echo "Creating 'language' subdirectory."; \
			$(top_srcdir)/mkinstalldirs $(DEST)/language; \
		fi; \
		for i in language/*.lang; do \
			$(INSTALL_DATA) $$i $(DEST)/language/; \
		done; \
	fi
	@cd src/mod/; $(MAKE_INSTALL) install-language

install-filesys:
	@if test ! -d $(DEST)/filesys; then \
		echo "Creating a skeletal filesys subdirectory."; \
		$(top_srcdir)/mkinstalldirs $(DEST)/filesys; \
		$(top_srcdir)/mkinstalldirs $(DEST)/filesys/incoming; \
	fi

install-doc:
	@$(INSTALL_DATA) README $(DEST)
	@cd doc/; $(MAKE_INSTALL) install

install-scripts:
	@cd scripts/; $(MAKE_INSTALL) install

install-end:
	@echo
	@echo "Installation completed."
	@echo ""
	@echo "You MUST ensure that you edit/verify your configuration file."
	@echo "'eggdrop.conf.dist' lists current options."
	@echo ""
	@echo "Remember to change directory to $(DEST) before you proceed."
	@echo ""

#safety hash
