# BINTYPE must be set to generate QMAGIC a.out binaries in an ELF
# environment. Currently there is *no* support for an x286emul in
# any other format.
BINTYPE=i486-linuxaout
#BINTYPE=ix86-linuxaout


#CPPFLAGS=	-I../include -DNEW_SYSCALL -DDEBUG -DDEBUG_LDT -DDEBUG_CALL -DDEBUG_STACK
CPPFLAGS=	-I../include -DNEW_SYSCALL -DDEBUG
#CFLAGS= 	-g -O -Wall -Wstrict-prototypes
CFLAGS= 	-O2 -fomit-frame-pointer -m486 -Wall -Wstrict-prototypes
#LDFLAGS=	-Bstatic
LDFLAGS=	-s -Bstatic


BOOTOBJS=	boot.o
OBJS=		x286emul.o ldt.o syscall.o \
		emu_generic.o emu_memory.o emu_exec.o \
		emu_signal.o emu_odd.o

ifneq ($(BINTYPE),)
CC	:= /usr/$(BINTYPE)/bin/gcc -pipe -b $(BINTYPE)
LD	:= /usr/$(BINTYPE)/bin/ld -m i386linux
endif

GCCLIB=		`$(CC) --print-libgcc-file-name`


all:		message x286emul

message:
		@echo
		@echo "====================================================="
		@echo "x286emul is only used for Xenix 286 programs"
		@echo "You probably need not worry if this fails to compile."
		@echo "Just use the -i option to make if there is a problem."
		@echo "====================================================="
		@echo

install:	all
		cp x286emul /usr/lib/x286emul

clean:
		rm -f x286emul *.o


x286emul:	$(BOOTOBJS) $(OBJS)
		$(LD) $(LDFLAGS) -qmagic -o $@ \
			$(BOOTOBJS) \
			/usr/$(BINTYPE)/lib/crt0.o \
			$(OBJS) \
			-L/usr/$(BINTYPE)/lib \
			-lc $(GCCLIB) -lc $(GCCLIB)
#		$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTOBJS) $(OBJS)

dep:
		$(CC) -M $(CPPFLAGS) *.c > .depend

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