#
# 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 1.8  92/03/30  15:29:28  pha
# 	remove -z flag and -UCMUCS flag on options
# 
# Revision 1.7  92/03/19  11:31:07  pha
# 	don't do xstrip or mkdep
# 
# Revision 1.6  92/03/19  11:19:58  pha
# 	remove -DMACH_AFS (we don't have it - causes e_opioctl to be undef)
# 
# Revision 1.5  92/03/19  11:11:48  pha
# 	fix to include proper library path
# 
# Revision 1.4  92/03/18  22:20:45  kawada
# 	Corrected wrong option for cc.
# 
# Revision 1.3  92/03/18  14:18:31  pha
# 	hard code mig path
# 
# Revision 1.2  92/03/18  14:09:50  pha
# 	modified to build emulator on ashura unix
# 
# Revision 1.1.1.1  92/03/02  17:55:08  pha
# osf/1 server V3.5
# 
# Revision 1.1  92/03/02  17:55:07  pha
# Initial revision
# 
# Revision 1.1.1.1  92/03/02  17:51:03  pha
# osf/1 server V3.5
# 
# Revision 1.1  92/03/02  17:51:01  pha
# Initial revision
# 
# Revision 3.12  92/02/28  17:59:14  barbou
# Cleaned debugging message.
# 
# Revision 3.11  92/02/28  00:10:56  condict
# Shorten VPATH and CPATH for efficiency.
# Add user_copy.s.
# 
# Revision 3.10  92/02/25  17:47:53  condict
# Remove useless MAP_FILE option (was slowing down the emulator).
# 
# Revision 3.9  91/11/08  13:55:14  bernadat
# Added -DASSEMBLER flag for assembly file compiles
# 
# Revision 3.8  91/11/07  15:15:00  condict
# Substantially changed to support shadow source trees (Paul Roy).
# 
# Revision 3.7  91/10/30  17:41:24  bernadat
# Added -DMACH_AFS.
# 
# Revision 3.6  91/09/06  13:47:58  condict
# Move the include of Makefile.machine to here from Makeconf (fix build err).
# 
# Revision 3.5  91/08/30  10:25:53  condict
# Change make built-in var TARGET_MACHINE to TARGET_CPU, allow cross-compiles.
# 
# Revision 3.4  91/05/29  21:41:18  condict
# Change -g compiler flag to -O.
# 
# Revision 3.3  91/04/12  13:41:02  condict
# Change name of syscall_table.c to emul_sysent.c;
# Generate emul_sysent.c automatically from server/conf/syscalls.master
# Make the MIGFLAGS use the same defines as CFLAGS.
# 
# Revision 3.2  91/03/08  15:51:20  condict
# Modified to work with the OSF/1 header files
# 
# Revision 3.1  91/02/27  16:19:59  condict
# Undefine the built-in CMUCS symbol
# 
# Revision 3.0  91/01/17  12:05:01  condict
# Unchanged copy from Mach 3.0 BSD UNIX server
# 
# Revision 2.11  90/11/05  15:30:56  rpd
# 	Change MACHINE to TARGET_CPU.
# 	[90/10/30            rwd]
# 
# Revision 2.10  90/10/25  15:06:12  rwd
# 	Add I386 (same as AT386)
# 	[90/10/24            rwd]
# 
# 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.
#

target_cpu=m88k
TARGET_CPU=M88K

all:	emulator

VPATH= ${target_cpu}:../server
CPATH= .:${MAKECONF:h}/server:${SOURCEDIR}/server:${MKINC}:../server/include
LPATH= ${MKLIB}:${LPATH}
PATH = ${MKBIN}:${PATH}

.EXPORT: VPATH CPATH LPATH PATH

KCC=	cc
INCLUDES= -nostdinc -I. -I../../../src/osf1.server/emulator -I../server/include -I../../../src/osf1.server/server -I${MKINC} -I../../../src/osf1.server/usr/include
COPTS = ${INCLUDES}
CDEBUGFLAGS = $($(TARGET_CPU)CDEBUGFLAGS?$($(TARGET_CPU)CDEBUGFLAGS):-O)
DEFINES= -DTypeCheck=0 -DMACH_IPC_COMPAT=0 -DMAP_UAREA -DOSF1_SERVER -D_KERNEL -DCOMPAT_43
CFLAGS=	$(CDEBUGFLAGS) ${DEFINES} ${COPTS}
ASFLAGS= ${${TARGET_CPU}ASFLAGS}
LDFLAGS= $(${TARGET_CPU}LDFLAGS?${${TARGET_CPU}LDFLAGS}:-x -e start)

PMAXCDEBUGFLAGS = -O2 -g3
PMAXASFLAGS= -nocpp
PMAXLDFLAGS= -e __start
AT386LDFLAGS= -x -e __start -L${MKLIB}
I386LDFLAGS= -x -e __start -L${MKLIB}
M88KLDFLAGS= -e start -L${MKLIB}
I386CDEBUGFLAGS = -O
M88KCDEBUGFLAGS = -g

OBJS=	bsd_user_side.o emul_init.o emul_stack_alloc.o emul_generic.o \
	allocator.o mach_user.o emul_sysent.o \
	emul_machdep.o emul_vector.o bcopy.o user_copy.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 emul_sysent.c emul_cache.c emul_mapped.c \
	${target_sys}/emul_machdep.c ${target_sys}/emul_vector.s \
	${target_sys}/bcopy.s ${target_sys}/user_copy.s uxkern/bsd_1_user.c

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

print_env:
	@echo CPATH=${CPATH}
	@echo VPATH=${VPATH}

.s.o:
	cpp -MD ${DEFINES} -DASSEMBLER $*.s > $*.i
	$(AS) ${ASFLAGS} -o $*.o $*.i
	rm -f $*.i

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

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

#
#  The sysent tables, mapping trap numbers to actions, are generated
#  automatically on both the emulator and the server side:
#
emul_sysent.c: ../server/conf/makesyscalls.sh ../server/conf/syscalls.master
	../server/conf/makesyscalls.sh -e ../server/conf/syscalls.master

#
#  Mach IPC-based interfaces
#

MAKE_UXKERN = [ -d uxkern ] || mkdir uxkern

MIG = /usr/mach3/bin/mig
MIGFLAGS = ${DEFINES} ${INCLUDES}

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: ${MKINC}/mach/mach.defs
	$(MIG) -MD $(MIGFLAGS) -DEMULATOR -header mach_interface.h -user mach_user.c -server /dev/null ${MKINC}/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
