#
# Makefile for the iBCS emulator files
#
# $Id: Makefile,v 1.30 1994/11/25 14:50:17 mike Exp $
# $Source: /var/CVS/ibcs/Makefile,v $
#


# 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 supported
# by later 1.1 kernels. It is however not a good idea to try it unless
# there is kernel support for 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. If you are using auto allocation
# you should use a 2.0 or later version of /dev/MAKEDEV and run a
# 'cd /dev ; sh MAKEDEV update' after loading the iBCS module. Note
# that at least one version of MAKEDEV create /dev/XOR instead of /dev/X0R.

SOCKSYS_MAJOR=30


# The following emulations are provided. Select those which you wish
# the emulator to support.
# (You currently can't avoid the SVR4/SVR3/SCO... emulation)
#
# EMU_BSD		BSD emulator.
# EMU_X286		Xenix 286 emulator.
#
EMU_BSD		= yes
EMU_X286	= yes


# Binary formats to support.
#
# ELF is used by SVR4 (UnixWare, Dell etc.) however the ELF loader is part
# of later Linux kernels (1.1.54+). If you have kernel support for ELF
# binaries you don't need it in the emulator as well.
#
# COFF is used by SVR3 (SCO, Wyse V/386) however many SVR4 systems may
# also include older COFF binaries and many applications are sold as
# COFF binaries since they may run on more platforms.
#
# XOUT is used by Xenix (both 386 and 286) however many SVR3 (and even
# SVR4 systems) still have old XOUT binaries on them. Such programs
# were often written with 286 segmentation assumed and are too much
# trouble to port to a flat address space.
#
EMU_BINFMT_ELF	= yes
EMU_BINFMT_COFF	= yes
EMU_BINFMT_XOUT	= yes


# The following compile time options are available:
#
# IBCS_TRACE		Add code to trace the iBCS emulator. See the Tools
#			subdirectory for a program that can be used to set
#			the tracing level.
#
# VERBOSE_ERRORS	Give textual error message as well as number in
#                       the trace log. (This only makes sense if IBCS_TRACE
#                       is also defined)
#
# COFF_TRACE		Add code to trace the COFF loader. This is useful
#			if you have executables are not recognised correctly.
#
# XOUT_DEBUG		Add code to trace the XOUT loader.
#
IBCS_TRACE	= yes
VERBOSE_ERRORS	= yes
COFF_TRACE	= yes
XOUT_DEBUG	= no

# END CONFIGURATION SECTION


######## You should not need to change anything below this line ########


# Build the compile flags etc. based on the selected options.

EMUOPTS	=
EMULIBS	=
OBJS	= 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 \
	sysi86.o socksys.o ulimit.o utsname.o wysev386.o wysev386i.o \
	xnx.o xstat.o stream.o sysisc.o sysfs.o vtkd.o

ifeq ($(EMU_BSD),yes)
EMUOPTS	:= $(EMUOPTS) -DEMU_BSD
OBJS	:= $(OBJS) bsd.o bsdioctl.o bsdsignal.o bsdsocket.o bsdstat.o
endif
ifeq ($(EMU_X286),yes)
EMUOPTS	:= $(EMUOPTS) -DEMU_X286
EMULIBS	:= x286emul
endif

ifeq ($(EMU_BINFMT_ELF),yes)
EMUOPTS	:= $(EMUOPTS) -DEMU_BINFMT_ELF
OBJS	:= $(OBJS) binfmt_elf.o
endif
ifeq ($(EMU_BINFMT_COFF),yes)
EMUOPTS	:= $(EMUOPTS) -DEMU_BINFMT_COFF
OBJS	:= $(OBJS) binfmt_coff.o
endif
ifeq ($(EMU_BINFMT_XOUT),yes)
EMUOPTS	:= $(EMUOPTS) -DEMU_BINFMT_XOUT
OBJS	:=$(OBJS) binfmt_xout.o
endif

ifeq ($(IBCS_TRACE),yes)
EMUOPTS	:= $(EMUOPTS) -DIBCS_TRACE
endif
ifeq ($(VERBOSE_ERRORS),yes)
EMUOPTS	:= $(EMUOPTS) -DVERBOSE_ERRORS
endif
ifeq ($(COFF_TRACE),yes)
EMUOPTS	:= $(EMUOPTS) -DCOFF_TRACE
endif
ifeq ($(XOUT_DEBUG),yes)
EMUOPTS	:= $(EMUOPTS) -DXOUT_DEBUG
endif

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

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 $<


ifdef CONFIG_BINFMT_IBCS
all:	ibcs.o $(EMULIBS)

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

install: all
	cp iBCS /usr/lib/modules/iBCS
	$(MAKE) -C x286emul install

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

x286emul: dummy
	$(MAKE) -C x286emul

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

clean:
	rm -f core *.o *.a *.s .depend
	$(MAKE) -C x286emul clean

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
