all: libgcj.so

CC =  /home/rth/work/gcc/bld-head/./gcc/xgcc -B/home/rth/work/gcc/bld-head/./gcc/ -B/usr/local/powerpc-linux/bin/ -B/usr/local/powerpc-linux/lib/ -isystem /usr/local/powerpc-linux/include -isystem /usr/local/powerpc-linux/sys-include

CXX =  /home/rth/work/gcc/bld-head/./gcc/xgcc -shared-libgcc -B/home/rth/work/gcc/bld-head/./gcc/ -nostdinc++ -L/home/rth/work/gcc/bld-head/powerpc-linux/libstdc++-v3/src -L/home/rth/work/gcc/bld-head/powerpc-linux/libstdc++-v3/src/.libs -B/usr/local/powerpc-linux/bin/ -B/usr/local/powerpc-linux/lib/ -isystem /usr/local/powerpc-linux/include -isystem /usr/local/powerpc-linux/sys-include

GCJ =  /home/rth/work/gcc/bld-head/./gcc/gcj -B/home/rth/work/gcc/bld-head/./gcc/ -B/usr/local/powerpc-linux/bin/ -B/usr/local/powerpc-linux/lib/ -isystem /usr/local/powerpc-linux/include -isystem /usr/local/powerpc-linux/sys-include

srcdir = ../../../src-gcc/libjava
top_srcdir = ../../../src-gcc/libjava
VPATH = ../../../src-gcc/libjava
top_builddir = .
MULTIBUILDTOP =

# May be used by various substitution variables.
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)

BOEHMGC_SRC = boehm.cc
BACKTRACE_SRC = sysdep/dwarf2-backtrace.cc

POSIX_PLATFORM_SRC = posix.cc
POSIX_THREAD_SRC = posix-threads.cc

SUBDIRS = $(DIRLTDL) testsuite gcj include external

# write_entries_to_file - writes each entry in a list
# to the specified file. Each entry is written individually
# to accomodate systems with severe command-line-length
# limitations.
# Parameters:
# $(1): variable containing entries to iterate over
# $(2): output file
write_entries_to_file = $(shell : > $(2)) $(foreach object,$(1),$(shell echo $(object) >> $(2)))

jardir = $(datadir)/java
jar_DATA = libgcj-$(gcc_version).jar

JAVA_HOME_DIR = $(prefix)
BOOT_CLASS_PATH_DIR = $(jardir)/$(jar_DATA)

## FIXME: Using libdir violates GNU coding standards.
secdir = $(libdir)/security
## Where to install default logging property file.
propdir = $(libdir)

## Where the standard .db file is found.
dbexecdir = $(libdir)/gcj-$(gcc_version)
## Name of the default .db.
db_name = classmap.db
## Compiler specific component of the .db file
db_pathtail = gcj-$(gcc_version)/$(db_name)

bin_PROGRAMS = jv-convert gij grmic grmiregistry gcj-dbtool

## It is convenient to actually build and install the default database
## when gcj-dbtool is available.
dbexec_DATA = $(db_name)

bin_SCRIPTS = addr2name.awk

GCJH = $(top_builddir)/$(MULTIBUILDTOP)../../$(host_subdir)/gcc/gcjh
ZIP = $(top_builddir)/$(MULTIBUILDTOP)../../$(host_subdir)/fastjar/fastjar

GCJ_WITH_FLAGS = $(GCJ) --encoding=UTF-8 -Wno-deprecated

JAVAC = $(GCJ_WITH_FLAGS) -C

GCC_UNWIND_INCLUDE = -I$(top_srcdir)/../gcc

