# Top level Makefile fragment for GNU CHILL.
#   Copyright (C) 1994 Free Software Foundation, Inc.

#This file is part of GNU CC.

#GNU CC 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 2, or (at your option)
#any later version.

#GNU CC 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 GNU CC; see the file COPYING.  If not, write to
#the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# This file provides the language dependent support in the main Makefile.
# Each language makefile fragment must provide the following targets:
#
# foo.all.build, foo.all.cross, foo.start.encap, foo.rest.encap,
# foo.info, foo.dvi,
# foo.install-normal, foo.install-common, foo.install-info, foo.install-man,
# foo.uninstall, foo.distdir,
# foo.mostlyclean, foo.clean, foo.distclean, foo.extraclean,
# 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: cc1plus)
# - define the names for selecting the language in LANGUAGES.

# define version of GNUCHILL compiler. Note: maybe we have to change the
# mechanism
GNUCHILL_VERSION = 1.5.2

# Actual names to use when installing a native compiler.
# (Cygnus configure overrides these when using -program-transform-name).
CHILL_INSTALL_NAME = chill

# Actual names to use when installing a cross-compiler.
# (Cygnus configure overrides these when using -program-transform-name).
CHILL_CROSS_NAME = $(target_alias)-chill

CHILL_SRCS = $(srcdir)/ch/actions.c $(srcdir)/ch/convert.c \
 $(srcdir)/ch/decl.c $(srcdir)/ch/except.c $(srcdir)/ch/expr.c \
 $(srcdir)/ch/grant.c $(srcdir)/ch/inout.c $(srcdir)/ch/lang.c \
 $(srcdir)/ch/lex.c $(srcdir)/ch/loop.c \
 $(srcdir)/ch/parse.c $(srcdir)/ch/satisfy.c \
 $(srcdir)/ch/tasking.c $(srcdir)/ch/timing.c $(srcdir)/ch/tree.c \
 $(srcdir)/ch/typeck.c

# Extra flags to pass to recursive makes.
CHILL_FLAGS_TO_PASS = \
	"CHILLFLAGS=$(CHILLFLAGS)" \
	"CHILL_FOR_TARGET=$(CHILL_FOR_TARGET)" \
	"CHILL_LIB=$(CHILL_LIB)" \
	"CC=$(CC)" \
	"GNUCHILL_VERSION=$(GNUCHILL_VERSION)"

# Define the names for selecting languages in LANGUAGES.
CHILL: chill cc1chill chill-runtime

# handle startfile in chill script and build script to install
chill: $(srcdir)/ch/chill.in Makefile
	thisdir=`pwd` ; \
	sed -e "s:startfile=chillrt0:startfile=$${thisdir}/ch/runtime/chillrt0.o:" \
	    -e "s:libpath=chillrt:libpath=-L$${thisdir}/ch/runtime/:" \
	    -e "s:whatgcc=gcc:whatgcc=\"$${thisdir}/xgcc -B$${thisdir}/\":" \
	    -e "s:gnuchill_version=unknown:gnuchill_version=$(GNUCHILL_VERSION):" \
	    -e "s:gnuchill_script_flags=:gnuchill_script_flags=\"$(GNUCHILL_SCRIPT_FLAGS)\":" $(srcdir)/ch/chill.in > chill ; \
	chmod a+x chill ; \
	if [ -f ../gcc-cross$(exeext) ]; then \
	  whatgcc=$(GCC_CROSS_NAME) ; \
	else \
	  whatgcc=$(GCC_INSTALL_NAME) ; \
	fi; \
	sed -e "s:startfile=chillrt0:startfile=$(libsubdir)/chillrt0.o:" \
	    -e "s:whatgcc=gcc:whatgcc=$(bindir)/$${whatgcc}:" \
	    -e "s:gnuchill_version=unknown:gnuchill_version=$(GNUCHILL_VERSION):" \
	    -e "s:libpath=chillrt:libpath=:" \
	    -e "s:gnuchill_script_flags=:gnuchill_script_flags=\"$(GNUCHILL_SCRIPT_FLAGS)\":" $(srcdir)/ch/chill.in > chill.install ; \
	chmod a+x chill.install

# Don't depend on cc1chill, because chill-cross is always built for cross,
# and thus a cc1chill dependence would force cc1chill to always be built.
# Note that gcc-cross and g++-cross do not have cc1 or cc1plus dependencies.
chill-cross: $(srcdir)/ch/chill.in
	touch $@

cc1chill: $(P) $(CHILL_SRCS) $(LIBDEPS) stamp-objlist \
	insn-config.h insn-flags.h insn-attr.h insn-codes.h \
	c-typeck.o c-aux-info.o c-common.o c-iterate.o
	cd ch; $(MAKE) $(FLAGS_TO_PASS) $(CHILL_FLAGS_TO_PASS) ../cc1chill

