# Top level -*- makefile -*- fragment for the GNU compiler for the Java(TM)
# language.
#   Copyright (C) 1996-2015 Free Software Foundation, Inc.

#This file is part of GCC.

#GCC is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 3, or (at your option)
#any later version.

#GCC is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with GCC; see the file COPYING3.  If not see
#<http://www.gnu.org/licenses/>.

#Java and all Java-based marks are trademarks or registered trademarks
#of Sun Microsystems, Inc. in the United States and other countries.
#The Free Software Foundation is independent of Sun Microsystems, Inc.

# This file provides the language dependent support in the main Makefile.
# Each language makefile fragment must provide the following targets:
#
# foo.all.cross, foo.start.encap, foo.rest.encap,
# foo.install-common, foo.install-man, foo.install-info, foo.install-pdf,
# foo.install-html, foo.info, foo.dvi, foo.pdf, foo.html, foo.uninstall,
# foo.mostlyclean, foo.clean, foo.distclean,
# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4
#
# where `foo' is the name of the language.
#
# It should also provide rules for:
#
# - making any compiler driver (eg: g++)
# - the compiler proper (eg: jc1)
# - define the names for selecting the language in LANGUAGES.

# Actual names to use when installing a native compiler.
JAVA_INSTALL_NAME := $(shell echo gcj|sed '$(program_transform_name)')
JAVA_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcj|sed '$(program_transform_name)')

XGCJ = gcj

# Define the names for selecting java in LANGUAGES.
java: jc1$(exeext) $(XGCJ)$(exeext) jvgenmain$(exeext) jcf-dump$(exeext)

# Define the name of target independent tools to be installed in $(bindir)
# Names are subject to changes
JAVA_TARGET_INDEPENDENT_BIN_TOOLS = jcf-dump

# Tell GNU make to ignore these if they exist.
.PHONY: java

CFLAGS-java/jvspec.o += $(DRIVER_DEFINES)

# Create the compiler driver for $(XGCJ).
$(XGCJ)$(exeext): $(GCC_OBJS) java/jvspec.o java/jcf-path.o \
	   libcommon-target.a $(LIBDEPS) $(EXTRA_GCC_OBJS)
	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(GCC_OBJS) \
	  java/jvspec.o java/jcf-path.o $(EXTRA_GCC_OBJS) libcommon-target.a \
	  $(EXTRA_GCC_LIBS) $(LIBS)

# Create a version of the $(XGCJ) driver which calls the cross-compiler.
$(XGCJ)-cross$(exeext): $(XGCJ)$(exeext)
	-rm -f $(XGCJ)-cross$(exeext)
	cp $(XGCJ)$(exeext) $(XGCJ)-cross$(exeext)

java.srcextra:

# Executables built by this Makefile:
JAVA_OBJS = java/class.o java/decl.o java/expr.o \
  java/constants.o java/lang.o java/typeck.o java/except.o \
  java/verify-glue.o java/verify-impl.o \
  java/zextract.o java/jcf-io.o java/win32-host.o java/jcf-parse.o java/mangle.o \
  java/mangle_name.o java/builtins.o java/resource.o \
  java/jcf-depend.o \
  java/jcf-path.o java/boehm.o java/java-gimplify.o hash-table.o

JCFDUMP_OBJS = java/jcf-dump.o java/jcf-io.o java/jcf-depend.o java/jcf-path.o \
		java/win32-host.o java/zextract.o ggc-none.o hash-table.o

JVGENMAIN_OBJS = java/jvgenmain.o java/mangle_name.o

java_OBJS = $(sort $(JAVA_OBJS) $(JCFDUMP_OBJS) $(JVGENMAIN_OBJS)) java/jvspec.o

# Use strict warnings for this front end.
java-warn = $(STRICT_WARN)

# String length warnings
java/jvspec.o-warn = -Wno-error