#WARNINGS = -Wextra -Wall
## Some systems don't allow `$' in identifiers by default, so we force
## it with -fdollars-in-identifiers.  -Wswitch-enum detects bugs in
## the verifier implementation, and maybe other places.  We need
## _GNU_SOURCE defined for some Linux builds.  It doesn't hurt to
## always define it.  Some systems, including Linux, need
## -D_FILE_OFFSET_BITS=64 to enable > 2GB file support.
AM_CXXFLAGS = \
	-fno-rtti \
	-fnon-call-exceptions \
	$(THREADCXXFLAGS) \
	-fdollars-in-identifiers \
	-Wswitch-enum \
	-D_FILE_OFFSET_BITS=64 \
	$(WARNINGS) \
	-D_GNU_SOURCE \
	-DPREFIX="\"$(prefix)\"" \
	-DLIBDIR="\"$(libdir)\"" \
        -DJAVA_HOME="\"$(JAVA_HOME_DIR)\"" \
        -DBOOT_CLASS_PATH="\"$(BOOT_CLASS_PATH_DIR)\"" \
	-DJAVA_EXT_DIRS="\"$(jardir)/ext\"" \
	-DGCJ_ENDORSED_DIRS="\"$(jardir)/gcj-endorsed\"" \
	-DLIBGCJ_DEFAULT_DATABASE="\"$(dbexecdir)/$(db_name)\"" \
	-DLIBGCJ_DEFAULT_DATABASE_PATH_TAIL="\"$(db_pathtail)\"" \
	-DTOOLEXECLIBDIR="\"$(toolexeclibdir)\""

AM_GCJFLAGS = \
	-fclasspath= -fbootclasspath=$(BOOTCLASSPATH) \
	--encoding=UTF-8 \
	-Wno-deprecated

CFLAGS = $(WARNINGS) -g -O2 -fPIC

COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)

CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CFLAGS)

GCJCOMPILE = $(GCJ) $(AM_GCJFLAGS) $(CFLAGS)

## Extra CFLAGS used for JNI C sources shared with GNU Classpath.
PEDANTIC_CFLAGS = -ansi -pedantic -Wall -Wno-long-long

GCINCS = -I$(top_srcdir)/../boehm-gc/include -I../boehm-gc/include
LIBFFIINCS = -I$(top_srcdir)/../libffi/include -I../libffi/include

AM_CPPFLAGS = -I$(top_srcdir) -Iinclude -I$(top_srcdir)/include \
	$(GCINCS) $(THREADINCS) $(INCLTDL) \
	$(GCC_UNWIND_INCLUDE) $(ZINCS) $(LIBFFIINCS) -I.

here = /home/rth/work/gcc/bld-head/powerpc-linux/libjava
CLASSPATH_SEPARATOR = :
BOOTCLASSPATH := $(here)$(CLASSPATH_SEPARATOR)$(srcdir)$(CLASSPATH_SEPARATOR)$(srcdir)/external/w3c_dom$(CLASSPATH_SEPARATOR)$(srcdir)/external/sax

## ################################################################

##
## How to build libgcj.a and libgcj.jar
##

include Makefile.src

libgij_la_SOURCES = gij.cc

# Work around libtool wanting to do piece-wise linking with -r.  Using a
# convenience library suddenly invokes the --whole-archive path instead.
# This allows the build to succeed for targets that allocate multiple got
# subsections in the linker, such as Alpha and MIPS.
libgcj_SOURCES := prims.cc jni.cc exception.cc stacktrace.cc \
	link.cc defineclass.cc interpret.cc verify.cc \
	$(nat_source_files) $(math_c_source_files) $(java_source_files) \
	$(built_java_source_files) \
	$(BOEHMGC_SRC) $(NOGC_SRC) \
	$(BACKTRACE_SRC) \
	$(POSIX_PLATFORM_SRC) $(WIN32_PLATFORM_SRC) $(ECOS_PLATFORM_SRC) \
	$(DARWIN_CRT_SRC) \
	$(POSIX_THREAD_SRC) $(WIN32_THREAD_SRC) $(NO_THREAD_SRC)
libgcj_LIBADD = \
	gnu-xml.o javax-imageio.o \
	javax-xml.o gnu-java-beans.o \
	external/sax/libsax-gcj.o \
	external/w3c_dom/libw3c-gcj.o

%.properties.o: %.properties
	$(GCJCOMPILE) -o $@ -c $< -Wc,--resource,$<

# Compile each classfile individually.

.SUFFIXES:
.SUFFIXES: .class .java .h .properties .c .cc .o

.java.class:
	$(JAVAC) $(JCFLAGS) -classpath '' -bootclasspath $(BOOTCLASSPATH) -d $(here) $<

