#
# Mach Operating System
# Copyright (c) 1991,1990,1989,1988,1987,1986 Carnegie Mellon University
# All Rights Reserved.
# 
# Permission to use, copy, modify and distribute this software and its
# documentation is hereby granted, provided that both the copyright
# notice and this permission notice appear in all copies of the
# software, derivative works or modified versions, and any portions
# thereof, and that both notices appear in supporting documentation.
# 
# CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
# ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
# 
# Carnegie Mellon requests users of this software to return to
# 
#  Software Distribution Coordinator   or   Software.Distribution@CS.CMU.EDU
#  School of Computer Science
#  Carnegie Mellon University
#  Pittsburgh PA 15213-3890
# 
# any improvements or extensions that they made and grant Carnegie Mellon
# the rights to redistribute these changes.
#  
# HISTORY
# $Log:	Makefile,v $
# Revision 2.4  92/02/02  13:00:03  rpd
# 	Revised for the new Makefile organization.
# 	[92/01/30            rpd]
# 

include ${MAKETOP}Makefile-common

# find machine-dependent files in machine subdirectory
# find mach/mach.defs on CPATH

VPATH = .:${cpu}:${CPATH}

# We want the POE version to be part of the emulator name.
# Makefile-version defines VERSION for us.

include ${MAKETOP}Makefile-version
EMULATOR = poe_emulator.${VERSION}

all : ${EMULATOR}

install : ${INSTALLDIR}/special/${EMULATOR}

release : ${TRELEASEDIR}/special/${EMULATOR}

clean :
	${RM} ${INSTALLDIR}/special/${EMULATOR}

emulator poe_emulator : ${EMULATOR}

# installation rules

${INSTALLDIR}/special/${EMULATOR} : ${EMULATOR}
	${RM} $@
	${CP} $? $@
	${XSTRIP} $@
	${CHMOD_BIN} $@

# release rules

${TRELEASEDIR}/special/${EMULATOR} : ${FRELEASEDIR}/special/${EMULATOR}
	${RM} $@
	${CP} $? $@

# the mkodirs target will create these directories

MKODIRS = mach

.INIT : mkodirs

# routines from mach/mach.defs that we get special versions of

MACH_ROUTINES = htg_vm_map

OBJS =	bsd_user_side.o emul_init.o emul_stack_alloc.o emul_generic.o \
	allocator.o syscall_table.o emul_machdep.o emul_vector.o \
	emul_cache.o bsd_1_user.o ${MACH_ROUTINES/.*/&.o}

LIBS = ${LIBMACH_SA}
DEPS = ${DEPMACH_SA} ${DEPCRT0}

${EMULATOR} : ${OBJS} emulator_base
	${RM} $@ $@.out
	${DEPS/%/$@} ${LD} -z -o $@.out -T `./emulator_base` ${LDFLAGS} \
		${CRT0} ${OBJS} ${LIBS} && \
	${MV} $@.out $@

# We want to include generated files and files from the poe sources with <>.

INCS = -I. -I../poe

# explicit dependencies on generated files

bsd_user_side.o : bsd_1.h

# mig rules to generate intermediate source files in the object directory

MACH_USER_SRCS = ${MACH_ROUTINES;.*;mach/&.c}
MACH_SRCS = mach/mach_interface.h ${MACH_USER_SRCS}

${MACH_SRCS} : mach/mach.defs
	${MIG} ${MIGFLAGS} -DEMULATOR -header mach/mach_interface.h -i mach/ -user '$${MACH_USER_SRCS}' -server /dev/null mach/mach.defs

BSD_SRCS = bsd_1.h bsd_1_user.c

${BSD_SRCS} : ../poe/bsd_1.defs
	${MIG} ${MIGFLAGS} -header bsd_1.h -user bsd_1_user.c -server /dev/null ../poe/bsd_1.defs

# build rules for mig objects.
# When talking to a server we trust (kernel or Poe),
# we disable type-checking.

${MACH_ROUTINES/.*/&.o} : $${@;(.*)\.o;mach/\1.c}
	${CC} -c ${CFLAGS} -DTypeCheck=0 ${@;(.*)\.o;mach/\1.c}

bsd_1_user.o : bsd_1_user.c
	${CC} -c ${CFLAGS} -DTypeCheck=0 bsd_1_user.c

# rules to generate emulator_base

emulator_base : emulator_base.c
	${RM} $@ $@.out
	${CC} -o $@.out ${CFLAGS} -D${TARGET_MACHINE}=1 emulator_base.c && \
	${MV} $@.out $@

-include Makedep
