#******************************************************************************
# Copyright (c) 2007, Intel Corp.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#   * Redistributions of source code must retain the above copyright notice,
#     this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#   * Neither the name of Intel Corporation nor the names of its contributors
#     may be used to endorse or promote products derived from this software
#     without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#*****************************************************************************

# Makefile for Intel IEEE 754R Decimal Floating-Point BID Library

ifeq ($(CALL_BY_REF),1)
COPT1 = -DDECIMAL_CALL_BY_REFERENCE=1
else
COPT1 = -DDECIMAL_CALL_BY_REFERENCE=0
endif

ifeq ($(GLOBAL_RND),1)
COPT2 = -DDECIMAL_GLOBAL_ROUNDING=1
else
COPT2 = -DDECIMAL_GLOBAL_ROUNDING=0
endif

ifeq ($(GLOBAL_FLAGS),1)
COPT3 = -DDECIMAL_GLOBAL_EXCEPTION_FLAGS=1
else
COPT3 = -DDECIMAL_GLOBAL_EXCEPTION_FLAGS=0
endif

ifeq ($(BID_BIG_ENDIAN),1)
COPT4 = -DBID_BIG_ENDIAN=1
else
COPT4 = -UBID_BIG_ENDIAN
endif
 
ifeq ($(HPUX_OS),1)
ifeq ($(DD64),1)
COPT5 = -DHPUX_OS +DD64
else
COPT5 = -DHPUX_OS +DD32
endif
else
COPT5 = -UHPUX_OS
endif

ifeq ($(UNCHANGED_BINARY_FLAGS),1)
COPT6 = -DUNCHANGED_BINARY_STATUS_FLAGS
else
COPT6 = 
endif

ifeq ($(OS_TYPE),LINUX)
CC = 
ifeq ($(HPUX_OS),1)
COPT = +Ofenvaccess 
else
ifeq ($(CC),icc)
#COPT = -Werror -Qoption,cpp,--extended_float_types -std=c99 -D__intptr_t_defined 
COPT =  -Werror -O2 -g -DDWARF20_FORMAT -DELF_OBJGEN -DSI_DEBUG -I. -Ibuild_objs/efi2linuxx86_debug -Iproton  -I shared -DHOST_LINUX  -DTARGET_LINUX -DDEBUG_ESP  -DHOSTSIZE=32 -DTGTSIZE=64   -DWMT -DDEBUG=2 -Wall -wd171,188,279,383,810,874,981 -wd1397,1682,1683,1684 -DKFOLD_TYPE_HYBRID=1 -DKFOLD_BUILD_HOST_X86=1 -DKFOLD_HOST_X86=1  -mieee-fp -Qoption,cpp,--extended_float_types -DLINUX -D__intptr_t_defined -DDECIMAL_CALL_BY_REFERENCE=0 -DDECIMAL_GLOBAL_ROUNDING=1 -DDECIMAL_GLOBAL_EXCEPTION_FLAGS=1 -wd111,177,181,193,344,583,593,869,1418,1419
else
#COPT = -Werror -D__intptr_t_defined 
# -Werror is temporarily removed for gcc since we do not have _Quad support in gcc and need to stub bid128 transcendental functionlaity
COPT = -D__intptr_t_defined -DLINUX -O2 -W -Wall -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
endif
endif
CFLAGS = -DLINUX $(COPT) $(COPT1) $(COPT2) $(COPT3) $(COPT4) $(COPT5) $(COPT6) $(COPT_ADD) $(DEFINES)
EXE = 
OBJ = .o
LIBEXT = .a
RM = rm -f
LMOPT = 
else 
CC = icl
ifeq ($(CC),icl)
COPT = -D_CRT_SECURE_NO_DEPRECATE -Qlong_double -Qoption,cpp,--extended_float_types -Qstd=c99
else
COPT = -D_CRT_SECURE_NO_DEPRECATE -DBID_MS_FLAGS -D_MSC_VER -D_M_IBID_X86
endif
CFLAGS = -I./ -D__intptr_t_defined -DWINDOWS /nologo $(COPT) $(COPT1) $(COPT2) $(COPT3) $(COPT4) $(COPT6) $(COPT_ADD) $(DEFINES)
EXE = .exe
OBJ = .obj
LIBEXT = .lib
RM = del
LMOPT = 
endif

BID_LIB = libbid$(LIBEXT)

default : libbid$(LIBEXT)

%$(OBJ) : %.c
	$(CC) -c $(CFLAGS) $<

clean:
	$(RM) *$(OBJ)
	$(RM) $(BID_LIB)

BIDSRCS = \
	bid64_add.c bid64_mul.c bid64_div.c bid64_sqrt.c bid64_rem.c \
	bid64_fma.c bid64_scalb.c bid_round.c bid64_next.c bid_dpd.c \
	bid128_next.c bid64_logb.c bid64_quantize.c bid_decimal_data.c \
	bid64_string.c bid128_2_str_tables.c bid_convert_data.c bid128.c \
	bid128_add.c bid128_mul.c bid128_div.c bid128_sqrt.c bid128_fma.c \
	bid128_round_integral.c bid64_round_integral.c bid128_quantize.c \
	bid128_scalb.c bid64_minmax.c bid128_minmax.c bid128_rem.c \
	bid128_logb.c bid_flag_operations.c bid32_to_bid64.c \
	bid128_string.c bid32_to_bid128.c bid64_to_bid128.c  \
	bid_from_int.c bid64_noncomp.c bid128_noncomp.c \
        bid64_compare.c bid128_compare.c bid_decimal_globals.c \
        bid64_to_int32.c bid64_to_uint32.c bid64_to_int64.c bid64_to_uint64.c \
        bid128_to_int32.c bid128_to_uint32.c bid128_to_int64.c \
	bid128_to_uint64.c bid_binarydecimal.c bid64_to_uint16.c \
	bid64_to_int16.c bid128_to_uint16.c bid128_to_int16.c \
	bid64_to_uint8.c bid64_to_int8.c bid128_to_uint8.c bid128_to_int8.c

LIBSRCS = $(BIDSRCS)

LIBOBJS = $(patsubst %.c,%$(OBJ),$(LIBSRCS))

ifeq ($(OS_TYPE),LINUX)

$(BID_LIB) : $(LIBOBJS)
	ar r $(BID_LIB) $(LIBOBJS)

else 

$(BID_LIB) : $(LIBOBJS)
	lib /out:$(BID_LIB) $(LIBOBJS)

endif