jc1$(exeext): $(JAVA_OBJS) $(BACKEND) $(LIBDEPS) attribs.o
	rm -f $@
	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
		$(JAVA_OBJS) $(BACKEND) $(ZLIB) $(LIBICONV) $(LIBS) attribs.o $(BACKENDLIBS)

jcf-dump$(exeext): $(JCFDUMP_OBJS) $(LIBDEPS)
	rm -f $@
	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(JCFDUMP_OBJS) \
		$(CPPLIBS) $(ZLIB) $(LDEXP_LIB) $(LIBS)

jvgenmain$(exeext): $(JVGENMAIN_OBJS) $(LIBDEPS)
	rm -f $@
	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ $(JVGENMAIN_OBJS) \
		$(LIBS)

#
# Build hooks:

java.all.cross: $(XGCJ)-cross$(exeext)
java.start.encap: $(XGCJ)$(exeext)
java.rest.encap:


java.tags: force
	cd $(srcdir)/java; etags -o TAGS.sub *.c *.h --language=none \
	  --regex='/DEFTREECODE [(]\([A-Z_]+\)/\1/' java-tree.def; \
	etags --include TAGS.sub --include ../TAGS.sub


java.info: doc/gcj.info

java.srcinfo: doc/gcj.info
	-cp -p $^ $(srcdir)/doc

java.dvi: doc/gcj.dvi

JAVA_PDFFILES = doc/gcj.pdf

java.pdf: $(JAVA_PDFFILES)

JAVA_HTMLFILES = $(build_htmldir)/java

java.html: $(JAVA_HTMLFILES)/index.html

JAVA_MANFILES = doc/gcj.1 doc/jcf-dump.1 doc/gij.1 \
                doc/jv-convert.1 doc/grmic.1 \
                doc/gcj-dbtool.1 doc/gc-analyze.1 doc/aot-compile.1 \
                doc/rebuild-gcj-db.1

java.man: $(JAVA_MANFILES)

java.srcman: $(JAVA_MANFILES)
	-cp -p $^ $(srcdir)/doc

check-java :
check-java-subtargets :

# Install hooks:
# jc1, gcj, and jvgenmain are installed elsewhere as part
# of $(COMPILERS).

# Install gcj as well as the target-independent tools.
java.install-common: installdirs
	-if [ -f $(XGCJ)$(exeext) ]; then \
	  rm -f $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
	  $(INSTALL_PROGRAM) $(XGCJ)$(exeext) $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
	  chmod a+x $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
	  if [ -f $(XGCJ)-cross$(exeext) ]; then \
	    true; \
	  else \
	    rm -f $(DESTDIR)$(bindir)/$(JAVA_TARGET_INSTALL_NAME)$(exeext); \
	    ( cd $(DESTDIR)$(bindir) && \
	      $(LN) $(JAVA_INSTALL_NAME)$(exeext) $(JAVA_TARGET_INSTALL_NAME)$(exeext) ); \
	  fi ; \
	fi ; \
        for tool in $(JAVA_TARGET_INDEPENDENT_BIN_TOOLS); do \
	  tool_transformed_name=`echo $$tool|sed '$(program_transform_name)'`; \
          if [ -f $$tool$(exeext) ]; then \
	    rm -f $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
	    $(INSTALL_PROGRAM) $$tool$(exeext) $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
	    chmod a+x $(DESTDIR)$(bindir)/$$tool_transformed_name$(exeext); \
          fi ; \
       done

java.install-plugin:
java.install-man:

java.uninstall:
	-rm -rf $(DESTDIR)$(bindir)/$(JAVA_INSTALL_NAME)$(exeext)
	-rm -rf $(DESTDIR)$(man1dir)/$(JAVA_INSTALL_NAME)$(man1ext)
	-rm -rf $(DESTDIR)$(man1dir)/jcf-dump$(man1ext)
	-rm -rf $(DESTDIR)$(man1dir)/gij$(man1ext)
	-rm -rf $(DESTDIR)$(man1dir)/jv-convert$(man1ext)
	-rm -rf $(DESTDIR)$(man1dir)/gcj-dbtool$(man1ext)
	-rm -rf $(DESTDIR)$(man1dir)/aot-compile$(man1ext)
	-rm -rf $(DESTDIR)$(man1dir)/rebuild-gcj-db$(man1ext)