.c.o:
	$(COMPILE) -c -o $@ $<

.cc.o:
	$(CXXCOMPILE) -c -o $@ $<

.java.o:
	$(GCJCOMPILE) -o $@ -c $<

all_java_class_files := \
	$(all_java_source_files:.java=.class)
all_external_sax_class_files_1 := \
	$(all_external_sax_java_source_files:.java=.class)
all_external_sax_class_files := \
	$(addprefix external/sax/,$(all_external_sax_class_files_1))
all_external_w3c_dom_class_files_1 := \
	$(all_external_w3c_dom_java_source_files:.java=.class)
all_external_w3c_dom_class_files := \
	$(addprefix external/w3c_dom/,$(all_external_w3c_dom_class_files_1))

all_java_class_entries = \
	$(sort $(patsubst %/,%,$(dir $(all_java_class_files)))) \
	$(all_java_class_files) \
	$(foreach f, $(all_property_files), -C $(srcdir) $(f)) \
	$(foreach f, $(all_external_sax_class_files_1), -C external/sax $(f)) \
	$(foreach f, $(all_external_w3c_dom_class_files_1), -C external/w3c_dom $(f))

libgcj.clslist: Makefile
	@echo Creating list of classes for jar...
	@: $(call write_entries_to_file,$(all_java_class_entries),$@)

libgcj.jar: $(all_java_class_files) $(all_property_files) \
   $(all_external_sax_class_files) $(all_external_w3c_dom_class_files) \
   libgcj.clslist
	-rm -f $@
	$(ZIP) -cfM0E@ $@ < libgcj.clslist

libgcj_C_OBJECTS = $(patsubst %.c,%.o,$(filter %.c,$(libgcj_SOURCES)))
libgcj_CC_OBJECTS = $(patsubst %.cc,%.o,$(filter %.cc,$(libgcj_SOURCES)))
libgcj_JAVA_OBJECTS = $(patsubst %.java,%.o,$(filter %.java,$(libgcj_SOURCES)))
libgcj_OBJECTS = $(libgcj_C_OBJECTS) $(libgcj_CC_OBJECTS) $(libgcj_JAVA_OBJECTS)

$(libgcj_C_OBJECTS): %.o: %.c
$(libgcj_CC_OBJECTS): %.o: %.cc
$(libgcj_JAVA_OBJECTS): %.o: %.java

libgcj.objectlist: Makefile
	@echo Creating list of files to link...
	@: rm -f $@
	@: $(call write_entries_to_file,$(libgcj_OBJECTS),$@)

libgcj.a: libgcj.objectlist $(libgcj_OBJECTS)
	rm -f $@
	xargs < libgcj.objectlist ar cqS $@
	ranlib $@

libgcj.lds: libgcj.objectlist
	rm -f $@ t-$@
	sed -e 's/^/INPUT (/' -e 's/$$/)/' < $? > t-$@
	`$(CC) --print-prog-name=ld` --verbose \
	| sed -e '/^=========/,/^=========/!d;/^=========/d' >> t-$@ 
	mv t-$@ $@

dummy.o:
	echo | $(CC) -o $@ -c -xc -

libgcj.so: $(libgcj_OBJECTS) libgcj.lds dummy.o
	$(CC) -shared dummy.o -Wl,-T,libgcj.lds -o $@

## ################################################################

##
## How to build header files.
##

%.h: %.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) $(basename $<)

## Header files used when compiling some of the nat* files.
ordinary_nat_headers = \
    $(ordinary_java_source_files:.java=.h) \
    $(built_java_source_files:.java=.h)

inner_nat_headers = java/io/ObjectOutputStream$$PutField.h \
	java/io/ObjectInputStream$$GetField.h \
	java/nio/DirectByteBufferImpl$$ReadWrite.h \
	java/nio/channels/Pipe$$SinkChannel.h \
	java/nio/channels/Pipe$$SourceChannel.h \
	java/lang/reflect/Proxy$$ProxyData.h \
	java/lang/reflect/Proxy$$ProxyType.h \
	gnu/java/net/PlainSocketImpl$$SocketInputStream.h \
	gnu/java/net/PlainSocketImpl$$SocketOutputStream.h \
	gnu/java/nio/PipeImpl$$SinkChannelImpl.h \
	gnu/java/nio/PipeImpl$$SourceChannelImpl.h \
	$(PLATFORM_INNER_NAT_HDRS)

