#
# Makefile for the iBCS emulator files
#
# $Id: Makefile,v 1.17 1994/05/26 15:04:49 mike Exp $
# $Source: /var/CVS/ibcs/Makefile,v $
#
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here
# unless it's something special (ie not a .c file).
#
# Note 2! The CFLAGS definitions are now in the main makefile...
#
# Feb 14 1994
#   Dual mode. If iBCS support is configured in to the kernel and this
#   source replaces the ibcs in the standard distribution an ibcs.o
#   will be built and linked with the kernel. If iBCS support isn't
#   configured in to the kernel then a loadable module is built which
#   can be attached to the iBCS interface stubs in the kernel. Using the
#   loadable module form of iBCS emulation introduces a small overhead
#   (a variable read and function call) on each system call.
#   -- Mike Jagdis (jaggy@purplet.demon.co.uk)


# CONFIGURATION SECTION

# SOCKSYS_MAJOR is the major number to use for the /dev/socksys socket
# interface to streams based TCP/IP (i.e. Lachman as used by many SVR3s).
# Setting this to zero tells the module initialisation code to attempt
# to auto allocate the next available major number. This is not currently
# supported by any kernel known, so don't do it!
# You also need to create the file /dev/socksys with mknod, e.g.:
#    mknod /dev/socksys c <n> 0
# where <n> is the chosen major number.
SOCKSYS_MAJOR=30

# The following compile time options are available:
#
# -DIBCS_TRACE		Add code to trace the iBCS emulator.
#
# -DVERBOSE_ERRORS	Give textual error message as well as number in
#                       the trace log. (This only makes sense if IBCS_TRACE
#                       is also defined)
#
# -DCOFF_TRACE		Add code to trace the COFF loader. This is useful
#			if you have executables are not recognised correctly.
#
# -DXOUT_DEBUG		Debug the XOUT loader.
#
OPTIONS=-DIBCS_TRACE -DVERBOSE_ERRORS -DCOFF_TRACE

# END CONFIGURATION SECTION


ifeq (${CFLAGS},)
CFLAGS = -D__KERNEL__=1 \
	-I../include -Wall -Wstrict-prototypes \
	-O2 -fomit-frame-pointer -m486
endif
CFLAGS := -Iinclude $(CFLAGS) -DSOCKSYS_MAJOR=$(SOCKSYS_MAJOR) $(OPTIONS)

include /usr/src/linux/.config

ifeq (${VERSION},)
KVERSION = $(shell uname -r)
else
KVERSION = $(VERSION).$(PATCHLEVEL)
ifneq ($(SUBLEVEL),)
KVERSION := $(KVERSION).$(SUBLEVEL)
endif
endif

.S.s:
	$(CPP) -traditional $< -o $*.s
.c.s:
	$(CC) $(CFLAGS) -S $<
.s.o:
	$(AS) -c -o $*.o $<
.c.o:
	$(CC) $(CFLAGS) -c $<

OBJS = binfmt_coff.o binfmt_elf.o binfmt_xout.o \
	map.o coff.o hrtsys.o ioctl.o ipc.o mmap.o open.o \
	secureware.o socket.o poll.o signal.o stat.o sysconf.o \
	sysfs.o sysi86.o socksys.o ulimit.o utsname.o wysev386.o wysev386i.o \
	xnx.o xstat.o stream.o sysisc.o


ifdef CONFIG_BINFMT_IBCS
all:	ibcs.o

ibcs.o: emulate.o $(OBJS)
	$(LD) -r -o ibcs.o emulate.o $(OBJS)
	sync
else
all:	ibcs.o iBCS

ibcs.o:	emu.stub.o
	$(LD) -r -o ibcs.o emu.stub.o

iBCS:	emulate2.o $(OBJS)
	$(LD) -r -o iBCS emulate2.o $(OBJS)
endif

emulate2.o:	emulate.c
	$(CC) $(CFLAGS) \
		-DKVERSION=\"$(KVERSION)\" \
		-c -o emulate2.o emulate.c

clean:
	rm -f core *.o *.a *.s .depend

dep:
	$(CPP) -M -Iinclude $(OPTIONS) *.c > .depend
	$(CPP) -M -Iinclude $(OPTIONS) emulate.c | sed -e 's/emulate.o/emulate2.o/' >> .depend

dummy:

#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
