# Override targets
LANGUAGES = c gcov$(exeext) c++ f77 objc

# Allow multi-threaded/single-threaded libraries
MULTILIB_OPTIONS    = Zmt
MULTILIB_DIRNAMES   = mt st
MULTILIB_MATCHES    = Zmt=Zmts Zmt=Zmtd
MULTILIB_EXCEPTIONS =
MULTILIB_EXTRA_OPTS =

# Dont use collect2
USE_COLLECT2 =

# Override linker flags
LDFLAGS = -Zexe -Zcrtdll

# We don`t want debug information in libgcc
LIBGCC2_DEBUG_CFLAGS = -s
# We also want epilogues for each function in libgcc
TARGET_LIBGCC2_CFLAGS = -s -O6 -Wall -mprobe -mepilogue -DNDEBUG

# Provide an alternative source code for libgcc1
LIBGCC1 = libgcc1-asm.a
CROSS_LIBGCC1 = libgcc1-asm.a
LIB1ASMSRC = i386/emx-libgcc1.asm
LIB1ASMFUNCS = _alloca _udivdi3 _umoddi3 _divdi3 _moddi3 _gcc_bcmp

# Eliminate unneeded functions from libgcc2, along with those
# implemented in the alternative $(LIB1ASMSRC)
NO_LIB2FUNCS = __gcc_bcmp _trampoline _ctors $(LIB1ASMFUNCS)

# Extra functions to add to libgcc
LIB2FUNCS_EXTRA = $(srcdir)/config/i386/emx-ctordtor.c

# EMX include directory
SYSTEM_HEADER_DIR = /emx/include

# Copy these files to include/ subdirectory
# $(srcdir)/ginclude/stddef.h does not contain emx`s definition of _threadid
USER_H = $(srcdir)/ginclude/stdarg.h \
    $(srcdir)/ginclude/varargs.h $(srcdir)/ginclude/iso646.h \
    $(srcdir)/ginclude/proto.h $(EXTRA_HEADERS) \
    $(LANG_EXTRA_HEADERS)

# Additional dependencies to build gcc.a and gcc_p.a
# plus dynamicaly-linked version of libgcc*
$(ALL): gcc.a
gcc.a: $(LIBGCC)
	mv $(LIBGCC) $@ && rm -f libgcc2.a && \
	echo "*** Building profiling version of libgcc ***" && \
	$(MAKE) $(LIBGCC) SHELL="$(SHELL)" CFLAGS="$(CFLAGS) -fno-omit-frame-pointer -pg" && \
	cp $(LIBGCC) gcc_p.a && \
	touch $@ -r $(LIBGCC)

stage1 stage2 stage3 stage4:
	-mv -f *.exe *.a *.dll *.ready $@
