# UltraRogue: The Ultimate Adventure in the Dungeons of Doom
# Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong
# All rights reserved.
#
# See the file LICENSE.TXT for full copyright and licensing information.

#
# Makefile for urogue
#

DISTNAME=urogue1.0.7
PACKAGE_TARNAME=@PACKAGE_TARNAME@

HDRS		  = dict.h dictutil.h rogue.h
OBJS		  = armor.o \
		artifact.o \
		bag.o \
		chase.o \
		command.o \
		daemon.o \
		daemons.o \
		dict.o \
		dictutil.o \
		encumb.o \
		fight.o \
		getplay.o \
		ident.o \
		init.o \
		io.o \
		list.o \
		magic.o \
		main.o \
		maze.o \
		mdport.o \
		memory.o \
		misc.o \
		monsdata.o \
		monsters.o \
		move.o \
		newlvl.o \
		options.o \
		pack.o \
		passages.o \
		player.o \
		potions.o \
		random.o \
		rings.o \
		rip.o \
		rooms.o \
		save.o \
		scrolls.o \
		state.o \
		status.o \
		sticks.o \
		things.o \
		trader.o \
		verify.o \
		vers.o \
		weapons.o \
		wizard.o \
		xcrypt.o

PROGRAM 	  =@PROGRAM@

CFILES		  = armor.c \
		artifact.c \
		bag.c \
		chase.c \
		command.c \
		daemon.c \
		daemons.c \
		dict.c \
		dictutil.c \
		encumb.c \
		fight.c \
		getplay.c \
		ident.c \
		init.c \
		io.c \
		list.c \
		magic.c \
		main.c \
		maze.c \
		mdport.c \
		memory.c \
		misc.c \
		monsdata.c \
		monsters.c \
		move.c \
		newlvl.c \
		options.c \
		pack.c \
		passages.c \
		player.c \
		potions.c \
		random.c \
		rings.c \
		rip.c \
		rooms.c \
		save.c \
		scrolls.c \
		state.c \
		status.c \
		sticks.c \
		things.c \
		trader.c \
		verify.c \
		vers.c \
		weapons.c \
		wizard.c \
		xcrypt.c

MISC=           Makefile README LICENSE.TXT history.txt TODO
DOCS = $(PROGRAM).cat
RAWDOCS = README LICENSE.TXT history.txt TODO

CC    = @CC@
CPPFLAGS=@DEFS@
CFLAGS=
CRLIB = @LIBS@
RM    = rm -f
TAR   = tar
GROFF=@GROFF@
NROFF=@NROFF@
COLCRT=@COLCRT@
INSTALL=@INSTALL@

SCOREFILE=@SCOREFILE@
LOGFILE=@LOGFILE@
SAVEDIR=@SAVEDIR@
CHARDIR=@CHARDIR@
GROUPOWNER=@GROUPOWNER@

DESTDIR=
prefix=@prefix@
exec_prefix=@exec_prefix@
datarootdir=@datarootdir@
bindir=@bindir@
docdir=@docdir@
mandir=@mandir@
man6dir=$(mandir)/man6

.c.o:
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $*.o $*.c

all: $(PROGRAM) docs

$(PROGRAM):	$(OBJS) $(MAKEFILE)
	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(CRLIB) -o $@

clean:		
	rm -f $(OBJS) urogue a.out core *.map urogue.exe $(PROGRAM).cat 

docs: $(DOCS)

$(PROGRAM).cat@DOCS_GROFF@: urogue.6
	$(GROFF) -P-c -P-b -P-u -Tascii -man urogue.6 > $(PROGRAM).cat

$(PROGRAM).cat@DOCS_NROFF@: urogue.6
	$(NROFF) -man urogue.6 | $(COLCRT) - > $(PROGRAM).cat

$(PROGRAM).cat@DOCS_NONE@: urogue.6
	@echo "Not building" $(PROGRAM).cat

