#
# Mach Operating System
# Copyright (c) 1990 Carnegie-Mellon University
# Copyright (c) 1989 Carnegie-Mellon University
# Copyright (c) 1988 Carnegie-Mellon University
# Copyright (c) 1987 Carnegie-Mellon University
# Copyright (c) 1986 Carnegie-Mellon University
# All rights reserved.  The CMU software License Agreement specifies
# the terms and conditions for use and redistribution.
#  
# HISTORY
# $Log:	Makefile,v $
# Revision 2.9  90/06/19  23:06:23  rpd
# 	Added -x to LDFLAGS for architectures not using xstrip.
# 	[90/06/03            rpd]
# 
# Revision 2.8  90/06/02  15:20:07  rpd
# 	Run xstrip on the emulator.
# 	[90/05/11            rpd]
# 	Process mach.defs with -DEMULATOR.
# 	[90/04/08            rpd]
# 	Added rules to run mig directly.
# 	Compile with -DMACH_IPC_COMPAT=0.
# 	[90/03/26  19:24:57  rpd]
# 
# 	Invoke emulator_base with ./emulator_base.
# 	[90/02/27  17:28:20  rpd]
# 
# Revision 2.7  90/05/29  20:22:20  rwd
# 	Added -DMAP_FILE to COPTS.
# 	[90/03/26            rwd]
# 
# Revision 2.6  90/05/21  13:45:12  dbg
# 	i386 loader doesn't look down LPATH (?!)
# 	[90/04/20            dbg]
# 
# Revision 2.5  90/03/14  21:22:30  rwd
# 	Add emul_mapped.c and define MAP_UAREA.
# 	[90/01/23            rwd]
# 
# Revision 2.4  89/11/29  15:24:39  af
# 	Mods to account for the Mips compiler specifics.
# 	[89/11/16  15:18:28  af]
# 
# Revision 2.3  89/10/17  11:23:48  rwd
# 	Added Makedep include and make
# 	[89/10/06            rwd]
# 
# Revision 2.2.1.1  89/09/21  20:35:20  dbg
# 	Remove genassym.c.
# 	[89/09/21            dbg]
# 
# Revision 2.2  89/08/09  14:35:11  rwd
# 	clean should remove *.[ch] also.
# 	[89/08/07            rwd]
# 
#
# Makefile for bsd emulator.
#
KCC=	cc
COPTS= -MD
CDEBUGFLAGS = $($(MACHINE)CDEBUGFLAGS?$($(MACHINE)CDEBUGFLAGS):-O)
DEFINES= -DTypeCheck=0 -DMACH_IPC_COMPAT=0 -DMAP_UAREA -DMAP_FILE
CFLAGS=	$(CDEBUGFLAGS) ${DEFINES} ${COPTS}
ASFLAGS= ${${MACHINE}ASFLAGS}
LDFLAGS= $(${MACHINE}LDFLAGS?${${MACHINE}LDFLAGS}:-x -e start)

PMAXCDEBUGFLAGS = -O2 -g3
PMAXASFLAGS= -nocpp
PMAXLDFLAGS= -e __start
AT386LDFLAGS= -x -e __start -L${MKLIB}

OBJS=	bsd_user_side.o emul_init.o emul_stack_alloc.o emul_generic.o \
	allocator.o mach_user.o syscall_table.o \
	emul_machdep.o emul_vector.o bsd_1_user.o emul_cache.o \
	emul_mapped.o

SRCS=	bsd_user_side.c emul_init.c emul_stack_alloc.c emul_generic.c \
	allocator.c syscall_table.c emul_cache.c emul_mapped.c \
	machine/emul_machdep.c machine/emul_vector.s \
	uxkern/bsd_1_user.c

emulator: ${OBJS} emulator_base
	ld -z -o emulator -T `./emulator_base` ${LDFLAGS} ${OBJS} \
		-lthreads -lmach_sa
	-xstrip emulator
	md -u Makedep -d *.d

.s.o:
	$(CC) -ES -MD ${DEFINES} $*.s > $*.as
	$(AS) ${ASFLAGS} -o $*.o $*.as
	rm -f $*.as

emulator_base: emulator_base.c
	$(CC) $(CFLAGS) -o emulator_base emulator_base.c

bsd_1_user.o: uxkern/bsd_1_user.c
	$(CC) $(CFLAGS) -c -o bsd_1_user.o uxkern/bsd_1_user.c

bsd_user_side.o: uxkern/bsd_1.h

#
#  Mach IPC-based interfaces
#

MAKE_UXKERN = [ -d uxkern ] || mkdir uxkern

MIG = mig
MIGFLAGS = -DMACH_IPC_COMPAT=0

BSD_FILES = uxkern/bsd_1.h uxkern/bsd_1_user.c

$(BSD_FILES): uxkern/bsd_types_gen.h ../server/uxkern/bsd_1.defs
	-$(MAKE_UXKERN)
	$(MIG) -MD $(MIGFLAGS) -header uxkern/bsd_1.h -user uxkern/bsd_1_user.c -server /dev/null ../server/uxkern/bsd_1.defs

#
# We have to tell Mig to generate a header file, even though we don't really
# want it, because the user file includes the header file from the current
# directory.
#

mach_user.c: mach/mach.defs
	$(MIG) -MD $(MIGFLAGS) -DEMULATOR -header mach_interface.h -user mach_user.c -server /dev/null mach/mach.defs

uxkern/bsd_types_gen.h : bsd_types_gen
	-$(MAKE_UXKERN)
	./bsd_types_gen > uxkern/bsd_types_gen.h

bsd_types_gen : bsd_types_gen.o
	${KCC} -o bsd_types_gen bsd_types_gen.o

bsd_types_gen.o : uxkern/bsd_types_gen.c
	${KCC} -c ${CFLAGS} uxkern/bsd_types_gen.c

clean:
	rm -rf emulator ${OBJS} uxkern migfiles *.[chd] Makedep

-include Makedep
