# SPDX-License-Identifier: GPL-3.0-or-later
#
# Copyright (C) 2005-2022 Free Software Foundation, Inc.
# Copyright (C) 2022 Kernkonzept GmbH.
# Author(s): Georg Kotheimer <georg.kotheimer@kernkonzept.com>

# TODO: Do we need to support stack splitting?
#       - config/t-stack
#       - config/i386/t-stack-i386

# --- From libgcc/Makefile.in ---
enable_execute_stack = enable-execute-stack-empty.c
unwind_header = unwind-generic.h
md_unwind_header = no-unwind.h
sfp_machine_header = i386/sfp-machine.h
thread_header-l4api-plain := gthr-single.h
thread_header-l4api-l4f   := gthr-posix.h
thread_header = $(thread_header-l4api-$(L4API))

# List of extra object files that should be compiled for this target machine.
# The rules for compiling them should be in the t-* file for the machine.
EXTRA_PARTS = crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o crtprec32.o crtprec64.o crtprec80.o

# TODO:
# decimal_float = yes
# enable_decimal_float = bid
# related: config/t-dfprules
# related: config/t-tls defines USE_TLS which is used libbid

# TODO: (impl is Linux specific)
# CET_FLAGS = -fcf-protection -mshstk


# --- From libgcc/config/t-eh-dw2-dip ---
$(eval $(call libgcc_include_config,t-eh-dw2-dip))


# --- From libgcc/config/i386/t-crtpc ---
$(foreach prec,32 64 80,\
  $(eval $(call libgcc_link_rule,crtprec$(prec).c,$(LIBGCC_CONTRIB_SRC_DIR)/config/i386/crtprec.c)) \
  $(eval $(call libgcc_make_obj,crtprec$(prec).o,crtprec$(prec).c,-D__PREC=$(prec) $(LIBGCC2_CFLAGS))) \
)


ifeq ($(BID_VARIANT_FLAG_NOFPU),)
# -- From libgcc/config/t-crtfm ---
EXTRA_PARTS += crtfastmath.o
$(eval $(call libgcc_include_config,t-crtfm))
endif


# -- From libgcc/config/i386/t-crtstuff ---
# The pushl in CTOR initialization interferes with frame pointer elimination.
# crtend*.o cannot be compiled without -fno-asynchronous-unwind-tables,
# because then __FRAME_END__ might not be the last thing in .eh_frame
# section.  -fno-asynchronous-unwind-tables is off by default for i386
# and is on by default for x86-64.  We turn it off for both i386 and
# x86-64.
CRTSTUFF_T_CFLAGS += -fno-omit-frame-pointer -fno-asynchronous-unwind-tables


# -- From libgcc/config/i386/t-cpuinfo ---
LIB2ADD += config/i386/cpuinfo.c


ifeq ($(BID_VARIANT_FLAG_NOFPU),)
# --- From libgcc/config/t-softfp-tf ---
$(eval $(call libgcc_include_config,t-softfp-tf))


# --- From libgcc/config/i386/32/t-softfp ---
ifeq ($(BUILD_ARCH),x86)
# Omit TImode functions
softfp_int_modes := si di

# Provide fallbacks for __builtin_copysignq and __builtin_fabsq.
LIB2ADD += config/i386/32/tf-signs.c
endif


# --- From libgcc/config/i386/64/t-softfp ---
ifeq ($(BUILD_ARCH),amd64)
$(eval $(call libgcc_include_config,i386/64/t-softfp))
endif


# --- From libgcc/config/i386/t-softfp ---
$(eval $(call libgcc_include_config,i386/t-softfp))


# --- From libgcc/config/t-softfp ---
$(eval $(call libgcc_include_config,t-softfp))
endif


# GCC >= 14
ifneq ($(call libgcc_if_min_version,14),)
# --- From libgcc/config/i386/t-heap-trampoline ---
LIB2ADDEH += config/i386/heap-trampoline.c
LIB2ADDEHSHARED += config/i386/heap-trampoline.c
endif
