/*
 *	makefile for Eiffel 3.0 run-time
 */

#include "../U/runtime.H"

CFLAGS = -I$(TOP) -I. -I$(TOP)/ipc/app -I./include -I$(TOP)/idrs
DPFLAGS = -I$(TOP) -I. -I$(TOP)/ipc/app

LIB_SHARED= $(TOP)/ipc/shared
LIB_IPCNAME= ipc.o
LIB_MTIPCNAME = mtipc.o
LIB_IPC_ARCH = $(LIB_SHARED)/$(LIB_IPCNAME)
LIB_MTIPC_ARCH = $(LIB_SHARED)/$(LIB_MTIPCNAME)

EWB_PROTO_OBJ = $(TOP)/ipc/ewb/wewb_proto.o
MTEWB_PROTO_OBJ = $(TOP)/ipc/ewb/MTwewb_proto.o

IDRS_OBJ = $(TOP)/idrs/idrs.o
MTIDRS_OBJ = $(TOP)/idrs/MTidrs.o
NETWORK_OBJ = $(TOP)/ipc/app/network.o
MTNETWORK_OBJ = $(TOP)/ipc/app/MTnetwork.o

/*
 * Main source files for run-time archive
 */
LSRC = malloc.c garcol.c local.c stack.c store.c retrieve.c \
	hash.c traverse.c hashin.c tools.c internal.c plug.c \
	copy.c equal.c lmalloc.c out.c timer.c urgent.c sig.c \
	hector.c cecil.c file.c dir.c misc.c string.c \
	error.c umain.c memory.c memory_analyzer.c argv.c boolstr.c search.c \
	run_idr.c path_name.c object_id.c eif_threads.c eif_project.c \
	posix_threads.c gen_conf.c eif_type_id.c rout_obj.c \
	option.c compress.c console.c offset.c main.c except.c

/*
 * Files addedd only for workbench-type archive
 */
WADD = debug.c interp.c update.c wbench.c

/*
 * Files addedd only for multithreaded archive
 */

MTADD = \
	scoop.c \
	scoop_gc.c \
	scoop_helpers.c \
	processor_registry.c \
	private_queue.c \
	processor.c \
	queue_cache.c \
	message_channel.c \
	request_group.c \
	identifier_set.c

/*
 * Files for workbench have a 'w' pre-pended if they already exist for
 * the normal run-time archive.
 */
WOBJ = \
	$(IDRS_OBJ) \
	$(LIB_IPC_ARCH) \
	$(NETWORK_OBJ) \
|expand f!$(WADD)!
	!f:\.c=.o \
-expand
|expand f!$(LSRC)!
	w!f:\.c=.o \
-expand \\

/*
 * Object files for finalized run-time archive
 */
LOBJ = \
	$(IDRS_OBJ) \
|expand f!$(LSRC)!
	!f:\.c=.o \
-expand \\

/*
 * Files for multithreaded workbench have a 'MTw' pre-pended if they already exist for
 * the normal run-time archive.
 */
MT_WOBJ = \
	$(MTIDRS_OBJ) \
	$(LIB_MTIPC_ARCH) \
	$(MTNETWORK_OBJ) \
|expand f!$(WADD)!
	MT!f:\.c=.o \
-expand
|expand f!$(MTADD)!
	MTw!f:\.c=.o \
-expand
|expand f!$(LSRC)!
	MTw!f:\.c=.o \
-expand \\

/*
 * Object files for finalized run-time archive
 */
MT_LOBJ = \
	$(MTIDRS_OBJ) \
|expand f!$(MTADD)!
	MT!f:\.c=.o \
-expand
|expand f!$(LSRC)!
	MT!f:\.c=.o \
-expand \\


/* How to build a 'w' and `MT' and `MTw' file from a normal file. 
 */

|expand f!$(LSRC)!
w!f:\.c=.o: !f
        $(CC) -c $(JCFLAGS) -DWORKBENCH $? -o $@

-expand

|expand f!$(LSRC)!
MT!f:\.c=.o: !f
        $(CC) -c $(JMTCFLAGS) $? -o $@

