#
# t-cris
#
# The Makefile fragment to include when compiling gcc et al for CRIS
#
#
# The makefile macros etc. are included in the order found in the
# section "Target Fragment" in the gcc info-files (or the paper copy) of
# "Using and Porting GNU CC"
#
# Don't run fixproto.
STMP_FIXPROTO =

# Don't run fixinc.
STMP_FIXINC =

#
# We always mean the same for LIBGCC1 and CROSS_LIBGCC1.  We
# build libgcc1.a as part of libgcc2.a to get it
# multilib-compiled, so they should be empty.
#
LIBGCC1 =
CROSS_LIBGCC1 =

LIB2FUNCS_EXTRA = tmpaoutxtor.c libgcc1.txt tmpabi_symbol.c

FPBIT=tmplibgcc_fp_bit.c
DPBIT=dp-bit.c

dp-bit.c: $(srcdir)/config/fp-bit.c
	echo '#define FLOAT_BIT_ORDER_MISMATCH' > dp-bit.c
	cat $(srcdir)/config/fp-bit.c           >> dp-bit.c

# Use another name to avoid confusing SUN make.  Prefixed with
# "tmplibgcc" means "make clean" will wipe it.
# We define a few L_ thingies because we can't select them individually
# through FPBIT_FUNCS; see above.
tmplibgcc_fp_bit.c: $(srcdir)/config/fp-bit.c
	echo '#define FLOAT_BIT_ORDER_MISMATCH' >  $@
	echo '#define FLOAT'			>> $@
	cat $(srcdir)/config/fp-bit.c		>> $@

tmpaoutxtor.c: $(srcdir)/config/cris/aoutxtor.c
	cp $(srcdir)/config/cris/aoutxtor.c $@

tmpabi_symbol.c: $(srcdir)/config/cris/cris_abi_symbol.c
	cp $(srcdir)/config/cris/cris_abi_symbol.c $@

#
# Since we need to pass 64-bit entities BY VALUE, we have to bypass
# the normal calling scheme when we make the internal functions in
# libgcc2.a
#  Unfortunately, __make_dp () wants to call a function where
# the fourth argument is DI (the others are SImode), which does
# not fit in the libfunc scheme (with four argument registers,
# but allow DImode arguments to span two registers).
#  Allow a stubbed pthreads.h coming from a not-yet-configured newlib.
#  To compile libgcc as PIC for linux but not pass -fpic to other
# multilibs, and not make -fpic a -mlinux multilib option, we have yet
# another hack; an option which is equivalent to -fpic with -mlinux, but
# is ignored otherwise.  Sad, these hacks, but we can't pass
# a `case something in -mlinux) echo -fpic;; esac`, as
# TARGET_LIBGCC2_CFLAGS is passed through two layers of recursive makes.
# Ugh.
TARGET_LIBGCC2_CFLAGS = -Dinhibit_libc \
 '-D__make_dp(a,b,c,d)=__cris_make_dp(d,a,b,c)' \
 -idirafter $(srcdir)/../newlib/libc/sys/cris/include \
 -mhack-in-fpic-for-mlinux

EXTRA_MULTILIB_PARTS = crtbegin.o crtend.o crtbegin2.o crtbeginS.o crtendS.o

# The -melf effectively overrides the (multilib) -maout option,
# which is what we want for these files.  We also want to *not*
# bring on fancy -ffunction-sections, -fdata-sections features.
CRTSTUFF_T_CFLAGS = $(LIBGCC2_CFLAGS) -melf -moverride-best-lib-options

# This one is only used for -mlinux.  Though we have to cater to building
# it for other multilib variants too, so pass -melf to avoid annoying the
# a.out assembler with the ELF constructs in that file.
CRTSTUFF_T_CFLAGS_S = $(LIBGCC2_CFLAGS) -moverride-best-lib-options \
 `case "${GCC_FOR_TARGET} ${MULTILIB_CFLAGS}" in *-mlinux*) ;; *) echo -melf;; esac`

# By default we compile and link to ELF.  This is modified under
# control of these -m*-options:
#
# * elinux - We need a specific library for elinux (NO_MM linux
# 2.0), since it's a.out only and has glibc (not newlib).
#
# * linux - (with MMU) has glibc and is always ELF and v10.
#
# * aout - We also unfortunately need a.out libraries, because
# getting debug information into an a.out binary made from ELF
# objects is not currently working (neither for stabs nor
# dwarf2), and linking from ELF to a.out isn't very well-tested;
# corner cases are overlooked.
#
# * arch=v10 - We benefit from a specific library for v10 (Etrax 100 LX)
# because of the multiply instructions.  This is ELF only.
#
# We don't need the combinations, because we don't run elinux on
# v10 (we run real linux there) and code for v10 should be
# compiled ELF only.  You can compile with e.g. -march=v10
# combined with -melinux (perhaps for experimental purposes),
# but you need to link without it in order to get the right
# libraries.  Provide for v11 as a synonym.
# Note that multilibbing -fpic or -fPIC willl just give you a headache;
# shlibs are treated separately when it matters for libs in this
# toolchain.  We always compile libgcc -fpic for -mlinux.

MULTILIB_OPTIONS = melinux/mlinux/march=v10/maout
MULTILIB_DIRNAMES = elinux linux v10 aout
MULTILIB_MATCHES = \
		march?v10=mcpu?etrax100lx \
		march?v10=mcpu?ng \
		march?v10=march?etrax100lx \
		march?v10=march?ng \
		march?v10=march?v11 \
		march?v10=mcpu?v11 \
		march?v10=mcpu?v10

# We can't put -ffunction-sections -fdata-sections -fvtable-gc
# here; "-ffunction-sections -fdata-sections" is invalid for
# a.out and "-fvtable-gc" is only valid in C++.  However, we can
# fake a new option (ugh) and replace it with the best possible
# options regarding the current multilib combination.

MULTILIB_EXTRA_OPTS = mbest-lib-options
LIBGCC1_TEST =

INSTALL_LIBGCC = install-multilib
LIBGCC = stmp-multilib

#
# End of documented makefile fragment.  Over to hacking.
#

# This should be documented but isn't.  Better put it here than in
# configure.in; less impact when changed.
MAYBE_USE_COLLECT2 = -DUSE_COLLECT2
USE_COLLECT2 = collect2


# Note that this conceptual libgcc1 functionality is compiled as
# part of libgcc2 through LIB2FUNCS_EXTRA.
ARITFUNCS = _mulsi3 _udivsi3 _divsi3 _umodsi3 _modsi3
LIBARIT_CFLAGS = $(LIBGCC2_CFLAGS) -mexpand-mul

libgcc1.txt:
	rm -f $@ 2>/dev/null; \
	for name in $(ARITFUNCS); do \
	 echo $$name""_libgcc1_cris.o >> $@; \
        done

%_libgcc1_cris.o: $(srcdir)/config/cris/arit.c $(GCC_PASSES)
	def=`echo $@ | sed -e 's/_libgcc1_cris.o//;'`; \
	$(GCC_FOR_TARGET) $(LIBARIT_CFLAGS) $(INCLUDES) \
         -DL$$def -o $@ -c $(srcdir)/config/cris/arit.c

# Perhaps register the .fini section with atexit.
$(T)crtbegin2.o: $(srcdir)/config/cris/crtbegin2.c
	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
	  -fno-exceptions $(CRTSTUFF_T_CFLAGS) -o $@ \
	  -c $(srcdir)/config/cris/crtbegin2.c

#
# End of cris makefile fragment 
#
