#
# Makefile for crossfire 0.95.0 and beyond
#
# This file will eventually be replaced by a configure script.  But for
# now, this simple makefile should do the job.
#
#   Copyright (C) 2001 Mark Wedel & Crossfire Development Team
#   Copyright (C) 1992 Frank Tore Johansen
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#   The authors can be reached via e-mail to crossfire-devel@real-time.com

VPATH = @srcdir@
srcdir = @srcdir@

# order of these files is relevant so when new archives are made, they
# will be extracted in this order so time information/dependencies will work
# OK.
INSTALLFILES = $(srcdir)/artifacts $(srcdir)/ban_file $(srcdir)/def_help \
	$(srcdir)/dm_file $(srcdir)/forbid $(srcdir)/formulae \
	$(srcdir)/messages $(srcdir)/motd $(srcdir)/races \
	$(srcdir)/skill_params $(srcdir)/spell_params \
	$(srcdir)/treasures $(srcdir)/animations $(srcdir)/archetypes \
	$(srcdir)/bmaps $(srcdir)/bmaps.paths $(srcdir)/crossfire.0 \
	$(srcdir)/crossfire.1 \
	$(srcdir)/attackmess $(srcdir)/image_info

BININSTALL = $(srcdir)/collect.pl $(srcdir)/util.pl

ALLFILES = $(SRCS) README \
	Makefile.in .collect-stamp  $(INSTALLFILES) $(BININSTALL) settings \
	checkarch.pl.in collect.pl.in
	

FILES_HELP = $(srcdir)/help/apply $(srcdir)/help/bind \
	$(srcdir)/help/cast $(srcdir)/help/golem $(srcdir)/help/invoke \
	$(srcdir)/help/keys $(srcdir)/help/mark $(srcdir)/help/melee \
	$(srcdir)/help/mouse $(srcdir)/help/move \
	$(srcdir)/help/name $(srcdir)/help/output \
	$(srcdir)/help/output-count $(srcdir)/help/output-sync \
	$(srcdir)/help/party $(srcdir)/help/pickup \
	$(srcdir)/help/quit $(srcdir)/help/range $(srcdir)/help/save \
	$(srcdir)/help/sort_inventory $(srcdir)/help/spells \
	$(srcdir)/help/statistics $(srcdir)/help/take $(srcdir)/help/traps \
	$(srcdir)/help/unbind $(srcdir)/help/usekeys

FILES_WIZHELP = $(srcdir)/wizhelp/abil $(srcdir)/wizhelp/addexp \
	$(srcdir)/wizhelp/create $(srcdir)/wizhelp/debug \
	$(srcdir)/wizhelp/dump $(srcdir)/wizhelp/dumpallarchtypes \
	$(srcdir)/wizhelp/dumpallmaps $(srcdir)/wizhelp/dumpallobjects \
	$(srcdir)/wizhelp/dumpbelow $(srcdir)/wizhelp/dumpfriendlyobjects \
	$(srcdir)/wizhelp/forget_spell $(srcdir)/wizhelp/free \
	$(srcdir)/wizhelp/goto $(srcdir)/wizhelp/invisible \
	$(srcdir)/wizhelp/kick $(srcdir)/wizhelp/learn_special_prayer \
	$(srcdir)/wizhelp/learn_spell $(srcdir)/wizhelp/nodm \
	$(srcdir)/wizhelp/nowiz $(srcdir)/wizhelp/overlay_save \
	$(srcdir)/wizhelp/patch $(srcdir)/wizhelp/plugin \
	$(srcdir)/wizhelp/pluglist $(srcdir)/wizhelp/plugout \
	$(srcdir)/wizhelp/printlos $(srcdir)/wizhelp/remove \
	$(srcdir)/wizhelp/reset $(srcdir)/wizhelp/set_god \
	$(srcdir)/wizhelp/shutdown $(srcdir)/wizhelp/speed \
	$(srcdir)/wizhelp/spellreset $(srcdir)/wizhelp/ssdumptable \
	$(srcdir)/wizhelp/style_info $(srcdir)/wizhelp/summon \
	$(srcdir)/wizhelp/teleport $(srcdir)/wizhelp/time \
	$(srcdir)/wizhelp/who $(srcdir)/wizhelp/wizhelp \
	$(srcdir)/wizhelp/wizpass

FILES_ADM = adm/README adm/map_check \
	adm/map_info adm/map_expand.pl adm/mapslitter.pl adm/archsearch.pl \
	adm/collect_images.pl


