# Changes copyright (c) 1992-93 by Mark Hill, James Larus, and David Wood for
# the Wisconsin Wind Tunnel Project.
#
# ALL RIGHTS RESERVED.
#
# This software is furnished under a license and may be used and
# copied only in accordance with the terms of such license and the
# inclusion of the above copyright notice.  This software or any other
# copies thereof or any derivative works may not be provided or
# otherwise made available to any other persons.  Title to and ownership
# of the software is retained by Mark Hill, James Larus, and David Wood.
# Any use of this software must include the above copyright notice.
#
# THIS SOFTWARE IS PROVIDED "AS IS".  THE LICENSOR MAKES NO
# WARRANTIES ABOUT ITS CORRECTNESS OR PERFORMANCE.
#
# 
# Modifications made by Babak Falsafi 
#

.KEEP_STATE:

WWTLIBDIR = $(WWT_ROOT)/Lib

MODEL = parmacs

TARGET = em3d

INC = -I$(WWT_ROOT)/Include/$(PROTOCOL) -I$(WWT_ROOT)/Include

# Add standard options to (potentially) already defined ones
CFLAGS += $(INC)
LDFLAGS += -n -dc -dp -e __wwt_startup_ -X
VTFLAGS += -d -w

LIBDIRS += -L$(WWTLIBDIR) -L$(WWTLIBDIR)/$(PROTOCOL)
LIBS += -l$(MODEL) -lm -lc

OBJS = em3d.o make_graph.o mcs_lock.o /lib/crt0.o

#==============
# PARMACS stuff
#==============
MACDIR = $(WWTLIBDIR)
MACROS = $(MACDIR)/c.m4.monmacs $(MACDIR)/c.m4.smacs $(MACDIR)/c.m4.local
#==============

.SUFFIXES:
.SUFFIXES: .o .c .U .C .V .h .H .u

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

%.o: $(SRCDIR)/%.c
	$(CC) -c $(CFLAGS) $(SRCDIR)/$*.c

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

%.o: $(SRCDIR)/%.C
	$(CC) -c $(CFLAGS) $(SRCDIR)/$*.C

%.c: %.U
	m4 $(MACROS) $*.U > $*.c

%.c: $(SRCDIR)/%.U
	m4 $(MACROS) $(SRCDIR)/$*.U > $*.c

%.C: %.V
	m4 $(MACROS) $*.V > $*.C

%.C: $(SRCDIR)/%.V
	m4 $(MACROS) $(SRCDIR)/$*.V > $*.C

%.h: %.H
	m4 $(MACROS) $*.H > $*.h

%.h: $(SRCDIR)/%.H
	m4 $(MACROS) $(SRCDIR)/$*.H > $*.h

$(TARGET): $(OBJS)
	ld $(LDFLAGS) $(OBJS) -o $(TARGET).no-vt $(LIBDIRS) $(LIBS)
	/p/wwt/bin/vt -a $(TARGET) -d -w $(OTHER_VTFLAGS) $(TARGET).no-vt
	/bin/rm $(TARGET).no-vt

em3d.o make_graph.o: em3d.h
em3d.o make_graph.o mcs_lock.o: mcs_lock.h

clean:
	rm -f *.[cfoh] *.rej *.orig $(TARGET) $(TARGET).no-vt $(TARGET).Z

rcs:
	ci -m"checkpoint" -f -n"`mydate`" -l *.u *.H Makefile