-expand

|expand f!$(LSRC)!
MTw!f:\.c=.o: !f
        $(CC) -c $(JMTCFLAGS) -DWORKBENCH $? -o $@

-expand

|expand f!$(WADD)!
!f:\.c=.o: !f
	$(CC) -c $(JCFLAGS) -DWORKBENCH $? -o $@

-expand

|expand f!$(WADD)!
MT!f:\.c=.o: !f
	$(CC) -c $(JMTCFLAGS) -DWORKBENCH $? -o $@

-expand

|expand f!$(MTADD)!
MTw!f:\.c=.o: scoop/!f
	$(CC) -c $(JMTCFLAGS) -DWORKBENCH $? -o $@

-expand

|expand f!$(MTADD)!
MT!f:\.c=.o: scoop/!f
	$(CC) -c $(JMTCFLAGS) $? -o $@

-expand

NormalObjectRule()
ShellScriptLongTarget(eif_size_h,eif_size.h)
AddSource($(LSRC) $(WADD) $(MTADD))

CustomLibraryTarget(mtfinalized,$(MT_LOBJ))
CustomLibraryTarget(mtwkbench,$(MT_WOBJ))
CustomLibraryTarget(finalized,$(LOBJ))
CustomLibraryTarget(wkbench,$(WOBJ))

CustomMTSharedLibraryTarget(mtfinalized,$(MT_LOBJ))
CustomMTSharedLibraryTarget(mtwkbench,$(MT_WOBJ))
CustomSharedLibraryTarget(finalized,$(LOBJ))
CustomSharedLibraryTarget(wkbench,$(WOBJ))

NormalProgramTarget(x2c,x2c.c,x2c.o offset.o)
NormalProgramTarget(runtime_validation,runtime_validation.c,runtime_validation.o offset.o)

AllTarget(eif_config.h eif_portable.h eif_confmagic.h)

eif_config.h: $(TOP)/eif_config.h
	$(RM) $@
	$(LN) $(TOP)/eif_config.h .

eif_confmagic.h: $(TOP)/eif_confmagic.h
	$(RM) $@
	$(LN) $(TOP)/eif_confmagic.h .

eif_portable.h: $(TOP)/eif_portable.h
	$(RM) $@
	$(LN) $(TOP)/eif_portable.h .

/*
 * Workbench files added to SOURCES
 */

DependTarget()
LintTarget()

shared: sharedfinal sharedwork
mtshared: mtsharedfinal mtsharedwork
sharedfinal: libfinalized.so
mtsharedfinal: libmtfinalized.so
sharedwork: libwkbench.so
mtsharedwork: libmtwkbench.so

static: final work
final: libfinalized.a
mtfinal: libmtfinalized.a
work: libwkbench.a
mtwork: libmtwkbench.a
mtebench: libmtebench.a
mt: mtwork mtfinal mtebench

/*
 * The network object is pre-linked with all the needed libraries.
 */

RemoteDependency($(TOP)/ipc/app,network.o)
RemoteDependency($(TOP)/idrs,idrs.o)
RemoteDependency($(LIB_SHARED),$(LIB_IPCNAME))
RemoteDependency($(LIB_SHARED),$(LIB_MTIPCNAME))
RemoteDependency($(TOP)/ipc/ewb,wewb_proto.o))
RemoteDependency($(TOP)/ipc/ewb,MTwewb_proto.o)

/*
 * Run-time tests
 */

TESTS = mram gram lram eram sram

test: $(TESTS)
	mram >test 2>&1
	gram >>test 2>&1
	lram >>test 2>&1
	eram >>test 2>&1
	sram >>test 2>&1

TestProgramTarget(mram,malloc.c,/**/)
TestProgramTarget(gram,garcol.c,/**/)
TestProgramTarget(lram,local.c,/**/)
TestProgramTarget(eram,except.c,/**/)
TestProgramTarget(sram,sig.c,/**/)

local_realclean::
	$(RM) $(TESTS)

local_clobber::
	$(RM) test
