#
# v0.9
#
# Space Makefile
#
# Cameron K. Smith, September 1997
# 
# Dependancy code added by Mark Cooke
#
# This program is free software and may be freely redistributed as 
# specified in the GNU General Public License.  Please see the file
# 'COPYING' for details.
#

# User configurable portion

###############################################################################
#                You should not have to edit below this point.                #
###############################################################################

CC = gcc
CFLAGS = $(INCDIR) $(MUDCFLAGS) -O3 -g -Wall

# Used for testing. 
#CFLAGS = -Wall -Wpointer-arith -Wcast-qual -Wconversion -Wstrict-prototypes \
#	-Wmissing-prototypes -Wmissing-declarations $(INCDIR) $(MUDCFLAGS)

BASE_OBJS =	commands.o events.o hashtab.o object.o sensors.o damage.o \
		eng.o tactical.o nav.o shields.o comm.o smain.o smisc.o \
		platform.o scmlib.o scm.o varray.o flag.o

BASE_SRC =	commands.c events.c hashtab.c object.c sensors.c damage.c \
		eng.c tactical.c nav.c shields.c comm.c smain.c smisc.c \
		platform.c scm.c varray.c flag.c

OBJS = $(BASE_OBJS)

# Build the list of modules in the scm directory dynamically. That way custom
# extras should be linked in automatically.

SCM_C    = $(shell ls scm/scm_*.c )
SCM_O    = $(shell ls scm/scm_*.c | sed -e"s/\\.c/\\.o/g" )
SCM_BASE = $(shell ls scm/scm_*.c | sed -e"s/\\.c//g" -e"s/^scm\///g" )

all:
	@echo The engine must be compiled along with the MU* server. The \
	Makefile in the
	@echo server directory should automatically do this.

engine:	do-it-all

space.o: $(OBJS)
	$(LD) -r -o space.o $(OBJS)

clean:
	-rm -f *.o scm/*.o scmlib.h scm.def unsplit .depend

unsplit: unsplit.c

depend: $(BASE_SRC) $(SCM_C) unsplit scmlib.h scm.def
	for i in $(BASE_SRC) $(SCM_C) ; do $(CC) $(CFLAGS) -M $$i; done | sed -e 's:/usr[^ ]* ::g' | ./unsplit > .depend~
	mv .depend~ .depend

distclean: clean


scmlib.h: $(SCM_C) scm/scm.h
	@echo "/* Interface structures for the plugins */" > scmlib.h
	@for i in $(SCM_BASE); do echo "extern SCM_INTERFACE" $$i";" >> scmlib.h; done

scm.def: $(SCM_C) scm/scm.h
	@echo "static SCM_INTERFACE* scm_plugins[]= {" > scm.def
	@for i in $(SCM_BASE); do echo "&"$$i"," >> scm.def ; done
	@echo "NULL };" >> scm.def

scmlib.o: $(SCM_O) scm/scm.h
	$(LD) -r -o scmlib.o $(SCM_O)

scm.o: scm.def scmlib.h scm.c scmlib.o scm/scm.h

ifeq (.depend,$(wildcard .depend))
include .depend
do-it-all:      space.o
else
do-it-all:      depend space.o
endif

