# Makefile for 'XNibbles' game
# Copyright (C) 1998 Sean MacIsaac and Ian Peters
 
# 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 of 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
# Specific questions about this program can be addressed to the authors,
# Sean Macisaac (sjm@acm.org), and Ian Peters (ipeters@acm.org).

### GENERAL OPTIONS ###

  # Compiler to use (C++ compiler _please_)
  CC = g++

  # Directory for XNibbles specific data
  # This must be set correctly at compile time
  DATADIR = /usr/local/games/xnibbles

  # Prefix to find bin and man directories for installation
  PREFIX  = /usr/local

  # Install program
  INSTALL = /usr/bin/install

  # User to own the program
  USER = 0
  GROUP = 0

### LINUX ONLY OPTIONS ###

  # Requires kernel sound support, change from 0 to 1 if you want it
  SOUND = 1
  SOUNDDEV = /dev/dsp

  # Requires kernel joystick support, change from 0 to 1 if you want it
  JOYSTICK = 1
  JOYSTICK0DEV = /dev/js0
  JOYSTICK1DEV = /dev/js1

### DO NOT EDIT BELOW THIS LINE (UNLESS YOU KNOW WHAT YOU ARE DOING) ###

ifeq ($(SOUND),1)
  OBJECTS += sound.o
  SDEV = -D__SOUND__ -DSOUNDDEV=\"$(SOUNDDEV)\"
endif

ifeq ($(JOYSTICK),1)
  OBJECTS += joystick.o
  JDEV = -D__JOYSTICK__ -DJOYSTICK0DEV=\"$(JOYSTICK0DEV)\" -DJOYSTICK1DEV=\"$(JOYSTICK1DEV)\"
endif

nothing-specified:
	@echo ""
	@echo "You must specify a target system:"
	@echo ""
	@echo "make linux               Linux on ix86"
	@echo "make irix                Irix 5.3 (6.x?)"
	@echo ""
	@echo "Check the README file for help."
	@echo ""

linux:
	$(MAKE) OBJECTS='$(OBJECTS)' \
	CC=$(CC) LDFLAGS='-L/usr/X11R6/lib' \
	CFLAGS='-Wall -O2 $(SDEV) \
	-I/usr/X11R6/include -fwritable-strings \
	$(JDEV) \
	-DDATADIR=\"$(DATADIR)\"' \
	all

irix:
	$(MAKE) OBJECTS= \
	CC=$(CC) LDFLAGS='-L/usr/X11/lib' \
	CFLAGS='-Wall -O2 -I/usr/include/X11 \
	-DDATADIR=\"$(DATADIR)\"' \
	all

xnibbles: bodyPart.o boni.o bonus.o deadWorm.o levels.o people.o $(OBJECTS) statusBar.o ticker.o timer.o walls.o worm.o xnibbles.o xpms.o counter.o
	$(CC) $(CFLAGS) $(LDFLAGS) \
	bodyPart.o boni.o bonus.o levels.o people.o statusBar.o ticker.o \
	timer.o walls.o worm.o xnibbles.o xpms.o $(OBJECTS) deadWorm.o counter.o \
	-o xnibbles -lm -lXpm -lX11

xnleditor: xnleditor/level.o xnleditor/newWalls.o xnleditor/sideBar.o xnleditor/walls.o xnleditor/xnleditor.o xnleditor/xpms.o xnleditor/numericDisplay.o
	$(CC) $(CFLAGS) $(LDFLAGS) \
	xnleditor/level.o xnleditor/newWalls.o xnleditor/sideBar.o \
	xnleditor/walls.o xnleditor/xnleditor.o xnleditor/xpms.o \
	xnleditor/numericDisplay.o \
	-o xnleditor/xnleditor -lm -lXpm -lX11

all: xnibbles xnleditor

clean:
	rm -f *.o
	rm -f xnleditor/*.o
	rm -f core
	rm -f xnleditor/core

pristine: clean
	rm -f xnibbles
	rm -f xnleditor/xnleditor

tar: pristine
	(cd ..; tar -cvzf xnibbles.tgz xnibbles/ ; chmod 644 xnibbles.tgz)

install:
	$(INSTALL) -d $(DATADIR) -g $(GROUP) -m 755 -o $(USER)
	$(INSTALL) -d $(DATADIR)/levels -g $(GROUP) -m 755 -o $(USER)
	$(INSTALL) -d $(DATADIR)/sounds -g $(GROUP) -m 755 -o $(USER)
	$(INSTALL) -d $(PREFIX) -g $(GROUP) -m 755 -o $(USER)
	$(INSTALL) -d $(PREFIX)/bin -g $(GROUP) -m 755 -o $(USER)
	$(INSTALL) -d $(PREFIX)/man -g $(GROUP) -m 755 -o $(USER)
	$(INSTALL) -d $(PREFIX)/man/man6 -g $(GROUP) -m 755 -o $(USER)
	$(INSTALL) -g $(GROUP) -m 644 -o $(USER) levels/*.xnl $(DATADIR)/levels
	$(INSTALL) -g $(GROUP) -m 644 -o $(USER) levels/README $(DATADIR)/levels
	$(INSTALL) -g $(GROUP) -m 644 -o $(USER) sounds/*.ub $(DATADIR)/sounds
	$(INSTALL) -g $(GROUP) -m 755 -o $(USER) xnibbles $(PREFIX)/bin
	$(INSTALL) -g $(GROUP) -m 755 -o $(USER) xnleditor/xnleditor $(PREFIX)/bin
	$(INSTALL) -g $(GROUP) -m 644 -o $(USER) xnibbles.6 $(PREFIX)/man/man6
	./make-LEVELS $(DATADIR) OOGA

bodyPart.o:	common.h bodyPart.h
boni.o:	common.h boni.h
bonus.o:	common.h bonus.h
levels.o:	common.h levels.h Makefile
people.o:	common.h people.h
sound.o:	sound.h
joystick.o:	joystick.h
statusBar.o:	common.h statusBar.h
ticker.o:	common.h ticker.h
timer.o:	common.h timer.h
walls.o:	common.h walls.h
worm.o:	common.h worm.h Makefile
xnibbles.o:	common.h Makefile
xpms.o:	xpms/*.xpm
