
/*
 * 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 \
	$(FONTNAME).pix.6 \
	$(FONTNAME).pix.7

PFILES = \
	README \
	artifacts \
	ban_file \
	def_help \
	def_keys \
	dm_file \
	formulae\
	fsconfig \
	messages \
	motd \
	races \
	skill_params \
	sounds \
	spell_params \
	treasures \
	xpmtopix.pl \

FILES=$(PFILES) \
	archetypes \
	bmaps	\
	$(FONTNAME).cfb \
	esrv_xpm.eric\
	faces\
	$(PIX)

FILES_HELP = \
	help/apply \
	help/bind \
	help/cast \
	help/golem \
	help/invoke \
	help/keys \
	help/mark \
	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/sort_inventory \
	help/spells \
	help/statistics \
	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 \
	adm/map_expand.pl \
	adm/mapslitter.pl

/* These are files to include in the archive, but not to be installed */
PFILES_MISC = bmaps.paths \
	collect.pl \
	util.pl \
	xbmtobdf.c \
	xpmtopix.c

FILES_MISC = $(FONTNAME).bdf \
	$(PFILES_MISC)

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

faces: .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)

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

#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

