###################################
# To compile, type 'make' as root #
###################################

#################################### FEATURES ################################
# add -DJOYSTICK to have joystick support (must have joystick kernel
# patches and devices installed)
#
# add -DCOMPILED_BITMAPS to try the svgalib compiled bitmap support
# (should speed up the game, especially on slower video cards), but its
# not working perfectly yet. (can cause segfaults)
#
# Here's an example: 
# FEATURES = -DJOYSTICK -DCOMPILE_BITMAPS
#
# Note: if you change the feature line below, run 'make clean' before
# compiling the game.

FEATURES =


# This is where the high score list will be stored
SCOREDIR = /var/games


# Where the executable will be placed
BINDIR   = /usr/games


##############################################################################
#************  Probably don't need to edit anything after this ***************
##############################################################################

VERSION  = 1.2

# the .xpm to c translator
XPM2BIT = ./xpm2bit

CC	 = g++
INC      = -I/usr/local/include
OPTIMIZE = -fomit-frame-pointer -O2 -s
DEBUG    = -g
OPTS	 = -Wall -m486 -pipe

DEFINES  = $(FEATURES) -DSCOREDIR=\"$(SCOREDIR)/\" -DVERSION=\"$(VERSION)\"

# regular use
CFLAGS	 = $(DEFINES) $(INC) $(OPTIMIZE) $(OPTS)

# for debugging/profiling
#CFLAGS	 = $(DEFINES) $(INC) $(DEBUG) $(OPTS)

#LFLAGS   = -static

INSTALLSCRIPT = installbin

PROG    = sasteroids
PROG_O  = sasteroids.o bitmaps.o titleScn.o HiScore.o Bitmap.o str.o \
	  Timer.o Ui.o backScn.o ObjTools.o Obj.o FastMath.o Explosion.o \
	  Sprite.o Joystick.o Keyboard.o Sound.o fonts.o

#LIBS     = -lvgagl -lvga -lm -lgmon
LIBS     = -lvgagl -lvga -lm

# name of tar.gz file for source/bin distributions
PACKAGE  = $(PROG)$(VERSION)

all:	$(PROG)
	@echo 
	@echo Sasteroids has successfully compiled.
	@echo Type 'make install' to install sasteroids in
	@echo $(BINDIR)
	@echo

install: makeinstallscript $(PROG)
	./$(INSTALLSCRIPT)

$(PROG): $(PROG_O)
	$(CC) $(LFLAGS) $(PROG_O) -o $(PROG) $(LIBS)

cleanbin: clean
	rm -f $(PROG)

clean:
	rm -f *.o *~

depend:
	makedepend -- $(INC) -- *.c

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

.c.s:
	$(CC) $(CFLAGS) -S -o $*.s $<


# this creates the source .tar.gz distribution.
distrib:
	rm -rf $(PACKAGE)-src.tar.gz
	( cd .. ; mv $(PROG) $(PACKAGE) )
	( cd .. ; tar zchvvf $(PACKAGE)/$(PACKAGE)-src.tar.gz $(PACKAGE)/*.[ch] \
		  $(PACKAGE)/?akefile $(PACKAGE)/1-* )
	( cd .. ; mv $(PACKAGE) $(PROG) )
	@echo $(PACKAGE)-src.tar.gz has been created.

# this creates the bin distribution
bindistrib: makeinstallscript
	rm -rf sasteroids.o
	rm -rf Joystick.o
	make LFLAGS=-static FEATURES=-DJOYSTICK
	strip $(PROG)
	rm -rf $(PACKAGE)-bin.tar.gz
	( cd .. ; mv $(PROG) $(PACKAGE) )        
	( cd .. ; tar zchvvf $(PACKAGE)/$(PACKAGE)-bin.tar.gz  \
                            $(PACKAGE)/$(PROG) $(PACKAGE)/2-* \
			    $(PACKAGE)/$(INSTALLSCRIPT) )
	( cd .. ; mv $(PACKAGE) $(PROG) )
	@echo $(PACKAGE)-bin.tar.gz has been created.

# this creates the xpm (pixmap) distribution, for editing the graphics
xpmdistrib:
	rm -rf $(PACKAGE)-xpm.tar.gz
	( cd .. ; mv $(PROG) $(PACKAGE) )
	( cd .. ; tar zchvvf $(PACKAGE)/$(PACKAGE)-xpm.tar.gz \
		  $(PACKAGE)/3-* \
		  $(PACKAGE)/*xpm $(PACKAGE)/$(XPM2BIT) )
	( cd .. ; mv $(PACKAGE) $(PROG) )
	@echo $(PACKAGE)-xpm.tar.gz has been created.

# creates the script to install the final program
makeinstallscript:
	@echo "#!/bin/sh" > $(INSTALLSCRIPT)
	@echo "install -d $(SCOREDIR)"  >> $(INSTALLSCRIPT)
	@echo "install -d $(BINDIR)"  >> $(INSTALLSCRIPT)
	@echo "install --strip --mode=4755 $(PROG) $(BINDIR)"  >> $(INSTALLSCRIPT)
	chmod +rx $(INSTALLSCRIPT)


# do a 'make newbitmaps' if you edit the .xpm files
# You need the sasteroids xpm distribution to use this.
newbitmaps: make-sprites make-title make-back

SPRITES = smallast.xpm medast.xpm bigast.xpm bullet.xpm bullet2.xpm enemy.xpm \
          ship0.xpm ship1.xpm spinner.xpm \
	  morph1.xpm morph2.xpm morph3.xpm morph4.xpm morph5.xpm morph6.xpm \
	  morph7.xpm morph8.xpm morph9.xpm shield.xpm

make-sprites:
	rm -rf bitmaps.c
	$(XPM2BIT) -p bitmaps $(SPRITES)

make-title:
	rm -rf titleScn.c
	$(XPM2BIT) -p titleScn title.xpm

make-back:
	rm -rf backScn.c
	$(XPM2BIT) -p backScn back.xpm

# hand-made since 'makedepend' acts a little weird anyway.
Bitmap.o:	Bitmap.h FastMath.h
FastMath.o:	FastMath.h
ObjTools.o:	ObjTools.h FastMath.h
Sprite.o:	Sprite.h FastMath.h Explosion.h Bitmap.h ObjTools.h
Obj.o:		Sprite.h Obj.h ObjTools.h bitmaps.h Bitmap.h 
Explosion.o:	Bitmap.h ObjTools.h PtrList.h FastMath.h Explosion.h
HiScore.o:	HiScore.h str.h 
Timer.o:	Timer.h 
Ui.o: 		Ui.h str.h
Joystick.o:	Joystick.h
sasteroids.o: 	bitmaps.h Bitmap.h titleScn.h backScn.h Timer.h FastMath.h
sasteroids.o: 	sasteroids.h HiScore.h str.h Obj.h Ui.h ObjTools.h Joystick.h
sasteroids.o:	Keyboard.h Sound.h
Sound.o:	Sound.h
titleScn.o: 	titleScn.h Bitmap.h 
backScn.o: 	backScn.h Bitmap.h 
bitmaps.o: 	bitmaps.h Bitmap.h 
fonts.o:	Ui.h
str.o: 		str.h
