# Edison Design Group C++ Front End.
# Makefile to build runtime (lib_src directory)

# By default, this Makefile uses the default target configuration and installs
# the resulting library in the default location (i.e., ../lib).  When building
# a runtime library for a non-default target, it is necessary to set the
# TARGET_SUFFIX and TARGET_OPT make variables appropriately for the chosen
# target.  TARGET_SUFFIX should have the target configuration name prepended
# with an underscore; TARGET_OPT should have "--target=" prepended to the
# target name.  For example, to build for target "foo", use this invocation:
#
#   make TARGET_SUFFIX="_foo" TARGET_OPT="--target=foo" install
#
# Alternatively, for those using gnu "make", the lines that follow can be
# uncommented and the invocation shortened to:
#
#   make TARGET="foo" install
#
#ifeq ($(TARGET),)
#TARGET_SUFFIX = 
#TARGET_OPT =
#else
#TARGET_SUFFIX = _$(TARGET)
#TARGET_OPT = --target=$(TARGET)
#endif

.SUFFIXES:
.SUFFIXES: .c .o

# Name of C++ library created
LIB = libC.a


INSTALL_DIR = ../lib$(TARGET_SUFFIX)

# C++ compiler to use
CPP = ./lib_eccp

.c.o:
	$(CPP) $(TARGET_OPT) -c $<

OBJECTS = \
	array_del_aligned.o \
	array_del.o \
	array_new_aligned.o \
	array_new.o \
	array_nodel_aligned.o \
	array_nodel.o \
	array_nonew_aligned.o \
	array_nonew.o \
	array_pdel.o \
	array_pnew.o \
	bad_alloc.o \
	c99_complex.o \
	delete_aligned.o \
	delete.o \
	delnothrow_aligned.o \
	delnothrow.o \
	del_virt.o \
	dtor_list.o \
	edg_exit.o \
	eh_util.o \
	error.o \
	exception.o \
	exit.o \
	guard.o \
	main.o \
	memzero.o \
	munch_ctors.o \
	munch_dtors.o \
	new_aligned.o \
	newhandler.o \
	newnothrow_aligned.o \
	newnothrow.o \
	new.o \
	placedel.o \
	placenew.o \
	pure_virt.o \
	rtti.o \
	set_new.o \
	sized_array_del_aligned.o \
	sized_array_del.o \
	sized_del_aligned.o \
	sized_del.o \
	static_init.o \
	stdexcept.o \
	thread_dtor.o \
	throw.o \
	typeinfo.o \
	vars.o \
	vec_cctor.o \
	vec_newdel.o \
	vla_alloc.o

default: $(LIB)

$(LIB): $(OBJECTS)
# Ensure that extern inline functions are instantiated when
# INSTANTIATE_EXTERN_INLINE is enabled.
	$(CPP) $(TARGET_OPT) --prelink_objects $?
# Most modern systems do not require lorder/tsort.  On systems that
# require lorder use the second form of the "ar" command below.
# the version without lorder on Linux.
	ar r $(LIB) $?
#	ar r $(LIB) `lorder $? | tsort 2> /dev/null`
# Remove ranlib on non-BSD systems
	- ranlib $(LIB)

decode.o: ../util/decode.c
	# Compile decode.c to get __cxa_demangle for IA-64 ABI.
	# Not needed otherwise.
	$(CPP) $(TARGET_OPT) \
		-DCOMPILE_DECODE_FOR_LIB_SRC=1 -DDEFAULT_EMULATE_GNU_ABI_BUGS=1\
		-DUSE_LONG_DOUBLE_FOR_HOST_FP_VALUE=0 \
		-DUSE_STDINT_HEADER='!USE_INT_TYPES_HEADER' -I../src -c \
		../util/decode.c

$(INSTALL_DIR)/$(LIB): $(LIB)
	rm -f $(INSTALL_DIR)/$(LIB)
	cp $(LIB) $(INSTALL_DIR)
# Remove ranlib on non-BSD systems
	- ranlib $(INSTALL_DIR)/$(LIB)
	chmod -w $(INSTALL_DIR)/$(LIB)

install: $(INSTALL_DIR)/$(LIB)

clean:
	rm -f core a.out *.o *.int.c *.ti *.ii

clobber: clean
	rm -f $(LIB)