java.install-info: $(DESTDIR)$(infodir)/gcj.info

java.install-pdf: $(JAVA_PDFFILES)
	@$(NORMAL_INSTALL)
	test -z "$(pdfdir)" || $(mkinstalldirs) "$(DESTDIR)$(pdfdir)/gcc"
	@list='$(JAVA_PDFFILES)'; for p in $$list; do \
	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
	  f=$(pdf__strip_dir) \
	  echo " $(INSTALL_DATA) '$$d$$p' '$(DESTDIR)$(pdfdir)/gcc/$$f'"; \
	  $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
	done

java.install-html: $(JAVA_HTMLFILES)
	@$(NORMAL_INSTALL)
	test -z "$(htmldir)" || $(mkinstalldirs) "$(DESTDIR)$(htmldir)"
	@list='$(JAVA_HTMLFILES)'; for p in $$list; do \
	  if test -f "$$p" || test -d "$$p"; then d=""; else d="$(srcdir)/"; fi; \
	  f=$(html__strip_dir) \
	  if test -d "$$d$$p"; then \
	    echo " $(mkinstalldirs) '$(DESTDIR)$(htmldir)/$$f'"; \
	    $(mkinstalldirs) "$(DESTDIR)$(htmldir)/$$f" || exit 1; \
	    echo " $(INSTALL_DATA) '$$d$$p'/* '$(DESTDIR)$(htmldir)/$$f'"; \
	    $(INSTALL_DATA) "$$d$$p"/* "$(DESTDIR)$(htmldir)/$$f"; \
	  else \
	    echo " $(INSTALL_DATA) '$$d$$p' '$(DESTDIR)$(htmldir)/$$f'"; \
	    $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(htmldir)/$$f"; \
	  fi; \
	done
#
# Clean hooks:
# A lot of the ancillary files are deleted by the main makefile.
# We just have to delete files specific to us.

java.mostlyclean:
	-rm -f java/*$(objext) $(DEMANGLER_PROG)
	-rm -f java/*$(coverageexts)
	-rm -f jc1$(exeext) $(XGCJ)$(exeext) jvgenmain$(exeext) \
          jcf-dump$(exeext) s-java
java.clean:
java.distclean:
	-rm -f java/config.status java/Makefile
java.maintainer-clean:
	-rm -f $(docobjdir)/gcj.1
	-rm -f $(docobjdir)/jcf-dump.1
	-rm -f $(docobjdir)/gij.1
	-rm -f $(docobjdir)/jv-convert.1
	-rm -f $(docobjdir)/grmic.1
	-rm -f $(docobjdir)/gcj-dbtool.1
	-rm -f $(docobjdir)/gc-analyze.1
	-rm -f $(docobjdir)/aot-compile.1
	-rm -f $(docobjdir)/rebuild-gcj-db.1
#
# Stage hooks:
# The main makefile has already created stage?/java.

java.stage1: stage1-start
	-mv java/*$(objext) stage1/java
java.stage2: stage2-start
	-mv java/*$(objext) stage2/java
java.stage3: stage3-start
	-mv java/*$(objext) stage3/java
java.stage4: stage4-start
	-mv java/*$(objext) stage4/java
java.stageprofile: stageprofile-start
	-mv java/*$(objext) stageprofile/java
java.stagefeedback: stageprofile-start
	-mv java/*$(objext) stagefeedback/java

#

# jcf-io.o needs $(ZLIBINC) added to cflags.
CFLAGS-java/jcf-io.o += $(ZLIBINC)

# jcf-path.o needs a -D.
CFLAGS-java/jcf-path.o += \
	-DLIBGCJ_ZIP_FILE='"$(datadir)/java/libgcj-$(version).jar"' \
	-DDEFAULT_TARGET_VERSION=\"$(version)\"

TEXI_JAVA_FILES = java/gcj.texi $(gcc_docdir)/include/fdl.texi		\
	 $(gcc_docdir)/include/gpl_v3.texi $(gcc_docdir)/include/gcc-common.texi   \
	 gcc-vers.texi

# Documentation
doc/gcj.info: $(TEXI_JAVA_FILES)
	if test "x$(BUILD_INFO)" = xinfo; then \
	  rm -f doc/gcj.info*; \
	  $(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
		-I $(gcc_docdir)/include -o $@ $<; \
	else true; fi

doc/gcj.dvi: $(TEXI_JAVA_FILES)
	$(TEXI2DVI) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<

doc/gcj.pdf: $(TEXI_JAVA_FILES)
	$(TEXI2PDF) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<

$(build_htmldir)/java/index.html: $(TEXI_JAVA_FILES)
	$(mkinstalldirs) $(@D)
	rm -f $(@D)/*
	$(TEXI2HTML) -I $(gcc_docdir) -I $(gcc_docdir)/include \
		-I $(srcdir)/java -o $(@D) $<

.INTERMEDIATE: gcj.pod jcf-dump.pod gij.pod \
  jv-convert.pod grmic.pod gcj-dbtool.pod gc-analyze.pod

gcj.pod: java/gcj.texi
	-$(TEXI2POD) -D gcj < $< > $@
jcf-dump.pod: java/gcj.texi
	-$(TEXI2POD) -D jcf-dump < $< > $@
gij.pod: java/gcj.texi
	-$(TEXI2POD) -D gij < $< > $@
jv-convert.pod: java/gcj.texi
	-$(TEXI2POD) -D jv-convert < $< > $@
grmic.pod: java/gcj.texi
	-$(TEXI2POD) -D grmic < $< > $@
gcj-dbtool.pod: java/gcj.texi
	-$(TEXI2POD) -D gcj-dbtool < $< > $@
gc-analyze.pod: java/gcj.texi
	-$(TEXI2POD) -D gc-analyze < $< > $@
aot-compile.pod: java/gcj.texi
	-$(TEXI2POD) -D aot-compile < $< > $@
rebuild-gcj-db.pod: java/gcj.texi
	-$(TEXI2POD) -D rebuild-gcj-db < $< > $@

# Install the man pages.
java.install-man: installdirs \
                  $(DESTDIR)$(man1dir)/$(JAVA_INSTALL_NAME)$(man1ext) \
		  $(JAVA_TARGET_INDEPENDENT_BIN_TOOLS:%=doc/%.1) \
		  doc/gij.1 doc/jv-convert.1 doc/grmic.1 \
		  doc/gcj-dbtool.1 doc/gc-analyze.1 \
		  doc/aot-compile.1 doc/rebuild-gcj-db.1
	for tool in $(JAVA_TARGET_INDEPENDENT_BIN_TOOLS) \
		gij jv-convert grmic gcj-dbtool gc-analyze aot-compile \
		rebuild-gcj-db; do \
	  tool_transformed_name=`echo $$tool|sed '$(program_transform_name)'`; \
	  man_name=$(DESTDIR)$(man1dir)/$${tool_transformed_name}$(man1ext); \
	  rm -f $$man_name ; \
	  for source_name in doc/$${tool}.1 $(srcdir)/doc/$${tool}.1 ; do \
	    if test -f $$source_name; then \
	      $(INSTALL_DATA) $$source_name $$man_name; \
	      break; \
	      else : ; \
	    fi; \
	  done ; \
	  chmod a-x $$man_name ; \
	done

$(DESTDIR)$(man1dir)/$(JAVA_INSTALL_NAME)$(man1ext): doc/gcj.1 installdirs
	-rm -f $@
	-$(INSTALL_DATA) $< $@
	-chmod a-x $@
