
/*
 * This Imakefile does many things:
 * - all
 * - clean
 * - collect
 * - 
 */

#include "../config/crossfire.tmpl"

INCLUDES = -I../include

/* LOCAL_LDFLAGS = -L../common /* SGI doesn't understand this */
LOCAL_LIBRARIES = -L../common -lcross

/* The order of the files listed here is an attempt to make sure that
 * it will pack them in such an order, that the archetypes, bmaps, etc
 * will not need to be re-built.  This way, we don't need to have the
 * arch directory a standard part of the distribution.
 */

PIX = 	$(FONTNAME).pix.1 \
	$(FONTNAME).pix.2 \
	$(FONTNAME).pix.3 \
	$(FONTNAME).pix.4 \
	$(FONTNAME).pix.5

FILES = \
	README \
	archetypes \
	artifacts \
	ban_file \
	bmaps	\
	$(FONTNAME).cfb \
	def_help \
	def_keys \
	esrv_xpm.eric\
	faces\
	fsconfig \
	motd \
	sounds \
	spell_params \
	treasures \
	$(PIX)

FILES_HELP = \
	help/bind \
	help/cast \
	help/golem \
	help/invoke \
	help/keys \
	help/melee \
	help/mouse \
	help/move \
	help/name \
	help/output \
	help/output-count \
	help/output-sync \
	help/party \
	help/pickup \
	help/quit \
	help/range \
	help/save \
	help/spells \
	help/take \
	help/traps \
	help/unbind

FILES_ADM = \
	adm/README \
	adm/check-xpm.pl \
	adm/dilate_xpm_files \
	adm/fix_xpm_colors \
	adm/make_ericsrv_file.pl \
	adm/map_check \
	adm/map_info

/* These are files to include in the archive, but not to be installed */
FILES_MISC = bmaps.paths \
	collect.pl \
	$(FONTNAME).bdf \
	util.pl \
	xbmtobdf.c \
	xpmtopix.c



LIBFLAGS = -m 0644

DEFINES = -DFONTDIR=\"${FONTDIR}\" -DFONTNAME=\"$(FONTNAME)\" $(TARGET) \
	-DLIBDIR=\"$(C_LIBDIR)\" $(COMPRESS_DEF)

#ifdef OWIN
FONTTARGET = $(FONTNAME)24.fb
FONTDIRCMD = bldfamily -d
#else
FONTTARGET = $(FONTNAME).$(FONTTYPE)
FONTDIRCMD = $(MKFONTDIR)
#endif

#

OBJS = xbmtobdf.o \
	xpmtopix.o

SRCS = $(OBJS:.o=.c)

AllTarget(xbmtobdf xpmtopix $(FILES) $(FONTTARGET))

NormalProgramTarget(xbmtobdf, xbmtobdf.o, NullParameter,NullParameter, NullParameter)

NormalProgramTarget(xpmtopix, xpmtopix.o, NullParameter, NullParameter,NullParameter)

DependTarget()

/* Removed xbmtobdf as a dependency from many of the rules.
 * This is so that when someone gets a version that already includes
 * up to date versions of the .bdf and .cfb file, it does not try to
 * make a new copy.  This allows distribution of crossfire without the
 * 'arch' directory, provided the necessary files (.bdf, .cfb, archetypes
 * file) were already built.
 */

$(PIX): bmaps.paths
	./xpmtopix $(FONTNAME).pix

esrv_xpm.eric: bmaps.paths
	adm/make_ericsrv_file.pl

$(FONTNAME).bdf: bmaps.paths
	$(RM) $(FONTNAME).bdf $(FONTNAME).$(FONTTYPE)
	./xbmtobdf -name $(FONTNAME) -f bmaps.paths -d . > $(FONTNAME).bdf

$(FONTNAME).cfb: bmaps.paths
	$(RM) -f $(FONTNAME).cfb
	./xbmtobdf -f bmaps.paths -d . -b > $(FONTNAME).cfb

$(FONTNAME)24.fb: $(FONTNAME).bdf
	convertfont $(FONTNAME).bdf

$(FONTNAME).$(FONTTYPE): $(FONTNAME).bdf
	bdfto$(FONTTYPE) < $(FONTNAME).bdf > $(FONTNAME).$(FONTTYPE)

install:: $(FONTTARGET)
	MakeDir($(FONTDIR))
	$(CP) $(FONTTARGET) $(FONTDIR)
	$(FONTDIRCMD) $(FONTDIR)
	chmod a+r $(FONTDIR)/fonts.dir $(FONTDIR)/$(FONTTARGET)

/***  ***/

.collect-stamp: 
	touch .collect-stamp

collect: 
	perl collect.pl ./arch

archetypes: .collect-stamp
	make collect

bmaps.paths bmaps: .collect-stamp
	make collect

InstallMultipleDestFlags(install,$(FILES),$(C_LIBDIR),$(LIBFLAGS))

install::
	MakeDir($(C_LIBDIR)/players)
	MakeDir($(C_LIBDIR)/help)
	MakeDir($(C_LIBDIR)/unique-items)
        InstallMultipleDestFlags(install, $(FILES_HELP), $(C_LIBDIR)/help, $(LIBFLAGS))

install::
	cp -r ./maps $(C_LIBDIR)

install::
	touch $(C_LIBDIR)/highscore

clean::
	$(RM) $(FONTNAME).snf $(FONTNAME).pcf $(FONTNAME)24.fb

real-clean::
	$(RM) $(FONTNAME).bdf  $(FONTNAME).cfb $(FONTNAME).pix.*
	$(RM) archetypes bmaps .collect-stamp

/* Include .collect-stamp, so that it won't try to re-build the
 * archetypes and bitmap files.  The released version will have already
 * taken care of that.
 */

InsertArchive(Imakefile .collect-stamp $(FILES_MISC) $(FILES),lib)
InsertArchive($(FILES_ADM),lib/adm)
InsertArchive($(FILES_HELP),lib/help)

#ifndef ArchiveNoArch
subarchive::
	MakeDir($(ATOP)/lib/arch)
	cp -r ./arch $(ATOP)/lib
#endif

subarchive::
	MakeDir($(ATOP)/lib/maps/editor)
	cp -r ./maps/editor $(ATOP)/lib/maps

/**********************************************************************
 * lib-packet: archetypes, treasures
 **********************************************************************/

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

/*** end of Imakefile ***/

install-font:: $(FONTTARGET)
	MakeDir($(FONTDIR))
	$(CP) $(FONTTARGET) $(FONTDIR)
	$(FONTDIRCMD) $(FONTDIR)
	chmod a+r $(FONTDIR)/fonts.dir $(FONTDIR)/$(FONTTARGET)

install-same::
	MakeDir($(C_LIBDIR)/players)
	MakeDir($(C_LIBDIR)/unique-items)
	touch $(C_LIBDIR)/highscore

