# Makefile for uClibc
#
# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
#
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#

subdirs += libpthread/nptl_db

# Get the thread include dependencies and shared object name
CFLAGS-libpthread/nptl_db := -DNOT_IN_libc \
	-DLIBPTHREAD_SO="\"libpthread.so.$(ABI_VERSION)\"" \
	-std=gnu99 -D_GNU_SOURCE \
	-I$(top_srcdir)libpthread/nptl \
	-I$(top_srcdir)ldso/include

LDFLAGS-libthread_db.so := $(LDFLAGS_NOSTRIP) $(if $(call check_ld,--warn-unresolved-symbols),-Wl$(comma)--warn-unresolved-symbols)
LIBS-libthread_db.so := $(LIBS)

libthread_db_FULL_NAME := libthread_db-$(VERSION).so

libthread_db_DIR := $(top_srcdir)libpthread/nptl_db
libthread_db_OUT := $(top_builddir)libpthread/nptl_db

libthread_db_SRC := $(notdir $(wildcard $(libthread_db_DIR)/td_*.c)	\
		    $(libthread_db_DIR)/fetch-value.c)
ifeq ($(UCLIBC_SUSV4_LEGACY),)
libthread_db_SRC := $(filter-out td_ta_setconcurrency.c,$(libthread_db_SRC))
endif

libthread_db_OBJ := $(addprefix $(libthread_db_OUT)/,$(libthread_db_SRC:.c=.o))

libthread_db-so-y := $(libthread_db_OBJ:.o=.oS)
ifeq ($(DOPIC),y)
libthread_db-a-y := $(libthread_db-so-y)
else
libthread_db-a-y := $(libthread_db_OBJ)
endif

libthread_db-multi-y := $(addprefix $(libthread_db_DIR)/,$(libthread_db_SRC))

lib-a-$(PTHREADS_DEBUG_SUPPORT) += $(top_builddir)lib/libthread_db.a
lib-so-$(PTHREADS_DEBUG_SUPPORT) += $(top_builddir)lib/libthread_db.so
objclean-y += CLEAN_libpthread/nptl_db
headers-$(PTHREADS_DEBUG_SUPPORT) += $(nptl_db_headers)
headers_clean-y += HEADERCLEAN_libpthread/nptl_db

ifeq ($(DOPIC),y)
$(top_builddir)lib/libthread_db.so: $(top_builddir)lib/libthread_db.a $(libc.depend)
else
$(top_builddir)lib/libthread_db.so: $(libthread_db_OUT)/libthread_db_so.a $(libc.depend)
endif
	$(call link.so,$(libthread_db_FULL_NAME),1)

$(libthread_db_OUT)/libthread_db_so.a: $(libthread_db-so-y)
	$(Q)$(RM) $@
	$(do_strip)
	$(do_ar)

$(top_builddir)lib/libthread_db.a: $(libthread_db-a-y) | $(top_builddir)lib
	$(Q)$(RM) $@
	$(do_strip)
	$(do_ar)

$(top_builddir)include/thread_db.h:
	$(do_ln) $(call rel_srcdir)$(PTDIR)_db/$(@F) $@

nptl_db_headers:= $(top_builddir)include/thread_db.h

HEADERCLEAN_libpthread/nptl_db:
	$(do_rm) $(nptl_db_headers)

CLEAN_libpthread/nptl_db:
	$(do_rm) $(addprefix $(libthread_db_OUT)/*., o oS a)
