##############################################################################
#           Makefile for use by LiveData developers                          #
##############################################################################

#
#  This directory builds mgame.addin.
#
#  To compile with debug, use the env var CPP_DEBUG:
#
# setenv CPP_DEBUG -g
#
#

# If the location of the Alias libraries and header files are
# different from $ALIAS_LOCATION, set it here.
# Also if the location of the Games files is different, then 
# update the locations below.
#
ALIAS_LOCATION=/usr/aw/alias
GAMES_LOCATION=$(ALIAS_LOCATION)/ODS/Games
SHELL=/bin/sh

GAME_ADDIN =  mgame.addin

GAME_LIBS = $(GAMES_LOCATION)/lib/libDtOMio.so $(GAMES_LOCATION)/lib/libDtUt.so 

CC = cc
CPLUSPLUS = CC
INCLUDES = -I. -I$(ALIAS_LOCATION)/ODS/Common/include -I$(GAMES_LOCATION)/include

#
# Some code is conditionally compiled because it produces a lot of output.
# (see AlPrint.c++ for example) Uncomment the following line if you would
# like to see all the output.
#
# COPIOUS_OUTPUT = -DCOPIOUS_OUTPUT

#
# the -prototypes flag causes a warning message to be displayed on 
# IRIX 5.3 machines, but doesn't affect the plugins in any way.
#  Local macros used on the compile line. Use the env var
#  CPP_DEBUG to turn on debug (setenv CPP_DEBUG -g).
#
# CFLAGS = ${CPP_DEBUG} -xansi -signed -prototypes $(INCLUDES) $(COPIOUS_OUTPUT)
CFLAGS = ${CPP_DEBUG} -xansi -signed $(INCLUDES) $(COPIOUS_OUTPUT)
CPLUSPLUSFLAGS = $(CFLAGS)

# 
# The 'libLiveData.so' tells the linker to check the DSO for the Alias api
# symbols.  If you do not specify this, you will see all of the references
# to the Alias api symbols.  This is not harmful, since these symbols are
# resolved when the plugin is loaded.
#
PLUGINFLAGS = -shared -all $(ALIAS_LOCATION)/lib/libLiveData.so 
LFLAGS=-r 

#
# Rules for building.
#
.SUFFIXES: .addin .plugin .o .c++ .c

.c++.addin:
	$(CPLUSPLUS) -c $(CPLUSPLUSFLAGS) $<
	$(CPLUSPLUS) $(PLUGINFLAGS) -o $*.addin $*.o

.c++.plugin:
	$(CPLUSPLUS) -c $(CPLUSPLUSFLAGS) $<
	$(CPLUSPLUS) $(PLUGINFLAGS) -o $*.plugin $*.o

.o.plugin:
	$(CPLUSPLUS) $(PLUGINFLAGS) -o $*.plugin $<

.c++.o:
	$(CPLUSPLUS) -c $(CPLUSPLUSFLAGS) $*.c++

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

.o:
	$(CPLUSPLUS) $(LFLAGS) -o $@ $? $(CLIBS)

.c.i:
	 $(CC) -E $(CFLAGS) $*.c | sed -e '/^[    ]*$$/d' > $*.i

.c++.i:
	$(CPLUSPLUS) -E $(CPLUSPLUSFLAGS) $*.c++ | sed -e '/^[  ]*$$/d' > $*.i

#
# Build all the examples.
#
default: $(GAME_ADDIN)

#
# Copy all the source files for the examples.
#
copy:
	cp $(ALIAS_LOCATION)/ODS/Games/mgame/*.[ch]* .
	cp $(ALIAS_LOCATION)/ODS/Games/include/*.[ch]* .

#
# Clean up.
#
clean:
	rm *.o $(GAME_ADDIN)

#
# Rules for building specific examples.
#

$(GAME_ADDIN): mgame.o 
	$(CPLUSPLUS) $(PLUGINFLAGS) $(GAME_LIBS) -o $@ mgame.o -lXm -lX11 -lXt -lSgm