nat_headers = $(ordinary_nat_headers) $(inner_nat_headers) gnu/gcj/tools/gcj_dbtool/Main.h
nat_headers_install = $(ordinary_nat_headers)

xlib_nat_headers = $(xlib_java_source_files:.java=.h)

$(ordinary_nat_headers) $(xlib_nat_headers): %.h: %.class

java/lang/ClassLoader.h: java/lang/ClassLoader.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
		-prepend 'jclass _Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader);' \
		-prepend 'void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv, bool is_jar);' \
		-friend 'jclass (::_Jv_FindClass) (_Jv_Utf8Const *name, java::lang::ClassLoader *loader);' \
		-friend 'void ::_Jv_RunMain (jclass klass, const char *name, int argc, const char **argv, bool is_jar);' \
		$(basename $<)

java/lang/Thread.h: java/lang/Thread.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
		-prepend 'class _Jv_JNIEnv;' \
		-prepend '#define _JV_NOT_OWNER 1' \
		-prepend '#define _JV_INTERRUPTED 2' \
		-prepend '_Jv_JNIEnv * _Jv_GetCurrentJNIEnv ();' \
		-prepend 'void _Jv_SetCurrentJNIEnv (_Jv_JNIEnv *env);' \
		-prepend 'void _Jv_ThreadRun (java::lang::Thread* thread);' \
		-prepend 'jint _Jv_AttachCurrentThread(java::lang::Thread* thread);' \
		-prepend 'java::lang::Thread* _Jv_AttachCurrentThread (jstring name, java::lang::ThreadGroup* group);' \
		-prepend 'java::lang::Thread* _Jv_AttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group);' \
		-prepend 'jint _Jv_DetachCurrentThread ();' \
		-friend '_Jv_JNIEnv * ::_Jv_GetCurrentJNIEnv ();' \
		-friend 'void ::_Jv_SetCurrentJNIEnv (_Jv_JNIEnv *env);' \
		-friend 'void ::_Jv_ThreadRun (java::lang::Thread* thread);' \
		-friend 'jint (::_Jv_AttachCurrentThread) (java::lang::Thread* thread);' \
		-friend 'java::lang::Thread* ::_Jv_AttachCurrentThread (jstring name, java::lang::ThreadGroup* group);' \
		-friend 'java::lang::Thread* ::_Jv_AttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group);' \
		-friend 'jint (::_Jv_DetachCurrentThread) ();' \
		$(basename $<)

java/lang/String.h: java/lang/String.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	    -prepend 'jchar* _Jv_GetStringChars (jstring str);' \
	    -prepend 'jstring* _Jv_StringFindSlot (jchar*, jint, jint);' \
	    -prepend 'jstring* _Jv_StringGetSlot (jstring);' \
	    -prepend 'jstring _Jv_NewStringUtf8Const (_Jv_Utf8Const* str);' \
	    -prepend 'jstring _Jv_NewStringLatin1 (const char*, jsize);' \
	    -prepend 'jstring _Jv_AllocString (jsize);' \
	    -friend 'jchar* ::_Jv_GetStringChars (jstring str);' \
	    -friend 'jstring* ::_Jv_StringFindSlot (jchar*, jint, jint);' \
	    -friend 'jstring* ::_Jv_StringGetSlot (jstring);' \
	    -friend 'jstring (::_Jv_NewStringUtf8Const) (_Jv_Utf8Const* str);' \
	    -friend 'jstring (::_Jv_NewStringLatin1) (const char*, jsize);' \
	    -friend 'jstring (::_Jv_AllocString) (jsize);' \
	    $(basename $<)

java/lang/reflect/Constructor.h: java/lang/reflect/Constructor.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	    -prepend 'jmethodID _Jv_FromReflectedConstructor (java::lang::reflect::Constructor *);' \
	    -prepend 'jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);' \
	    -friend 'jmethodID (::_Jv_FromReflectedConstructor) (java::lang::reflect::Constructor *);' \
	    -friend 'jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);' \
	    -friend 'class java::lang::Class;' \
	    $(basename $<)

