# This variable needs to be set according to the architecture
# of the machine you are compiling on.  When htool runs make,
# it sets ARCH for you on the make command line.
# To compile a node program manually, you must
# supply ARCH yourself.  To do this, either type 
# "make ARCH=whatever", or just edit this Makefile to
# explicitly set the value below.
#ARCH	=	ALPHA

# The WHERE variable contains the name of a file that
# contains a list of hosts on which to compile this program.
# If $(WHERE) is "local" or empty, the stuff gets compiled
# on the local machine only.
# WHERE=local

# The following defines are set from these X resources:
# HLIBDIR	htool.henceLibDir
# PLIB	htool.pvm3Lib
# XDIR	htool.binDir
# INCLUDES	htool.includeDir
HLIBDIR	=	$(HOME)/hence/$(ARCH)
PLIB	=	$(HOME)/pvm3/lib/$(ARCH)/libpvm3.a
XDIR	=	$(HOME)/pvm3/bin/$(ARCH)
INCLUDES=	-I$(HOME)/src/hence/master/include

# work around brain-damage in some versions of make
SHELL	=	/bin/sh
MAKE	=	make

HLIBS	=	$(HLIBDIR)/libslave3.a \
		$(HLIBDIR)/libhence3.a \
		$(HLIBDIR)/librb.a \
		$(HLIBDIR)/libdl.a \
		$(HLIBDIR)/liballoc.a \
		$(PLIB) 

# The correct definitions of these macros
# vary from one system to another.
# Uncomment and/or redefine as necessary.
#CC	=	cc
FORT	=	`case "$(FC)@$(F77)" in *@) echo $(FC) ;; @*) echo $(F77) ;; *) echo f77;; esac`
#
# CFLAGS is used here to allow us to add the -DIMA_$(ARCH)
# option to the default compile rule for C programs.
# If you need to add -g or -O or whatever, put them in
# CDEBUGFLAGS or just type "make CDEBUGFLAGS=whatever"
#
#CDEBUGFLAGS=-g
CFLAGS	=	-DIMA_$(ARCH) -DPVM3 $(CDEBUGFLAGS)

PROGRAMS=collect start tile 
PVMMAKE=set -x ; case "$(WHERE)" in \
	local|"") \
		$(MAKE) $(MFLAGS) ARCH=$(ARCH) HOME=$(HOME) $@.local ;;\
	*)pvmrsh -h `cat $(WHERE)` -f *.[chf] Makefile -c \
		make $(MFLAGS) $@.local 'HOME=$$(HOME)' 'ARCH=$$(ARCH)' ;;\
	esac

all:
	@$(PVMMAKE)

all.local: $(PROGRAMS)

install:
	@$(PVMMAKE)

install.local: $(PROGRAMS)
	@- if [ ! -d $(XDIR) ] ; then \
		echo creating dir $(XDIR) ; \
		mkdir $(XDIR) ; \
	fi ; \
	exit 0
	cp $(PROGRAMS) $(XDIR)

clean:
	@$(PVMMAKE)

clean.local:
	rm -f $(PROGRAMS) *.o

collect:	collect.o w_collect.o $(HLIBS)
	$(CC) $(CFLAGS) -o collect collect.o w_collect.o $(HLIBS)

w_collect.o:	cw_collect.c
	$(CC) $(CFLAGS) $(INCLUDES)  -c cw_collect.c
	mv cw_collect.o w_collect.o

start:	start.o w_start.o $(HLIBS)
	$(CC) $(CFLAGS) -o start start.o w_start.o $(HLIBS)

w_start.o:	cw_start.c
	$(CC) $(CFLAGS) $(INCLUDES)  -c cw_start.c
	mv cw_start.o w_start.o

tile:	tile.o w_tile.o $(HLIBS)
	$(CC) $(CFLAGS) -o tile tile.o w_tile.o $(HLIBS)

w_tile.o:	cw_tile.c
	$(CC) $(CFLAGS) $(INCLUDES)  -c cw_tile.c
	mv cw_tile.o w_tile.o

