#
# Mach Operating System
# Copyright (c) 1991,1990 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.6  92/02/02  13:01:27  rpd
# 	Revised for the new Makefile organization.
# 	[92/01/30            rpd]
# 

include ${MAKETOP}Makefile-common

# find machine-dependent files in machine subdirectory

VPATH = .:${cpu}

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

include ${MAKETOP}Makefile-version
POE = poe.${VERSION}

# top-level targets

all : poe_init boot ${POE}

install : ${INSTALLDIR}/etc/poe_init ${INSTALLDIR}/etc/boot \
		${INSTALLDIR}/special/${POE}

release : ${TRELEASEDIR}/etc/poe_init ${TRELEASEDIR}/etc/boot \
		${TRELEASEDIR}/special/${POE}

clean :
	${RM} ${INSTALLDIR}/etc/poe_init ${INSTALLDIR}/etc/boot \
		${INSTALLDIR}/special/${POE}

poe : ${POE}

# installation rules

${INSTALLDIR}/etc/poe_init : poe_init
	${RM} $@
	${CP} $? $@
	${STRIP} $@
	${CHMOD_BIN} $@

${INSTALLDIR}/etc/boot : boot
	${RM} $@
	${CP} $? $@
	${STRIP} $@
	${CHMOD_BIN} $@

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

# release rules

${TRELEASEDIR}/etc/poe_init : ${FRELEASEDIR}/etc/poe_init
	${RM} $@
	${CP} $? $@

${TRELEASEDIR}/etc/boot : ${FRELEASEDIR}/etc/boot
	${RM} $@
	${CP} $? $@

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

# Poe source files include machine-dependent files
# with <machine/root_device.h>, etc.
# We setup a link in the object directory to make this work.
# So that shadowing (sort-of) works, we search MAKEPSD
# for the first appropriate directory.

.INIT : mklinks

mklinks :
	@-[ -d machine ] || \
	{ echo "linking machine"; \
	  rm -f machine; \
	  ln -s `${WH} -p MAKEPSD -q -d ${cpu}` machine; }

# build rules

# files in this directory are included with <>
INCS = -I.

POE_OBJS = bsd_1Server.o udev_memory_objectServer.o \
	ufs_memory_objectServer.o bdev_fops.o bsd_copy.o bsd_descrip.o \
	bsd_dops.o bsd_exception.o bsd_exec.o bsd_exit.o bsd_fops.o \
	bsd_fops2.o bsd_fork.o bsd_host.o bsd_io.o bsd_ioctl.o \
	bsd_itimer.o bsd_lookup.o bsd_machdep.o bsd_misc.o bsd_mman.o \
	bsd_mount.o bsd_prot.o machine_ptrace.o bsd_select.o \
	bsd_signal.o bsd_server_side.o bsd_special.o init_sysent.o \
	main.o mem_fops.o server_loop.o syscall.o tty_fops.o \
	ufs_devpager.o ufs_dir.o ufs_dops.o ufs_fops.o ufs_inode.o \
	ufs_mount.o ufs_pager.o pipe_fops.o subr_cbuf.o subr_copy.o \
	subr_fops.o subr_timeout.o subr_uerror.o map_file.o \
	printf.o libc.o vers.o

POE_LIBS = ${LIBTHREADS} ${LIBMACH_SA}
POE_DEPS = ${DEPTHREADS} ${DEPMACH_SA} ${DEPCRT0}

${POE} : ${POE_OBJS}
	${RM} $@ $@.out
	${POE_DEPS/%/$@} ${LD} -z -o $@.out ${LDFLAGS} \
		${CRT0} ${POE_OBJS} ${POE_LIBS} && \
	${MV} $@.out $@

INIT_LIBS =
INIT_DEPS = ${DEPCRT0}

poe_init : minit.o
	${RM} $@ $@.out
	${INIT_DEPS/%/$@} ${CC} -o $@.out ${CFLAGS} minit.o ${INIT_LIBS} && \
	${MV} $@.out $@

BOOT_LIBS = ${LIBMACH}
BOOT_DEPS = ${DEPMACH} ${DEPCRT0}

boot : boot.o
	${RM} $@ $@.out
	${BOOT_DEPS/%/$@} ${CC} -o $@.out ${CFLAGS} boot.o ${BOOT_LIBS} && \
	${MV} $@.out $@

# rules to make vers.c

VERSION_FILES = conf/version.major \
		conf/version.minor \
		conf/version.variant \
		conf/version.edit \
		conf/version.patch

vers.c : ${VERSION_FILES} conf/copyright conf/newvers.sh
	@/bin/sh conf/newvers.sh conf/copyright `cat ${VERSION_FILES}`

# mig rules

bsd_1Server.c : bsd_1.defs
	${MIG} ${MIGFLAGS} -header /dev/null -user /dev/null bsd_1.defs

ufs_memory_objectServer.c : memory_object.defs
	${MIG} ${MIGFLAGS} \
		-DSUBSYSTEM=ufs_memory_object -DSERVERPREFIX=ufs_ \
		-header /dev/null -user /dev/null memory_object.defs && \
	mv memory_object.defs.d ufs_memory_object.defs.d

udev_memory_objectServer.c : memory_object.defs
	${MIG} ${MIGFLAGS} \
		-DSUBSYSTEM=udev_memory_object -DSERVERPREFIX=udev_ \
		-header /dev/null -user /dev/null memory_object.defs && \
	mv memory_object.defs.d udev_memory_object.defs.d

-include Makedep
