# This program was written by Alexander Siegel in September of 1989   
# at Cornell University.  It may may copied freely for private use or 
# public dispersion provided that this comment is not removed.  This  
# program, any portion of this program, or any derivative of this     
# program may not be sold or traded for financial gain.

# Name of game executable
GAME = golddig
# Name of level editor executable
EDITOR = gdedit
# Directory where games binaries are stored
BIN = ${PREFIX}/bin
# Directory where the library for this game will be stored
LIB = ${PREFIX}/share/${GAME}
#LIB = levs
# Directory where manual pages are kept
MANEXT = 6
MAN = ${PREFIX}/man/man${MANEXT}
# Add vms.c and vms.o to these lists if the operating system is VMS
SRCS = golddig.c shared.c badguy.c movement.c scores.c moveall.c
OBJS = golddig.o shared.o badguy.o movement.o scores.o moveall.o

# Common compilers
#CC = cc
#CC = gcc

# Some common choices for CFLAGS.
#CFLAGS = -O2 -I/usr/X11R6/include
CFLAGS+= -I${X11BASE}/include
#CFLAGS = -O
#CFLAGS = -O -W -Wreturn-type -Wunused -g -finline-functions
#CFLAGS = -g
#LDFLAGS = -g

# install options
#
SCORE_GROUP?=games
#
INSTALL?=install
COPY?=-c
GAMEOWN?=root
GAMEGRP?=wheel
GAMEMODE?=0555
GAMEDATAMODE?=0444
GAMEDIRMODE?=0755
MANOWN?=root
MANGRP?=wheel
MANMODE?=0444
#
#
BSD_INSTALL_GAME_DIR?= \
	${INSTALL} -d -o ${GAMEOWN} -g ${GAMEGRP} -m ${GAMEDIRMODE}
#
BSD_INSTALL_GAME?=          \
        ${INSTALL} ${COPY} ${_STRIPFLAG_INSTALL} -o ${GAMEOWN} \
	-g ${GAMEGRP} -m ${GAMEMODE}
#
BSD_INSTALL_GAME_DATA?=     \
        ${INSTALL} ${COPY} -o ${GAMEOWN} -g ${GAMEGRP} -m ${GAMEDATAMODE}
#
BSD_INSTALL_MAN?=           \
        ${INSTALL} ${COPY} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
#


all: ${GAME} ${EDITOR}

install: ${GAME} ${EDITOR}
	${BSD_INSTALL_GAME_DIR} ${LIB}
	${BSD_INSTALL_GAME} ${GAME} ${BIN}
	${BSD_INSTALL_GAME} ${EDITOR} ${BIN}
	${BSD_INSTALL_GAME_DIR} /var/games
	touch golddig.scores
	${BSD_INSTALL_GAME_DATA} golddig.scores /var/games/golddig.scores
	${BSD_INSTALL_GAME_DATA} levs/goldlev* levs/default ${LIB}
	${BSD_INSTALL_MAN} golddig.6 ${MAN}/golddig.${MANEXT}
	${BSD_INSTALL_MAN} gdedit.6 ${MAN}/gdedit.${MANEXT}
	chgrp ${SCORE_GROUP} ${BIN}/${GAME}
	chmod g+s ${BIN}/${GAME}
	chgrp ${SCORE_GROUP} /var/games/golddig.scores
	chmod 0664 /var/games/golddig.scores

update: ${GAME} ${EDITOR}
	cp ${GAME} ${EDITOR} ${BIN}
# The next line sets up the level files so that anyone can edit all of
# the levels.  Remove this line to have better security.
	chmod 4755 ${BIN}/${EDITOR}

clean:
	rm -f *.o *~ bitmap/*~ bitmaps.h core ${GAME} ${EDITOR}

lint:
	lint -DLIB=\"${LIB}\" ${SRCS}

${GAME}: ${OBJS}
	${CC} ${LDFLAGS} -o ${GAME} ${OBJS} -lX11

${EDITOR}: makelev.o shared.o
	${CC} ${LDFLAGS} -o ${EDITOR} makelev.o shared.o -lX11

shared.o: shared.c bitmaps.h

bitmaps.h: bitmap/*.bits
	cat bitmap/*.bits > bitmaps.h

.c.o:
	${CC} ${CFLAGS} -c -I. -DLIB=\"${LIB}\" $<
