# $Id: Makefile.in,v 1.7 2001/11/16 03:51:26 m-hirano Exp $
# $RWC_Release: Omni-1.6 $
# $RWC_Copyright:
#  Omni Compiler Software Version 1.5-1.6
#  Copyright (C) 2002 PC Cluster Consortium
#  
#  This software is free software; you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License version
#  2.1 published by the Free Software Foundation.
#  
#  Omni Compiler Software Version 1.0-1.4
#  Copyright (C) 1999, 2000, 2001.
#   Tsukuba Research Center, Real World Computing Partnership, Japan.
#  
#  Please check the Copyright and License information in the files named
#  COPYRIGHT and LICENSE under the top  directory of the Omni Compiler
#  Software release kit.
#  
#  
#  $
#
#	Makefile for jexc, java byte code to C translator
#	using the second pass of the exc back-end as code generator.
#

TOPDIR		=	../..
prefix		=	@prefix@
exec_prefix	=	@exec_prefix@

INSTALLBINDIR	=	$(prefix)/bin
INSTALLLIBDIR	=	$(prefix)/lib
INSTALLLIBEXECDIR	=	 $(prefix)/lib/openmp/libexec
INSTALLINCDIR	=	$(prefix)/include
INSTALL		=	@INSTALLCOM@
MKDIR		=	@MKDIRCOM@

GCCINC		=	-I`case "$(CC)" in *gcc) echo \`$(CC) -v 2>&1 | grep specs | sed 's/specs$$/include/' | awk '{ print $$NF }'\`;; esac`


CC_OPT_SWITCH	=	@CFLAGS@
CPPFLAGS	=	-I. -I$(TOPDIR)/include @DEFS@ @CPPFLAGS@
CFLAGS		=	$(CC_OPT_SWITCH) $(CPPFLAGS)

CC		=	@CC@

AR		=	@AR@
RANLIB		=	@RANLIB@

JEXC		=	CLASSPATH=$${CLASSPATH}:../../exc-tools-java ./jexc

DEPEND_SWITCH	=	$(CPPFLAGS)

DUMP_OBJ = dump_class.o read_class_file.o jexc_dump.o jexc_mem.o \
	jexc_util.o jexc_misc.o

JEXC_OBJ =  jexc_main.o jexc_translate.o jexc_sys_class.o jexc_trans_code.o \
	read_class_file.o jexc_dump.o jexc_mem.o jexc_util.o jexc_misc.o \
	mach-dep.o

RUNTIME_OBJS = jexc_runtime.o jexc_gc.o jexc_java_lang.o jexc_java_io.o jexc_java_util.o

EXE_TARGET = jexc dump_class
LIB_TARGET = libjexc.a
INC_TARGET = jexc_vm.h jexc_runtime.h jexc_sys_class.h

DYN_GEN	= jvm-opcode.h jvm-opcode.c jexc_sys_class.def.c

all:	$(DYN_GEN) $(EXE_TARGET) $(LIB_TARGET) @jexcBackend@

jexc:	$(DYN_GEN) $(JEXC_OBJ) 
	$(CC) $(CFLAGS) -o jexc $(JEXC_OBJ)

dump_class:	$(DYN_GEN) $(DUMP_OBJ)
	$(CC) $(CFLAGS) -o dump_class $(DUMP_OBJ)

jvm-opcode.h:	jvm.opcode jvm-opcode.h.awk
	awk -f jvm-opcode.h.awk < jvm.opcode > jvm-opcode.h

jvm-opcode.c:	jvm.opcode jvm-opcode.c.awk
	awk -f jvm-opcode.c.awk < jvm.opcode > jvm-opcode.c

jexc_sys_class.def.c:	jexc_sys_class.def jexc_sys_class.awk
	awk -f jexc_sys_class.awk < jexc_sys_class.def > jexc_sys_class.def.c

jexc_util.o:	jvm-opcode.c
jexc_sys_class.o:	jexc_sys_class.def.c

libjexc.a:	$(DYN_GEN) $(RUNTIME_OBJS)
	$(AR) $@ $(RUNTIME_OBJS)
	$(RANLIB) $@

C-back:	jexc libjexc.a exc.lst
	$(JEXC) -main exc/util/ompcc -package-list ./exc.lst
	mv ./jexc.out.c ./C-back.c
	$(CC) $(CFLAGS) -o $@ ./C-back.c -L. -ljexc