chill-runtime: stmp-headers $(GCC_PASSES)
	case "$(LANGUAGES)" in \
	*CHILL*) if [ -f ch/runtime/Makefile -a -z "$(CROSS)" ] ; then \
		   thisdir1=`pwd`; \
		   cd ch/runtime; $(MAKE) $(FLAGS_TO_PASS) $(CHILL_FLAGS_TO_PASS) GCC_FOR_TARGET="$${thisdir1}/xgcc -B$${thisdir1}/" all ; \
		 else true; fi ;; \
	esac

# Build hooks:

CHILL.all.build: chill
CHILL.all.cross: chill-cross
CHILL.start.encap: chill
CHILL.rest.encap:

CHILL.info: $(srcdir)/ch/chill.texi
	$(MAKEINFO) -I$(srcdir)/ch $(srcdir)/ch/chill.texi -o chill.info

chill.dvi: $(srcdir)/ch/chill.texi $(srcdir)/extend.texi $(srcdir)/invoke.texi $(srcdir)/md.texi $(srcdir)/rtl.texi $(srcdir)/tm.texi
	cd ch ; \
	TEXINPUTS=${texidir}:$(srcdir):$$TEXINPUTS tex chill.texi ; \
	texindex chill.?? ; \
	TEXINPUTS=${texidir}:$(srcdir):$$TEXINPUTS tex chill.texi
# FIXME: Not sure languages should do this.
	cp ch/chill.dvi chill.dvi

# Install hooks:
# cc1chill is installed elsewhere as part of $(COMPILERS).

CHILL.install-normal: install-libchill

# Install the CHILL run time library.
install-libchill: chill-runtime
	if [ -f ch/runtime/libchill.a ] ; then \
	  $(INSTALL_DATA) ch/runtime/libchill.a $(libsubdir)/libchill.a; \
	  if $(RANLIB_TEST) ; then \
	    (cd $(libsubdir); $(RANLIB) libchill.a); else true; fi; \
	  chmod a-x $(libsubdir)/libchill.a; \
	  $(INSTALL_DATA) ch/runtime/chillrt0.o $(libsubdir)/chillrt0.o; \
	else true; fi

# Install the driver program
CHILL.install-common:
	-if [ -f cc1chill ] ; then \
	  if [ -f chill.install ] ; then \
	    if [ -f gcc-cross$(exeext) ]; then \
	      rm -f $(bindir)/$(CHILL_CROSS_NAME); \
	      $(INSTALL_PROGRAM) chill.install $(bindir)/$(CHILL_CROSS_NAME); \
	      chmod a+x $(bindir)/$(CHILL_CROSS_NAME); \
	    else \
	      rm -f $(bindir)/$(CHILL_INSTALL_NAME); \
	      $(INSTALL_PROGRAM) chill.install $(bindir)/$(CHILL_INSTALL_NAME); \
	      chmod a+x $(bindir)/$(CHILL_INSTALL_NAME); \
	    fi ; \
	  fi ; \
	fi

CHILL.install-info:
	-for i in chill.info*; do \
	  rm -f $(infodir)/$$i; \
	  $(INSTALL_DATA) $$i $(infodir)/$$i; \
	done

CHILL.install-man:

CHILL.uninstall:
	-rm -rf $(bindir)/$(CHILL_INSTALL_NAME)
	-rm -rf $(bindir)/$(CHILL_CROSS_NAME)

# Clean hooks:
# A lot of the ancillary files are deleted by the main makefile.
# We just have to delete files specific to us.

CHILL.mostlyclean:
	-rm -f chill.install ch/*.o ch/ch-version.c
	-cd ch/runtime && $(MAKE) mostlyclean
CHILL.clean:
CHILL.distclean:
	-rm -f ch/config.status ch/Makefile
CHILL.extraclean:
CHILL.maintainer-clean:
	-rm -f ch/TAGS
	-rm -f ch/chill.info* ch/chill.dvi ch/chill.??s ch/chill.*aux
# CYGNUS LOCAL: Delete locally created file.
	-rm -f ch/hash.h

# Stage hooks:
# The main makefile has already created stage?/ch.

CHILL.stage1:
	-mv ch/*.o stage1/ch
CHILL.stage2:
	-mv ch/*.o stage2/ch
CHILL.stage3:
	-mv ch/*.o stage3/ch
CHILL.stage4:
	-mv ch/*.o stage4/ch

# Maintenance hooks:

# This target creates the files that can be rebuilt, but go in the
# distribution anyway.  It then copies the files to the distdir directory.
CHILL.distdir:
	mkdir tmp/ch
	cd ch ; $(MAKE) $(FLAGS_TO_PASS) $(CXX_FLAGS_TO_PASS) hash.h
	cd ch; \
	for file in *[0-9a-zA-Z+]; do \
	  ln $$file ../tmp/ch >/dev/null 2>&1 || cp $$file ../tmp/ch; \
	done