install: all
	touch test
	if test ! -f $(DESTDIR)$(SCOREFILE) ; then \
	    mkdir -p `dirname $(DESTDIR)$(SCOREFILE)` ; \
	    $(INSTALL) -m 0664 test $(DESTDIR)$(SCOREFILE) ; fi
	if test "x$(LOGFILE)" != "x" && test ! -f $(DESTDIR)$(LOGFILE) ; then \
	    mkdir -p `dirname $(DESTDIR)$(LOGFILE)` ; \
	    $(INSTALL) -m 0664 test $(DESTDIR)$(LOGFILE) ; fi
	if test "x$(SAVEDIR)" != "x" && test ! -d $(DESTDIR)$(SAVEDIR) ; then \
	    mkdir -p $(DESTDIR)$(SAVEDIR) ; fi
	if test "x$(CHARDIR)" != "x" && test ! -d $(DESTDIR)$(CHARDIR) ; then \
	    mkdir -p $(DESTDIR)$(CHARDIR) ; fi
	mkdir -p $(DESTDIR)$(bindir)
	$(INSTALL) -m 0755 $(PROGRAM) $(DESTDIR)$(bindir)/$(PROGRAM)
	-if test "x$(GROUPOWNER)" != "x" ; then \
	    chgrp $(GROUPOWNER) $(DESTDIR)$(SCOREFILE) ; \
	    chgrp $(GROUPOWNER) $(DESTDIR)$(LOGFILE) ; \
	    chgrp $(GROUPOWNER) $(DESTDIR)$(bindir)/$(PROGRAM) ; \
	    chgrp $(GROUPOWNER) $(DESTDIR)$(SAVEDIR) ; \
	    chgrp $(GROUPOWNER) $(DESTDIR)$(CHARDIR) ; \
	    chmod 02755 $(DESTDIR)$(bindir)/$(PROGRAM) ; \
	    chmod 0464 $(DESTDIR)$(SCOREFILE) ; \
	    chmod 0464 $(DESTDIR)$(LOGFILE) ; \
	    chmod 0775 $(DESTDIR)$(SAVEDIR) ; \
	    chmod 0775 $(DESTDIR)$(CHARDIR) ; \
        fi
	mkdir -p $(DESTDIR)$(man6dir)
	$(INSTALL) -m 0644 urogue.6 $(DESTDIR)$(man6dir)/$(PROGRAM).6
	mkdir -p $(DESTDIR)$(docdir)
	$(INSTALL) -m 0644 $(DOCS) $(RAWDOCS) $(DESTDIR)$(docdir)
	$(RM) test

uninstall:	
	$(RM) $(DESTDIR)$(bindir)/$(PROGRAM)
	$(RM) $(DESTDIR)$(man6dir)/$(PROGRAM).6
	$(RM) -r $(DESTDIR)$(docdir)

reinstall: uninstall install

dist.src:
	make clean
	tar cf $(DISTNAME)-src.tar $(CFILES) $(HDRS) $(MISC)
	gzip -f $(DISTNAME)-src.tar

dist.irix:
	make clean
	make CC=cc CFLAGS="-woff 1116 -O3" urogue
	nroff -man urogue.6 | colcrt - > urogue.cat
	tar cf $(DISTNAME)-irix.tar urogue urogue.cat README LICENSE.TXT
	gzip -f $(DISTNAME)-irix.tar

dist.aix:
	make clean
	make CC=xlc CFLAGS="-qmaxmem=16768 -O3 -qstrict" urogue
	nroff -man urogue.6 | colcrt - > urogue.cat
	tar cf $(DISTNAME)-aix.tar urogue urogue.cat README LICENSE.TXT
	gzip -f $(DISTNAME)-aix.tar

dist.linux:
	make clean
	make urogue
	groff -man urogue.6 | sed -e 's/.\x08//g' > urogue.cat
	tar cf $(DISTNAME)-linux.tar urogue urogue.cat README LICENSE.TXT
	gzip -f $(DISTNAME)-linux.tar

dist.interix:
	make clean
	make urogue
	groff -P-b -P-u -man -Tascii urogue.6 > urogue.cat
	tar cf $(DISTNAME)-interix.tar urogue urogue.cat README LICENSE.TXT
	gzip -f $(DISTNAME)-interix.tar

dist.cygwin:
	make clean
	make urogue
	groff -P-c -man -Tascii urogue.6 | sed -e 's/.\x08//g' > urogue.cat
	tar cf $(DISTNAME)-cygwin.tar urogue.exe urogue.cat README LICENSE.TXT
	gzip -f $(DISTNAME)-cygwin.tar

dist.djgpp:
	make clean
	make LDFLAGS="-L$(DJDIR)/LIB" CRLIB="-lpdcurses" urogue
	groff -man -Tascii urogue.6 | sed -e 's/.\x08//g' > urogue.cat
	rm -f $(DISTNAME)-djgpp.zip
	zip $(DISTNAME)-djgpp.zip urogue.exe urogue.cat README LICENSE.TXT