C-back.ogr:	jexc libjexc.a exc.lst
	$(JEXC) -main exc/util/ogrcc -package-list ./exc.lst
	mv ./jexc.out.c ./C-back.c
	$(CC) $(CFLAGS) -o $@ ./C-back.c -L. -ljexc

F-back:	jexc libjexc.a exc.lst
	$(JEXC) -main exc/util/ompf77 -package-list ./exc.lst
	mv ./jexc.out.c ./F-back.c
	$(CC) $(CFLAGS) -o $@ ./F-back.c -L. -ljexc

C-back.sm:	jexc libjexc.a shm.lst
	$(JEXC) -main shm/shmcc -package-list ./shm.lst
	mv ./jexc.out.c ./C-back.sm.c
	$(CC) $(CFLAGS) -o $@ ./C-back.sm.c -L. -ljexc

F-back.sm:	jexc libjexc.a shm.lst
	$(JEXC) -main shm/shmf77 -package-list ./shm.lst
	mv ./jexc.out.c ./F-back.sm.c
	$(CC) $(CFLAGS) -o $@ ./F-back.sm.c -L. -ljexc

shm.lst:
	rm -f shm.lst
	(cd ../../exc-tools-java; \
	find shm -name '*.class' -print) > ./shm.lst
	cat ./test/exc.lst ./shm.lst > ./exc.lst

exc.lst:
	rm -f exc.lst
	cp ./test/exc.lst .

install:	$(EXE_TARGET) $(LIB_TARGET) @jexcBackend@
	@if [ ! -d $(INSTALLBINDIR) ] ; then \
		(echo "Making directory $(INSTALLBINDIR)" ; \
		$(MKDIR) $(INSTALLBINDIR) ; \
		chmod 775 $(INSTALLBINDIR)); \
	else \
		true ; \
	fi
	for i in $(EXE_TARGET) ; do \
		$(INSTALL) -m 755 $$i $(INSTALLBINDIR); \
	done
	@if [ ! -d $(INSTALLLIBDIR) ] ; then \
		(echo "Making directory $(INSTALLLIBDIR)" ; \
		$(MKDIR) $(INSTALLLIBDIR) ; \
		chmod 775 $(INSTALLLIBDIR)); \
	else \
		true ; \
	fi
	for i in $(LIB_TARGET) ; do \
		$(INSTALL) -m 644 $$i $(INSTALLLIBDIR); \
		case $$i in \
			*.a) \
				$(RANLIB) $(INSTALLLIBDIR)/$$i;; \
		esac \
	done
	@if [ ! -d $(INSTALLINCDIR) ] ; then \
		(echo "Making directory $(INSTALLINCDIR)" ; \
		$(MKDIR) $(INSTALLINCDIR) ; \
		chmod 775 $(INSTALLINCDIR)); \
	else \
		true ; \
	fi
	for i in $(INC_TARGET) ; do \
		$(INSTALL) -m 644 $$i $(INSTALLINCDIR); \
	done
	@if [ ! -d $(INSTALLLIBEXECDIR) ] ; then \
		(echo "Making directory $(INSTALLLIBEXECDIR)" ; \
		$(MKDIR) $(INSTALLLIBEXECDIR) ; \
		chmod 775 $(INSTALLLIBEXECDIR)); \
	else \
		true ; \
	fi
	for i in / @jexcBackend@ ; do \
		case $$i in \
			/) true;; \
			*) $(INSTALL) -m 755 $$i $(INSTALLLIBEXECDIR);; \
		esac; \
	done

clean:
	rm -f jexc dump_class *~ *.a *.o *.exe jvm-opcode.h jvm-opcode.c *.def.c core \
	C-back.c F-back.c C-back.sm.c F-back.sm.c @jexcBackend@ exc.lst shm.lst

distclean:	clean
	rm -f Makefile config.* .depend*

depend:	$(DYN_GEN)
	touch .depend.tmp
	makedepend -f ./.depend.tmp -a -- $(GCCINC) $(DEPEND_SWITCH) -- *.c
	sed 's:^$(PLATFORMDIR)/:./:' ./.depend.tmp > ./.depend
	cat Makefile ./.depend > ./Makefile.tmp
	mv Makefile.tmp Makefile
	rm -f ./.depend ./.depend.tmp .depend.tmp.bak

Makefile::
	(cd $(TOPDIR); sh ./config.status)

