####################################################################
#   Copyright (c)
#
#   You may copy, distribute, and modify it freely as long as you  #
#   preserve this copyright and permission notice.                 #
#                                                                  #
#
####################################################################

#
#  Makefile for Adlib/src/adJava
#

SHELL   = /bin/sh

srcdir      = @srcdir@
top_srcdir  = @top_srcdir@

prefix      = @prefix@
exec_prefix = @exec_prefix@

bindir      = @bindir@
includedir  = @includedir@
libdir      = @libdir@

config_dir = ../include

VPATH       = .:${srcdir}

INSTALL     = cp

ADLIB       = $(top_srcdir)

MPICHLIB    = @MPI_LIB@
JAVA_HOME   = @JAVA@

TITLE = spmd

DIR = class

PKG = $(TITLE).
PFX = $(TITLE)_
POS = $(DIR)/$(TITLE)/

JC = ./jc
JH = ./jh

JCFLAG = @OPTIMIZE@ -d $(DIR)
JHFLAG = -jni

AD++ = $(ADLIB)/src/script/ad++

LD = ld

# The following two lines only work in aix
CC = xlc_r
MAKESHARELIB = /usr/lpp/xlC/bin/makeC++SharedLib

LIBSO = libspmdjava.so

NATIVE_CXX_OBJ= $(PFX)Dimension.o $(PFX)Group.o $(PFX)Procs.o \
		$(PFX)Range.o $(PFX)Stride.o $(PFX)DAD.o $(PFX)Location.o \
		$(PFX)CollapsedRange.o $(PFX)DimRange.o\
		$(PFX)BlockRange.o $(PFX)CyclicRange.o\
		$(PFX)LocBlocksIndex.o $(PFX)Index.o\
		$(PFX)SpmdEnv.o $(PFX)Clock.o\
		$(PFX)Remap.o $(PFX)Shift.o $(PFX)WriteHalo.o \
		$(PFX)Adlib.o

JAVACLASS= \
	$(POS)InterfaceObject.class \
	$(POS)Dimension.class $(POS) \
		$(POS)Range.class $(POS)Stride.class \
		$(POS)Location.class $(POS)LocBlocksIndex.class \
			$(POS)CollapsedRange.class $(POS)DimRange.class \
			$(POS)BlockRange.class $(POS)CyclicRange.class \
				$(POS)Index.class \
	$(POS)Group.class $(POS)Procs.class \
		$(POS)Procs0.class $(POS)Procs1.class $(POS)Procs2.class $(POS)Procs3.class \
	$(POS)SpmdEnv.class $(POS)Clock.class \
	$(POS)DAD.class \
	$(POS)Section.class \
		$(POS)Section0.class \
			$(POS)Array0Int.class $(POS)Array0Float.class \
		$(POS)Section1.class \
			$(POS)Array1Int.class $(POS)Array1Float.class \
		$(POS)Section2.class \
			$(POS)Array2Int.class $(POS)Array2Float.class \
		$(POS)Section3.class \
			$(POS)Array3Int.class $(POS)Array3Float.class \
		$(POS)Section4.class \
			$(POS)Array4Int.class $(POS)Array4Float.class \
		$(POS)Section5.class \
	$(POS)Remap.class $(POS)Shift.class $(POS)WriteHalo.class \
	$(POS)Adlib.class 

JCTABLE = jctable

.SUFFIXES:
.SUFFIXES: .java .h .class .C .o

.C.o:
	$(AD++) @OPTIMIZE@ -c -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/@JOS@ -o $@ $*.C

all: Makefile $(DIR) $(JAVACLASS) $(LIBSO)

Makefile: ${srcdir}/Makefile.in
	@echo 
	@echo Please configure the package to generate new makefile ...
	@exit

$(DIR): 
	mkdir $(DIR)
	mkdir $(DIR)/$(TITLE)

$(LIBSO): $(NATIVE_CXX_OBJ) 
	rm -f share.o
	rm -f libspmdjava.so
	if test "@JOS@" = "aix" ;\
	then \
	$(MAKESHARELIB) -o share.o -p 0 \
		-L$(JAVA_HOME)/lib/aix/native_threads -ljava \
		-L$(ADLIB)/src/kernel -ladlib \
		-L$(MPICHLIB) -lmpi \
		$(NATIVE_CXX_OBJ) ;\
	$(CC) -c -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/@JOS@ a.c ;\
	$(LD) -o $(LIBSO) a.o share.o -bnoentry -bM:SRE -bE:adlib.exp \
		-blibpath:/lib:/usr/lib -lc_r ;\
	fi
	if test "@JOS@" = "solaris" ;\
	then \
	$(LD) -o $(LIBSO) -G \
		$(NATIVE_CXX_OBJ) \
		-L$(JAVA_HOME)/lib/sparc -ljava \
		-L$(ADLIB)/src/kernel -ladlib \
		-L$(MPICHLIB) -lmpi \
		-L/opt/SUNWspro/lib -lC ;\
	fi
	if test "@JOS@" = "irix" ;\
	then \
	$(LD) -32 -o $(LIBSO) -shared \
		$(NATIVE_CXX_OBJ) \
		-L$(JAVA_HOME)/lib/sgi/green_threads -ljava \
		-L$(ADLIB)/src/kernel -ladlib \
		-L$(MPICHLIB) -lmpi -lc -lC -lm;  \
	fi	