java/lang/reflect/Field.h: java/lang/reflect/Field.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	    -prepend 'jfieldID _Jv_FromReflectedField (java::lang::reflect::Field *);' \
	    -prepend 'jobject _Jv_JNI_ToReflectedField (_Jv_JNIEnv*, jclass, jfieldID, jboolean);' \
	    -friend 'jfieldID (::_Jv_FromReflectedField) (java::lang::reflect::Field *);' \
	    -friend 'jobject (::_Jv_JNI_ToReflectedField) (_Jv_JNIEnv*, jclass, jfieldID, jboolean);' \
	    -friend 'class java::lang::Class;' \
	    $(basename $<)

java/lang/reflect/Method.h: java/lang/reflect/Method.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	    -prepend 'jmethodID _Jv_FromReflectedMethod (java::lang::reflect::Method *);' \
	    -prepend 'jobject _Jv_JNI_ToReflectedMethod (_Jv_JNIEnv *, jclass, jmethodID, jboolean);' \
	    -friend 'jmethodID (::_Jv_FromReflectedMethod) (java::lang::reflect::Method *);' \
	    -friend 'jobject (::_Jv_JNI_ToReflectedMethod) (_Jv_JNIEnv *, jclass, jmethodID, jboolean);' \
	    -friend 'class java::lang::Class;' \
	    -friend 'class java::io::ObjectInputStream;' \
	    $(basename $<)

java/lang/reflect/Proxy.h: java/lang/reflect/Proxy.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	    $(basename $<)

java/lang/reflect/Proxy$$ProxyData.h: java/lang/reflect/Proxy.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/lang/reflect/Proxy$$ProxyData'

java/lang/reflect/Proxy$$ProxyType.h: java/lang/reflect/Proxy.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/lang/reflect/Proxy$$ProxyType'

gnu/gcj/runtime/ExtensionClassLoader.h: gnu/gcj/runtime/ExtensionClassLoader.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	    -friend 'class ::java::lang::ClassLoader;' \
	    $(basename $<)

java/io/ObjectInputStream$$GetField.h: java/io/ObjectInputStream.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/io/ObjectInputStream$$GetField'

java/io/ObjectOutputStream$$PutField.h: java/io/ObjectOutputStream.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/io/ObjectOutputStream$$PutField'

java/nio/DirectByteBufferImpl$$ReadWrite.h: java/nio/DirectByteBufferImpl.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/nio/DirectByteBufferImpl$$ReadWrite'

java/nio/channels/Pipe$$SinkChannel.h: java/nio/channels/Pipe.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/nio/channels/Pipe$$SinkChannel'

java/nio/channels/Pipe$$SourceChannel.h: java/nio/channels/Pipe.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/nio/channels/Pipe$$SourceChannel'

gnu/java/net/PlainSocketImpl$$SocketInputStream.h: gnu/java/net/PlainSocketImpl.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'gnu/java/net/PlainSocketImpl$$SocketInputStream'

gnu/java/net/PlainSocketImpl$$SocketOutputStream.h: gnu/java/net/PlainSocketImpl.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'gnu/java/net/PlainSocketImpl$$SocketOutputStream'

gnu/java/nio/PipeImpl$$SinkChannelImpl.h: gnu/java/nio/PipeImpl.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'gnu/java/nio/PipeImpl$$SinkChannelImpl'

gnu/java/nio/PipeImpl$$SourceChannelImpl.h: gnu/java/nio/PipeImpl.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'gnu/java/nio/PipeImpl$$SourceChannelImpl'

## Only used by PosixProcess.java
java/lang/ConcreteProcess$$ProcessManager.h: java/lang/ConcreteProcess.class
	$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
	'java/lang/ConcreteProcess$$ProcessManager'

## Headers we maintain by hand and which we want to install.
extra_headers = java/lang/Object.h java/lang/Class.h

$(extra_headers) $(srcdir)/java/lang/Object.h $(srcdir)/java/lang/Class.h:
	@:
