# Build runtime library for C backend

srcdir		= @srcdir@
top_srcdir	= @top_srcdir@
top_builddir	= @top_builddir@
gc_prefix	= @with_gc@
arch_flag  	= @arch_flag@

runtime_srcdir	= $(top_srcdir)/sources/dfmc/c-run-time

subdir		= sources/dfmc/c-run-time

VPATH		= $(srcdir)

LIBDEST         = $(OPEN_DYLAN_USER_INSTALL)/lib
BINDEST         = $(OPEN_DYLAN_USER_INSTALL)/bin
INCDEST		= $(OPEN_DYLAN_USER_INSTALL)/include

AS = as -L
AR = ar -q

CFLAGS		= -DGC_LINUX_THREADS=1 -D_REENTRANT=1 -DGC_DEBUG=1 -fPIC \
		  -fno-strict-aliasing \
		  $(arch_flag) -O -g -I$(srcdir) -I$(runtime_srcdir) \
		  -I$(gc_prefix)/include -L$(gc_prefix)/lib

OBJS		= dummy-threads.o \
		  debug-print.o \
		  run-time.o

RUNTIMELIBDEST	 = $(LIBDEST)/runtime/

all:	$(OBJS)

dummy-threads.o:       $(runtime_srcdir)/dummy-threads.c

debug-print.o:  $(runtime_srcdir)/debug-print.c

run-time.o: $(runtime_srcdir)/run-time.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(INCDEST):
	mkdir -p $(INCDEST)

$(RUNTIMELIBDEST):
	mkdir -p $(RUNTIMELIBDEST)

# mini-jambase.jam has to be present, but do not require all platform-specific
# files to be present; only one will be used, so the others can be missing.
install-build:
	cp -fp $(top_srcdir)/sources/lib/run-time/mini-jambase.jam $(LIBDEST)
	-cp -fp $(runtime_srcdir)/c-freebsd-build.jam $(LIBDEST)
	-cp -fp $(runtime_srcdir)/c-linux-build.jam $(LIBDEST)
	-cp -fp $(runtime_srcdir)/x86-linux-build.jam $(LIBDEST)
	-cp -fp $(runtime_srcdir)/x86_64-linux-build.jam $(LIBDEST)
	-cp -fp $(runtime_srcdir)/x86-darwin-build.jam $(LIBDEST)
	-cp -fp $(runtime_srcdir)/x86_64-darwin-build.jam $(LIBDEST)
	-cp -fp $(runtime_srcdir)/ppc-darwin-build.jam $(LIBDEST)

install-header:	$(runtime_srcdir)/run-time.h $(INCDEST)
	cp -fp $(runtime_srcdir)/run-time.h $(INCDEST)

install-runtime: $(OBJS) $(RUNTIMELIBDEST)
	cp -fp $(OBJS) $(RUNTIMELIBDEST)

install: install-runtime install-build install-header

clean:
	rm -f *.o

Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	cd $(top_builddir) && ./config.status $(subdir)/Makefile
