#
# HISTORY
#
#  22-Dec-87  Mary R. Thompson at Carnegie Mellon
#	Added mach.defs and a machUser.c -> mach_user.c rule
#
#  14-Dec-87  Mary R. Thompson at Carnegie Mellon
#	Added pagerServer.o to libmach.a, and rename exception.defs
#	to exc.defs
#
# 23-Nov-87  Mary R. Thompson at Carnegie Mellon
#	Changed rules for msgnUser.c as it now a write around
#	for netnameUser.c
#
# 28-Oct-87  Mary R. Thompson at Carnegie Mellon
#	Add exception.defs
#
# 31-Jul-87  Mary R. Thompson at Carnegie Mellon
#	Added mig_support to LIB_SRCS
#
# 14-May-87  Mary R. Thompson at Carnegie Mellon
#	Added ipcxUser to USER and USERC
#
# 25-Apr-87  Mary R. Thompson at Carnegie Mellon
#	Added msg_receive to OBJS
#
#  2-Apr-87  David Black (dlb) at Carnegie-Mellon University
#	Add ts_convert.o to OBJS.
#
# 25-Mar-87  Mary R. Thompson
#	Added missing things to the LNTSRCS, added slot_name to
#	list of SRC
#
# 12-Mar-87  Mary R. Thompson
#	Removed accent_calls.h from the LINTSRCS
#
# 30-Jan-87  Mary R. Thompson
#	Moved msg_type.h install here from mig
#
# 30-Jan-87  Mary R. Thompson
#	Merged jjc changes of Nov 25 for the sun
#	Changed action for .cs files to put output from preprocessor
#	into an intermediate file and pass it to the assembler as an
#	input file because the Sun assembler can't have its input
#	piped in.
#
# 29-Jan-87  Mary R. Thompson
#	Added a copy of mach_extra.h to the include step
#
# 15-Jan-87  Mary R. Thompson (mrt) at Carnegie Mellon
#	Added Ovfork.c to list of files for libmach
#


DSTDIR=/usr/mach
INSTALL_DIR=${DSTDIR}/lib
SRCDIR=${DSTDIR}/src
SERVERINCDIR=${INCDIR}/servers
LINT=${DSTDIR}/lib/lint
TARGET_DIRS=${INSTALL_DIR} $(SERVERINCDIR) $(LINT) $(INCDIR)

ASM_CFLAGS = -A -MD
LINTLIB=llib-lmach.ln

LIB_BLD=libmach.a

.SUFFIXES: .cs

.cs.o:
	$(CC) -ES -MD $*.cs > $*.as
	as -o $*.o $*.as
	rm -f $*.as
	md -u Makedep -d $*.d

LIB_SRCS=	mach_traps.c mach_init.c  sbrk.c \
	mach_error.c fork.c Ovfork.c slot_name.c mig_support.c \
	ts_convert.c msg_receive.c mach_user.c\
	msgnUser.c env_mgrUser.c ipcxUser.c netnameUser.c serviceUser.c \
	excUser.c excServer.c pagerServer.c

USERC=	msgnUser.c  env_mgrUser.c ipcxUser.c netnameUser.c serviceUser.c \
	excUser.c mach_user.c

DEFS=	exc.defs mach.defs pager.defs
INCS=	mach.h mach_init.h mach_error.h mach_extra.h msg_type.h

include $(SRCDIR)/Make.inc

# Sources for raw traps are taken from kernel include files.
# Routines that shadow libc versions are ignored.
# .h files are used for mig generated interfaces instead of the .c files
# message.h defines msg_send, msg_receive and msg_rpc so msg_receive.c is not
# included

LINTSRC=$(INCDIR)/kern/mach_traps.h \
	mach_init.c sbrk.c Ovfork.c slot_name.c mig_support.c \
	mach_error.c $(INCDIR)/sys/message.h \
	$(INCDIR)/mach.h netname.h env_mgr.h \
	ipcx.h exc.h


all:	${LINTLIB}

# sbrk requires special rule because it contains asm statements.
# sbrk cannot be compiled by hc
sbrk.o: sbrk.c
	cc ${ASM_CFLAGS} -c $*.c
	md -u Makedep -d $*.d

# cannot compile with hc
mach_traps.o: mach_traps.cs
	cc -ES -MD mach_traps.cs > mach_traps.as
	as -o mach_traps.o mach_traps.as
	rm -f mach_traps.as
	md -u Makedep -d mach_traps.d


# cannot compile with hc
fork.o: fork.$(machine).cs
	cc -ES -MD $*.$(machine).cs > $*.as
	as -o $*.o $*.as
	rm -f $*.as
	md -u Makedep -d $*.$(machine).d

${LINTLIB}:	${LINTSRC}
	-if [ -f /usr/cs/bin/lint ]; then \
		lint -Cmach -DLINTLIBRARY ${LINTSRC}; else exit 0; fi

build_interface: ${USERC}


mach_user.c: mach.defs
	mig mach.defs
	mv machUser.c mach_user.c
	rm -f machServer.c

msgnUser.c: $(FORCE)
	cp -p  ${SRCDIR}/etc/netmsgserver/msgnUser.c .

netnameUser.c: $(FORCE)
	cd ${SRCDIR}/etc/netmsgserver; \
	make interface DSTDIR=$(DSTDIR) CPDIR=${SRCDIR}/lib/libmach

env_mgrUser.c: $(FORCE)
	cd ${SRCDIR}/etc/envmgr; \
	make interface DSTDIR=$(DSTDIR) CPDIR=${SRCDIR}/lib/libmach

serviceUser.c: $(FORCE)
	cd ${SRCDIR}/etc/service; \
	make interface DSTDIR=$(DSTDIR) CPDIR=${SRCDIR}/lib/libmach

ipcxUser.c: $(FORCE)
	cd ${SRCDIR}/etc/ipcexecd; \
	make interface DSTDIR=$(DSTDIR) CPDIR=${SRCDIR}/lib/libmach

include: 	$(TARGET_DIRS) envmgr.install netname.install \
		ipcx.install service.install exc.install

envmgr.install: emdefs.h env_mgr.h 
	-@mach_install $I -c emdefs.h env_mgr.h ${SERVERINCDIR}
	-@touch envmgr.install

service.install: service.h 
	-@mach_install $I -c service.h ${SERVERINCDIR}
	-@touch envmgr.install
	
ipcx.install: ipcx_types.h ipcx.h 
	-@mach_install $I -c ipcx_types.h ipcx.h ${SERVERINCDIR}
	-@touch ipcx.install

netname.install: netname_defs.h netname.h 
	-@mach_install $I -c netname_defs.h netname.h ${SERVERINCDIR}
	-@touch netname.install
	
exc.install: exc.h
	-@mach_install $I -c exc.h ${INCDIR}
	-@touch exc.install

install:	${LINTLIB}.install \
		envmgr.install ipcx.install \
		netname.install service.install exc.install



${LINTLIB}.install:	${LINTLIB}
	-@mach_install $(I) -c ${LINTLIB} ${LINT}/${LINTLIB}
	-@touch ${LINTLIB}.install


