# Makefile for uClibc
#
# Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
#
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
# The routines included in this math library are derived from the
# math library for Apple's MacOS X/Darwin math library, which was
# itself swiped from FreeBSD.  The original copyright information
# is as follows:
#
#     Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
#
#     Developed at SunPro, a Sun Microsystems, Inc. business.
#     Permission to use, copy, modify, and distribute this
#     software is freely granted, provided that this notice
#     is preserved.
#
# It has been ported to work with uClibc and generally behave
# by Erik Andersen <andersen@codepoet.org>
#

EXTRA_CFLAGS := -DNOT_IN_libc -DIS_IN_libm -D_IEEE_LIBM $(SSP_ALL_CFLAGS)
EXTRA_AFLAGS := -DNOT_IN_libc -DIS_IN_libm -D_IEEE_LIBM

klib-y :=

# Fix builds for powerpc as there are different cores in this section now
archdir := $(ARCH)
ifeq ($(ARCH),powerpc)
ifeq ($(CONFIG_E500),y)
archdir := $(ARCH)/e500
else
archdir := $(ARCH)/classic
endif
endif

ifneq ($(wildcard $(obj)/$(ARCH)/),)
ifeq ($(UCLIBC_HAS_FPU),y)
ifeq ($(DO_C99_MATH),y)
klib-y += $(archdir)/
endif
endif
endif

ifeq ($(DO_C99_MATH),y)
klib-y += \
	e_acos.o e_acosh.o e_asin.o e_atan2.o e_atanh.o e_cosh.o \
	e_exp.o e_fmod.o e_gamma.o e_gamma_r.o e_hypot.o e_j0.o \
	e_j1.o e_jn.o e_lgamma.o e_lgamma_r.o e_log.o e_log10.o \
	e_pow.o e_remainder.o e_rem_pio2.o e_scalb.o e_sinh.o \
	e_sqrt.o k_cos.o k_rem_pio2.o k_sin.o k_standard.o k_tan.o \
	s_asinh.o s_atan.o s_cbrt.o s_ceil.o s_copysign.o s_cos.o \
	s_erf.o s_expm1.o s_fabs.o s_finite.o s_floor.o s_frexp.o \
	s_ilogb.o s_ldexp.o s_lib_version.o s_lrint.o s_lround.o s_llround.o \
	s_log1p.o s_logb.o s_matherr.o s_modf.o s_nextafter.o s_round.o \
	s_rint.o s_scalbn.o s_signgam.o s_significand.o s_sin.o s_tan.o \
	s_tanh.o s_trunc.o w_acos.o w_acosh.o w_asin.o w_atan2.o w_atanh.o \
	w_cabs.o w_cosh.o w_drem.o w_exp.o w_fmod.o w_gamma.o w_gamma_r.o \
	w_hypot.o w_j0.o w_j1.o w_jn.o w_lgamma.o w_lgamma_r.o \
	w_log.o w_log10.o w_pow.o w_remainder.o w_scalb.o w_sinh.o \
	w_sqrt.o fpmacros.o nan.o carg.o s_llrint.o
kmulti-y := \
	acosf.o acoshf.o asinf.o asinhf.o atan2f.o atanf.o atanhf.o cbrtf.o \
	ceilf.o copysignf.o cosf.o coshf.o erfcf.o erff.o exp2f.o expf.o \
	expm1f.o fabsf.o fdimf.o floorf.o fmaf.o fmaxf.o fminf.o fmodf.o \
	frexpf.o hypotf.o ilogbf.o ldexpf.o lgammaf.o llroundf.o log10f.o \
	log1pf.o log2f.o logbf.o logf.o lrintf.o lroundf.o modff.o nearbyintf.o \
	nextafterf.o powf.o remainderf.o remquof.o rintf.o roundf.o \
	scalblnf.o scalbnf.o sinf.o sinhf.o sqrtf.o tanf.o tanhf.o \
	tgammaf.o truncf.o cargf.o llrintf.o
else
# This list of math functions was taken from POSIX/IEEE 1003.1b-1993
klib-y += \
	w_acos.o w_asin.o s_atan.o w_atan2.o s_ceil.o s_cos.o \
	w_cosh.o w_exp.o s_fabs.o s_floor.o w_fmod.o s_frexp.o \
	s_ldexp.o w_log.o w_log10.o s_modf.o w_pow.o s_sin.o \
	w_sinh.o w_sqrt.o s_tan.o s_tanh.o \
	s_expm1.o s_scalbn.o s_copysign.o e_acos.o e_asin.o e_atan2.o \
	k_cos.o e_cosh.o e_exp.o e_fmod.o e_log.o e_log10.o e_pow.o \
	k_sin.o e_sinh.o e_sqrt.o k_tan.o e_rem_pio2.o k_rem_pio2.o \
	s_finite.o
# We'll add sqrtf to avoid problems with libstdc++
kmulti-y := sqrtf.o
endif

# Assume that arch specific versions are provided as single sources/objects
ifeq ($(UCLIBC_HAS_FPU),y)
ifeq ($(DO_C99_MATH),y)
# Make a list of *.o from $(archdir)/*.o
a := $(notdir $(wildcard $(obj)/$(archdir)/*.c $(obj)/$(archdir)/*.S))
a := $(patsubst %.c,%.o,$(a))
a := $(patsubst %.S,%.o,$(a))
# Remove generic objects, if arch version exists
klib-y := $(filter-out $(a),$(klib-y))
# Remove generic objects built from multi-sources, if arch version exists
kmulti-y := $(filter-out $(a),$(kmulti-y))
# Also remove %.o if s_%.o is in arch specific subdir
kmulti-y := $(filter-out $(patsubst s_%.o,%.o,$(a)),$(kmulti-y))
endif
endif

kmulti-src := float_wrappers.c


ifeq ($(HAVE_SHARED)-$(DOPIC),y-)

always := $(obj)/libm_so.a

$(obj)/libm_so.a: $(obj)/klib-shared.list
	@echo '  AR      $@'
	$(Q)rm -f $@; mkdir -p $(dir $@)
	$(Q)$(AR) cr $@ `$(srctree)/scripts/catlist.sh $(obj)/klib-shared.list`

endif