clean:
	for Type in Int Float ; \
	do \
	  rm -f Array?$$Type.java ;\
        done 
	rm -f -r class
	rm -f $(PFX)*.h 
	rm -f core *.o libspmdjava.so

distclean:
	for Type in Int Float ; \
	do \
	  rm -f Array?$$Type.java ;\
        done 
	rm -f -r class
	rm -f $(PFX)*.h 
	rm -f core *.o libspmdjava.so
	rm Makefile

install: $(LIBSO) 
	if [ ! -d ${libdir} ] ; then mkdir ${libdir} ; fi
	if test "@JOS@" = "aix" ; then $(INSTALL) $(LIBSO) a.o share.o ${libdir}; fi
	if test "@JOS@" = "solaris" ; then $(INSTALL) $(LIBSO) ${libdir} ; fi
	if test "@JOS@" = "irix" ; then $(INSTALL) $(LIBSO) ${libdir} ; fi
	$(INSTALL) -r $(DIR)/$(TITLE) ${libdir}/

uninstall:
	if test "@JOS@" = "aix" ; \
	then rm -f ${libdir}/$(LIBSO) ${libdir}/a.o ${libdir}/share.o ; fi
	if test "@JOS@" = "solaris" ; then rm -f ${libdir}/$(LIBSO) ; fi
	rm -r -f ${libdir}/$(TITLE)

$(POS)InterfaceObject.class : InterfaceObject.java 
	$(JC) $(JCFLAG) InterfaceObject.java
	$(JH) $(JHFLAG) $(PKG)InterfaceObject

$(POS)Procs0.class: Procs0.java $(POS)Procs.class $(POS)Group.class
	$(JC) $(JCFLAG) Procs0.java	

$(POS)Procs1.class: Procs1.java $(POS)Procs.class $(POS)Group.class
	$(JC) $(JCFLAG) Procs1.java	

$(POS)Procs2.class: Procs2.java $(POS)Procs.class $(POS)Group.class
	$(JC) $(JCFLAG) Procs2.java	

$(POS)Procs3.class: Procs3.java $(POS)Procs.class $(POS)Group.class
	$(JC) $(JCFLAG) Procs3.java	

$(POS)Array0Int.class: Array0Int.java $(POS)Section0.class $(POS)Section.class
	$(JC) $(JCFLAG) Array0Int.java

Array0Int.java: Array0Type.in.java
	cat Array0Type.in.java |sed 's/@Type@/Int/g' \
	|sed 's/@type@/int/g' |sed 's/@key@/4/' > Array0Int.java 

$(POS)Array0Float.class: Array0Float.java $(POS)Section0.class $(POS)Section.class
	$(JC) $(JCFLAG) Array0Float.java

Array0Float.java: Array0Type.in.java
	cat Array0Type.in.java |sed 's/@Type@/Float/g' \
	|sed 's/@type@/float/g' |sed 's/@key@/6/' > Array0Float.java 

$(POS)Array1Int.class: Array1Int.java $(POS)Section1.class $(POS)Section.class
	$(JC) $(JCFLAG) Array1Int.java

Array1Int.java: Array1Type.in.java
	cat Array1Type.in.java |sed 's/@Type@/Int/g' \
	|sed 's/@type@/int/g' |sed 's/@key@/4/' > Array1Int.java 

$(POS)Array1Float.class: Array1Float.java $(POS)Section1.class $(POS)Section.class
	$(JC) $(JCFLAG) Array1Float.java

Array1Float.java: Array1Type.in.java
	cat Array1Type.in.java |sed 's/@Type@/Float/g' \
	|sed 's/@type@/float/g' |sed 's/@key@/6/' > Array1Float.java 

$(POS)Array2Int.class: Array2Int.java $(POS)Section2.class $(POS)Section.class
	$(JC) $(JCFLAG) Array2Int.java

Array2Int.java: Array2Type.in.java
	cat Array2Type.in.java |sed 's/@Type@/Int/g' \
	|sed 's/@type@/int/g' |sed 's/@key@/4/' > Array2Int.java 

$(POS)Array2Float.class: Array2Float.java $(POS)Section2.class $(POS)Section.class
	$(JC) $(JCFLAG) Array2Float.java

