#
# Makefile for the iBCS emulator files
#
# $Id: Makefile,v 1.34 1994/12/08 13:42:09 mike Exp $
# $Source: /var/CVS/ibcs/Makefile,v $
#

######## You should not need to change anything in this file ########

# Build the compile flags etc. based on the selected options in ./CONFIG.
# Edit ./CONFIG if you don't want the defaults!

include ./CONFIG

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 ($(XOUT_TRACE),yes)
EMUOPTS := $(EMUOPTS) -DXOUT_TRACE
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 Tools $(EMULIBS)

ibcs.o: emulate.o $(OBJS)
	$(LD) -r -o ibcs.o emulate.o $(OBJS)
	sync
else
all:	iBCS Tools $(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 Makefile CONFIG
	$(CC) $(CFLAGS) \
		-DKVERSION=\"$(KVERSION)\" \
		-c -o emulate2.o emulate.c

x286emul: dummy
	$(MAKE) -C x286emul

Tools:	dummy
	$(MAKE) -C Tools

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
