# Makefile template to be included by sysdeps/linux/<ARCH>/Makefile.arch
#
# Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
#
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#

ARCH_DIR  := $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)
ARCH_OUT  := $(top_builddir)libc/sysdeps/linux/$(TARGET_ARCH)

ARCH_CSRC := $(addprefix $(ARCH_DIR)/,$(CSRC-y))
ARCH_COBJ := $(addprefix $(ARCH_OUT)/,$(CSRC-y:.c=.o))
ARCH_SSRC = $(addprefix $(ARCH_DIR)/,$(SSRC-y))
ARCH_SOBJ = $(patsubst %.s,%.o,$(patsubst %.S,%.o,$(addprefix $(ARCH_OUT)/,$(SSRC-y))))

ARCH_OBJS-y = $(ARCH_COBJ) $(ARCH_SOBJ)

crt-y          := FORCE
libc-y         += $(ARCH_OBJS-y)
libc-nomulti-y += $(ARCH_SOBJ)
objclean-y     += CLEAN_$(subst $(top_builddir),,$(ARCH_OUT))

CFLAGS-crti.S+=$(PICFLAG)
CFLAGS-crtn.S+=$(PICFLAG)

CLEAN_$(subst $(top_builddir),,$(ARCH_OUT)):
	$(do_rm) $(addprefix $(ARCH_OUT)/*., o os oS) $(CTOR_TARGETS) $(CRTS)

ifneq ($(ARCH_HEADERS),)

ARCH_HEADERS_OUT := $(patsubst %,$(top_builddir)include/%,$(ARCH_HEADERS))

$(ARCH_HEADERS_OUT):
	$(do_ln) $(call rel_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(@F) $@

headers-y += $(ARCH_HEADERS_OUT)
headers_clean-y += HEADERCLEAN_$(subst $(top_builddir),,$(ARCH_OUT))
HEADERCLEAN_$(subst $(top_builddir),,$(ARCH_OUT)):
	$(do_rm) $(ARCH_HEADERS_OUT)
endif

CFLAGS-ucontext_i.c = -S

$(ARCH_OUT)/ucontext_i.c: $(ARCH_DIR)/ucontext_i.sym
	$(do_awk) $(top_srcdir)extra/scripts/gen-as-const.awk $< > $@

$(ARCH_OUT)/ucontext_i.s: $(ARCH_OUT)/ucontext_i.c
	$(compile.c)

$(ARCH_OUT)/ucontext_i.h: $(ARCH_OUT)/ucontext_i.s
	$(do_sed) $(PTHREAD_GENERATE_MANGLE) $< > $@

pregen-headers-$(UCLIBC_HAS_CONTEXT_FUNCS) += $(ARCH_OUT)/ucontext_i.h

headers_clean-$(UCLIBC_HAS_CONTEXT_FUNCS) += \
	HEADERCLEAN_$(subst $(top_builddir),,$(ARCH_OUT)/ucontext_i)

HEADERCLEAN_$(subst $(top_builddir),,$(ARCH_OUT)/ucontext_i):
	$(do_rm) $(addprefix $(ARCH_OUT)/ucontext_i., c h s)