DEPEND = makedepend

prefix = @prefix@
exec_prefix = @exec_prefix@
datadir = @datadir@
localdir = @localstatedir@
libdir = @libdir@
bindir = @bindir@

MKDIR = @MKDIR@

INSTALL = @INSTALL@

CP = @CP@
RM = @RM@
SHELL = @BOURNE_SHELL@


all:: archetypes bmaps.paths crossfire.0  animations


crossfire.0: bmaps.paths
	@PERL@ $(srcdir)/adm/collect_images.pl -png

.collect-stamp:
	touch .collect-stamp

collect:
	@PERL@ -I$(srcdir) $(srcdir)/collect.pl $(srcdir)/arch

archetypes: .collect-stamp
	make collect

faces: .collect-stamp
	make collect

animations: .collect-stamp
	make collect

bmaps.paths bmaps: .collect-stamp
	make collect

install:: archetypes bmaps.paths crossfire.0 animations collect.pl util.pl
	@if [ ! -d $(datadir) ]; then \
		$(MKDIR) -p $(datadir); \
	fi
	@if [ ! -d $(localdir) ]; then \
		$(MKDIR) -p $(localdir); \
	fi

	if [ ! -d $(datadir)/help ]; then \
		echo "Creating directory $(datadir)/help"; \
		$(MKDIR) -p $(datadir)/help; \
	fi;
	@for i in $(FILES_HELP); do \
	    echo "Installing $$i"; \
	    $(INSTALL) $(INSTALLFLAGS) $$i $(datadir)/help; \
	done
	if [ ! -d $(datadir)/wizhelp ]; then \
		echo "Creating directory $(datadir)/wizhelp"; \
		$(MKDIR) -p $(datadir)/wizhelp; \
	fi;
	@for i in $(FILES_WIZHELP); do \
	    echo "Installing $$i"; \
	    $(INSTALL) $(INSTALLFLAGS) $$i $(datadir)/wizhelp; \
	done
	@for i in $(INSTALLFILES); do \
	    echo "Installing $$i"; \
	    $(INSTALL) $(INSTALLFLAGS)  $$i $(datadir); \
	done

	@for i in $(BININSTALL); do \
		echo "Installing $$i"; \
		$(INSTALL) $(INSTALLFLAGS)  $$i $(bindir); \
	done

	@if [ ! -f $(datadir)/settings ]; then \
		$(INSTALL) $(INSTALLFLAGS) settings $(datadir); \
	fi

	touch $(localdir)/highscore
	touch $(localdir)/bookarch
	touch $(localdir)/temp.maps

	@for i in players unique-items; do \
	    if [ ! -d $(localdir)/$$i ]; then \
		echo "Creating directory $(localdir)/$$i"; \
		$(MKDIR) -p $(localdir)/$$i; \
	    fi; \
	done



clean::
	$(RM) -f Makefile.bak

distclean:: clean
	$(RM) -f Makefile checkarch.pl collect.pl

real-clean::
	$(RM) -f archetypes bmaps .collect-stamp

archive::
	@if [ -d $(ARCHIVE)/lib ]; then set +x; \
	else (set -x; $(MKDIR) $(ARCHIVE)/lib); fi
	$(CP) $(ALLFILES) $(ARCHIVE)/lib
	@if [ -d $(ARCHIVE)/lib/adm ]; then set +x; \
	else (set -x; $(MKDIR) $(ARCHIVE)/lib/adm); fi
	$(CP) $(FILES_ADM) $(ARCHIVE)/lib/adm
	@if [ -d $(ARCHIVE)/lib/help ]; then set +x; \
	else (set -x; $(MKDIR) $(ARCHIVE)/lib/help); fi
	$(CP) $(FILES_HELP) $(ARCHIVE)/lib/help
	@if [ -d $(ARCHIVE)/lib/wizhelp ]; then set +x; \
	else (set -x; $(MKDIR) $(ARCHIVE)/lib/wizhelp); fi
	$(CP) $(FILES_WIZHELP) $(ARCHIVE)/lib/wizhelp

patchlist::
	@echo Makefile.in $(PFILES) $(FILES_ADM) $(FILES_HELP) $(PFILES_MISC) > .patchlist

libArch:
	tar cvf A`perl puredate.pl`.tar arch treasures
	gzip A`perl puredate.pl`.tar


depend:
	$(DEPEND) $(DEPENDFLAGS) -- $(CFLAGS) $(INCLUDES) -I../include -- $(SRCS)

