#
## Makefile -- I must learn autoconf one of these days...
## Author          : Julian Peterson <weaver@earthcorp.com>
## Last Modified On: Fri Mar 10 21:53:05 2000
## $Id: Makefile,v 0.93 2000/03/11 02:53:22 julian Exp julian $
#

# INSTALLATION DIRS:
# binary will be installed to $game_prefix/$game_bin
# data to $game_prefix/$game_data
game_prefix      = /usr/local
game_bin         = bin
game_data        = share/missile


# who the owner of the installed game will be
install_as_owner = root
install_as_group = root


# for packaging
dist_name      	 = $(PROGRAM)
dist_dir       	 = $(PROGRAM)
dist_ver       	 = 0.99.0
dist_release   	 = 1


########################################################################
# Shouldn't need to play with much below here


#  The name of the program, its components, and the locations of include
#  files and libraries:
#

PROGRAM   = missile
DATA      = data

SOURCES   = missile.c
OBJECTS   = $(SOURCES:.c=.o)
LIBS      = `sdl-config --libs` -lSDL_image -lSDL_ttf
INCLUDE   =

# no good...
STATIC_LIBS = /usr/lib/libSDL.a /usr/lib/libSDL_image.a /usr/lib/libSDL_ttf.a -lm -lX11 -lXext -lXmu -lXt -lXi -lSM -lICE -ldl -lesd -lpthread 


#
#  Flags for the C compiler and make:
#
CC      = gcc
OPTS    = -DDATA='"$(game_prefix)/$(game_data)"'
CFLAGS  = -Wall -g $(OPTS) `sdl-config --cflags` 
SHELL   = /bin/sh

#
#  Flags for tar
#
TAR         = tar
TAR_FLAGS   = -cvz
TAR_EXCLUDE = --exclude $(dist_dir)/RCS --exclude $(dist_dir)/scrap \
              --exclude $(dist_name)-$(dist_ver).tar.gz             \
              --exclude $(dist_name)-$(dist_ver).src.tar.gz


#
#  Flags for install
#
INSTALL   = install
EXEC_PERM = -m 755
FILE_PERM = -m 644
IFLAGS    = -C -o $(install_as_owner) -g $(install_as_group)


#
#  Remake the program, by default:
#
all: $(PROGRAM)


$(PROGRAM):	$(OBJECTS)
		$(CC) -o $(PROGRAM) $(OBJECTS) $(CFLAGS) $(LIBS)


%.o : %.c %.h
	$(CC) $(CFLAGS) -c $< $(INCLUDE)


%.o : %.c
	$(CC) $(CFLAGS) -c $< $(INCLUDE)



install :
	strip $(PROGRAM)
	$(INSTALL) $(IFLAGS) $(EXEC_PERM) $(PROGRAM) $(game_prefix)/$(game_bin)/$(PROGRAM)
	cd $(DATA);\
	for f in `ls`; do \
	  $(INSTALL) $(IFLAGS) $(FILE_PERM) $$f $(game_prefix)/$(game_data)/$$f;\
	done
	@echo ""
	@echo "---------------------------------------------------------------------"
	@echo "Installation complete."
	@echo "---------------------------------------------------------------------"

uninstall :
	rm $(game_prefix)/$(game_bin)/$(PROGRAM)
	rm -rf $(game_prefix)/$(game_data)
	@echo ""
	@echo "---------------------------------------------------------------------"
	@echo "$(PROGRAM) and associated files uninstalled."
	@echo "User preferences are left in ~/.missilecommandrc"
	@echo "---------------------------------------------------------------------"



dist: nuke
	cd ..;\
  $(TAR) $(TAR_FLAGS) $(TAR_EXCLUDE) \
		-f $(dist_name)-$(dist_ver).src.tar.gz \
		$(dist_dir); \
		mv $(dist_name)-$(dist_ver).src.tar.gz $(dist_dir)


bindist: nuke
	make all
	cd ..;\
  $(TAR) $(TAR_FLAGS) $(TAR_EXCLUDE) \
		-f $(dist_name)-$(dist_ver).tar.gz \
		$(dist_dir); \
		mv $(dist_name)-$(dist_ver).tar.gz $(dist_dir)



clean:
	- rm -f *.o core `find . -name "*~"` 

nuke: clean
	- rm -f $(PROGRAM)
	- rm gdb-transcript .kdbgrc.missile gmon.out

pristine: nuke
	- rm $(dist_name)-$(dist_ver).tar.gz $(dist_dir)
	- rm $(dist_name)-$(dist_ver).src.tar.gz