Array2Float.java: Array2Type.in.java
	cat Array2Type.in.java |sed 's/@Type@/Float/g' \
	|sed 's/@type@/float/g' |sed 's/@key@/6/' > Array2Float.java 

$(POS)Array3Int.class: Array3Int.java $(POS)Section3.class $(POS)Section.class
	$(JC) $(JCFLAG) Array3Int.java

Array3Int.java: Array3Type.in.java
	cat Array3Type.in.java |sed 's/@Type@/Int/g' \
	|sed 's/@type@/int/g' |sed 's/@key@/4/' > Array3Int.java 

$(POS)Array3Float.class: Array3Float.java $(POS)Section3.class $(POS)Section.class
	$(JC) $(JCFLAG) Array3Float.java

Array3Float.java: Array3Type.in.java
	cat Array3Type.in.java |sed 's/@Type@/Float/g' \
	|sed 's/@type@/float/g' |sed 's/@key@/6/' > Array3Float.java 

$(POS)Array4Int.class: Array4Int.java $(POS)Section4.class $(POS)Section.class
	$(JC) $(JCFLAG) Array4Int.java

Array4Int.java: Array4Type.in.java
	cat Array4Type.in.java |sed 's/@Type@/Int/g' \
	|sed 's/@type@/int/g' |sed 's/@key@/4/' > Array4Int.java 

$(POS)Array4Float.class: Array4Float.java $(POS)Section4.class $(POS)Section.class
	$(JC) $(JCFLAG) Array4Float.java

Array4Float.java: Array4Type.in.java
	cat Array4Type.in.java |sed 's/@Type@/Float/g' \
	|sed 's/@type@/float/g' |sed 's/@key@/6/' > Array4Float.java 

$(POS)Section.class: Section.java $(POS)DAD.class
	$(JC) $(JCFLAG) Section.java

$(POS)Section0.class: Section0.java $(POS)Section.class
	$(JC) $(JCFLAG) Section0.java

$(POS)Section1.class: Section1.java $(POS)Section.class
	$(JC) $(JCFLAG) Section1.java

$(POS)Section2.class: Section2.java $(POS)Section.class
	$(JC) $(JCFLAG) Section2.java

$(POS)Section3.class: Section3.java $(POS)Section.class
	$(JC) $(JCFLAG) Section3.java

$(POS)Section4.class: Section4.java $(POS)Section.class
	$(JC) $(JCFLAG) Section4.java

$(POS)Section5.class: Section5.java $(POS)Section.class
	$(JC) $(JCFLAG) Section5.java

$(POS)SpmdEnv.class : SpmdEnv.java $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) SpmdEnv.java 
	$(JH) $(JHFLAG) $(PKG)SpmdEnv

$(POS)Clock.class: Clock.java $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) Clock.java
	$(JH) $(JHFLAG) $(PKG)Clock

$(POS)Adlib.class : Adlib.java $(POS)InterfaceObject.class \
		$(POS)Section.class $(POS)Remap.class $(POS)Shift.class 
	$(JC) $(JCFLAG) Adlib.java
	$(JH) $(JHFLAG) $(PKG)Adlib 

$(POS)Dimension.class : Dimension.java $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) Dimension.java
	$(JH) $(JHFLAG) $(PKG)Dimension

$(POS)Procs.class : Procs.java $(POS)Dimension.class \
	$(POS)Range.class $(POS)InterfaceObject.class 
	$(JC) $(JCFLAG) Procs.java Group.java
	$(JH) $(JHFLAG) $(PKG)Procs
	$(JH) $(JHFLAG) $(PKG)Group

$(POS)Group.class : Group.java $(POS)Dimension.class $(POS)InterfaceObject.class 
	$(JC) $(JCFLAG) Procs.java Group.java 
	$(JH) $(JHFLAG) $(PKG)Procs
	$(JH) $(JHFLAG) $(PKG)Group

$(POS)Location.class : Location.java $(POS)InterfaceObject.class 
	$(JC) $(JCFLAG) Location.java Range.java Stride.java LocBlocksIndex.java
	$(JH) $(JHFLAG) $(PKG)Location
	$(JH) $(JHFLAG) $(PKG)Range
	$(JH) $(JHFLAG) $(PKG)Stride
	$(JH) $(JHFLAG) $(PKG)LocBlocksIndex

$(POS)Range.class : Range.java $(POS)InterfaceObject.class 
	$(JC) $(JCFLAG) Location.java Range.java Stride.java LocBlocksIndex.java
	$(JH) $(JHFLAG) $(PKG)Location
	$(JH) $(JHFLAG) $(PKG)Range
	$(JH) $(JHFLAG) $(PKG)Stride
	$(JH) $(JHFLAG) $(PKG)LocBlocksIndex

$(POS)Stride.class : Stride.java $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) Location.java Range.java Stride.java LocBlocksIndex.java
	$(JH) $(JHFLAG) $(PKG)Location
	$(JH) $(JHFLAG) $(PKG)Range
	$(JH) $(JHFLAG) $(PKG)Stride
	$(JH) $(JHFLAG) $(PKG)LocBlocksIndex

$(POS)LocBlocksIndex.class : LocBlocksIndex.java $(POS)InterfaceObject.class 
	$(JC) $(JCFLAG) Location.java Range.java Stride.java LocBlocksIndex.java
	$(JH) $(JHFLAG) $(PKG)Location
	$(JH) $(JHFLAG) $(PKG)Range
	$(JH) $(JHFLAG) $(PKG)Stride
	$(JH) $(JHFLAG) $(PKG)LocBlocksIndex

$(POS)CollapsedRange.class : CollapsedRange.java $(POS)Range.class $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) CollapsedRange.java
	$(JH) $(JHFLAG) $(PKG)CollapsedRange

$(POS)DimRange.class : DimRange.java $(POS)Range.class $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) DimRange.java
	$(JH) $(JHFLAG) $(PKG)DimRange

$(POS)BlockRange.class : BlockRange.java $(POS)Range.class $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) BlockRange.java
	$(JH) $(JHFLAG) $(PKG)BlockRange

$(POS)CyclicRange.class : CyclicRange.java $(POS)Range.class $(POS)InterfaceObject.class
	$(JC) $(JCFLAG) CyclicRange.java
	$(JH) $(JHFLAG) $(PKG)CyclicRange

$(POS)DAD.class : DAD.java $(POS)InterfaceObject.class \
		$(POS)Group.class $(POS)Range.class $(POS)Stride.class
	$(JC) $(JCFLAG) DAD.java
	$(JH) $(JHFLAG) $(PKG)DAD

$(POS)Index.class : Index.java $(POS)LocBlocksIndex.class \
		$(POS)InterfaceObject.class 
	$(JC) $(JCFLAG) Index.java
	$(JH) $(JHFLAG) $(PKG)Index

$(POS)Remap.class : Remap.java $(POS)InterfaceObject.class $(POS)DAD.class
	$(JC) $(JCFLAG) Remap.java
	$(JH) $(JHFLAG) $(PKG)Remap

$(POS)Shift.class : Shift.java $(POS)InterfaceObject.class $(POS)DAD.class
	$(JC) $(JCFLAG) Shift.java
	$(JH) $(JHFLAG) $(PKG)Shift

$(POS)WriteHalo.class : WriteHalo.java $(POS)InterfaceObject.class $(POS)DAD.class 
	$(JC) $(JCFLAG) WriteHalo.java
	$(JH) $(JHFLAG) $(PKG)WriteHalo

$(PFX)InterfaceObject.o : $(PFX)InterfaceObject.C $(PFX)InterfaceObject.h
$(PFX)AdlibPrintStream.o : $(PFX)AdlibPrintStream.C $(PFX)AdlibPrintStream.h
$(PFX)Adlib.o : $(PFX)Adlib.C $(PFX)Adlib.h
$(PFX)Dimension.o : $(PFX)Dimension.C $(PFX)Dimension.h $(JCTABLE).h
$(PFX)Procs.o : $(PFX)Procs.C $(PFX)Procs.h $(JCTABLE).h
$(PFX)Group.o : $(PFX)Group.C $(PFX)Group.h $(JCTABLE).h
$(PFX)Location.o : $(PFX)Location.C $(PFX)Location.h $(JCTABLE).h
$(PFX)Stride.o : $(PFX)Stride.C $(PFX)Stride.h $(JCTABLE).h
$(PFX)Range.o : $(PFX)Range.C $(PFX)Range.h $(JCTABLE).h
$(PFX)DAD.o : $(PFX)DAD.C $(PFX)DAD.h $(JCTABLE).h
$(PFX)BlockRange.o : $(PFX)BlockRange.C $(PFX)BlockRange.h $(JCTABLE).h
$(PFX)CyclicRange.o : $(PFX)CyclicRange.C $(PFX)CyclicRange.h $(JCTABLE).h
$(PFX)Remap.o : $(PFX)Remap.C $(PFX)Remap.h $(JCTABLE).h
$(PFX)Shift.o : $(PFX)Shift.C $(PFX)Shift.h $(JCTABLE).h
$(PFX)WriteHalo.o : $(PFX)WriteHalo.C $(PFX)WriteHalo.h $(JCTABLE).h
$(PFX)LocBlocksIndex.o : $(PFX)LocBlocksIndex.C $(PFX)LocBlocksIndex.h $(JCTABLE).h
$(PFX)Index.o : $(PFX)Index.C $(PFX)Index.h $(JCTABLE).h
