# 
# Midway Distributed Shared Memory System
# Copyright (c) 1994 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.
#
#
# HISTORY
# 25 Aug 92 (bnb): created.
#  2 Sep 92 (mjz): fix dependencies
#  3 Oct 92 (mjz): fix for long object names -- ar truncates name AFTER
#		searching for it, so they get duplicated.  Barf.
#  5 Oct 92 (was): added gprof support
# 15 Oct 92 (mjz): fix "ar" commands to use '-', otherwise we barf if
#		the library doesn't exist.
# 28 Oct 92 (mjz): ATM interface, the easy way.
#  7 Jul 93 (mjz): upgrade for mk82 (really mk79 & beyond -- ode tools[md])

-include Makefile-common

.SUFFIXES: .c .o

LIB = libmidway.a

MEMDIR = memory
SMEXECDIR = ../smexec
XPAGERDIR = xpager
GPROFDIR = ../gprof
#ATMDIR = /afs/cs/user/jcb/atm/src
#ATMDIR = /afs/cs/project/midway/mattz/mw/src/atmsrc
#ATMDIR = /afs/cs/project/midway/mattz/mw/src/atmsrc2
# following for Interrupts + Signalling
#ATMDIR = /afs/cs/project/midway/mattz/mw/src/atmsrc4
#ATMDIR = /afs/cs/project/mach-14/bershad/src/atm

#
# Ancient HISTORY
# 22 Aug 91 (mjz): add new header file midway.h (old midway_mem)
#		Add runtime files.  For now punt general dependency
#		mechanism for MiG files, and include dependencies here.
#
# 18 Sep 91 (mjz): fix dependency handling; only massage "lib" members
#		in Makedep
# 12 Dec 91 (mjz): add -DDEBUG_PRT for comm.c for a while...
# 29 Jan 92 (mjz): add -lcthread for smexecd for mach3bogus handler
# 18 Jun 92 (was): added commands to built porting library
#
# 1 jul 92 : use PORT=1 when compiling porting library for now... 


VPATH =  $(MEMDIR):$(SMEXECDIR):$(XPAGERDIR):$(GPROFDIR)


#ode md: need directories that it will find include files in
# how adjust runtime/memory?
### Unfortunately, this only works for odemake, not CMU make (nor std make)
### (and you want a trailing "g" on the substitutions in odemake)
###
###MD_DIRS = $(VPATH/:/ /)  . ..
###MD_DIRS = $(MD_DIRS/^/-I/)
###TSD = $(CPATH/:/ /)
###STD_INCDIRS = $(TSD/^/-I) $(TSD/^/-K)
###MD_DIRS = $(MD_DIRS) -I- $(STD_INCDIRS)
VDIRS = `echo $(VPATH) | sed -e 's/:/ -I/g' -e 's/^/-I/'`
CDIRS = `echo $(CPATH) | sed -e 's/::/:/g' -e 's/:/ -I/g' -e 's/^/-I/'`
CDIRK = `echo $(CPATH) | sed -e 's/::/:/g' -e 's/:/ -K/g' -e 's/^/-K/'`
MD_DIRS = $(VDIRS) -I. -I.. -I- $(CDIRS) $(CDIRK)

.c.o:
	$(CC) $(CFLAGS) $(PROFILE) -c $*.c
	touch Makedep; md -file Makedep -std -rm $(MD_DIRS) $*.d

all:   $(LIB) 

OBJS_MEM = shmalloc.o shregion.o shmalloc_init.o midway.o \
	realmain.o comm.o lock.o rsched.o queue.o \
	pbuf.o pmsg.o lockaddr.o  barrier.o uxpass.o \
	exception.o timer.o vm.o gprof_support.o mcount.o \
	pagemgr.o updateq.o linex.o maptime.o mapfrc.o sys_stat.o \
	template.o stack.o ipatch.o version.o midway_start.o \
	midway_end.o vm_paged.o

OBJS_SMEXEC = ssUser.o midwayuxUser.o smexecdUser.o netnameUser.o

OBJS_XPAGER = XPagerServer.o xpager_init.o xpager_obj.o  \
		xpager.o backing.o panic.o \
		mach_msg_server.o memory_objectServer.o

OBJS_ATM = atm_iface.o $(ATMDIR)/atm_driver.o $(ATMDIR)/atm_rx.o \
		$(ATMDIR)/atm_tx.o $(ATMDIR)/atm_mapped.o

#no longer need atm_map.o 31jan94
OBJS_NET = socket_iface.o atm_iface.o atm_print.o

OBJS =  $(OBJS_MEM) $(OBJS_SMEXEC) $(OBJS_XPAGER) $(OBJS_NET)


# The following are the "generic" rules,
# We are not handling the smexec libs very well at all.
# 
libmidway.a: $(OBJS)
	$(AR) r$(ARFLAGS) $(LIB) $?
	$(RANLIB) $(LIB)


XXinclude:	machine midway.h midway_mem.h shmalloc.h
		ln -s midway.h  /afs/cs/project/midway/@sys/include
		ln -s midway_mem.h /afs/cs/project/midway/@sys/include
		ln -s shmalloc.h /afs/cs/project/midway/@sys/include

machine:
	-if [ -d machine ]; then true; else ln -s $(machine) machine; fi

clean:
	$(RM) $(RMFLAGS) machine libmidway.a Makedep* a.out core errs \
			 *.d *.s *.S *.o *.BAK *.CKP */*.BAK */*.CKP

#
# Special rules for memory
#
# [note: ode md barfs if .d doesn't exist, and .s files don't generate 'em.]

template.o: machine/template.s
	$(OLDCC) $(CFLAGS:-MD=) $(PROFILE_DBITS) -c machine/template.s
#	md -m Makedep -d template.d

stack.o: machine/stack.s
	$(OLDCC) $(CFLAGS:-MD=) $(PROFILE) -c machine/stack.s
#	md -m Makedep -d stack.d

midway_start.o: machine/midway_start.s midway_comp.h
	$(CC) $(CFLAGS:-MD=) $(PROFILE) -c machine/midway_start.s
#	md -m Makedep -d midway_start.d

midway_end.o: machine/midway_end.s
	$(CC) $(CFLAGS:-MD=) $(PROFILE) -c machine/midway_end.s
#	md -m Makedep -d midway_end.d

ipatch.o: machine/ipatch.c midway_comp.h
	$(CC) $(CFLAGS:-MD=) $(PROFILE) -c machine/ipatch.c
#	md -m Makedep -d ipatch.d

#
# special rules because of ar hosage (at least on the mips)
#
mach_msg_server.o: mach_msg_server.c
	$(CC) $(CFLAGS) -c $*.c
	touch Makedep; md -file Makedep -std -rm $(MD_DIRS) $*.d
	-ar d $(LIB) mach_msg_server

memory_objectServer.o: memory_objectServer.c
	$(CC) $(CFLAGS) -c $*.c
	touch Makedep; md -file Makedep -std -rm $(MD_DIRS) $*.d
	-ar d $(LIB) memory_objectSe

#
# Special rules for gprof. Never compile with -pg option!
#
gprof_support.o: gprof_support.c gprof.h
	$(CC) $(CFLAGS) -c $*.c
	touch Makedep; md -file Makedep -std -rm $(MD_DIRS) $*.d

mcount.o: machine/mcount.s
	$(OLDCC) $(CFLAGS:-MD=) -c machine/mcount.s
# ode md barfs if .d file does not exist.
#	md -file Makedep -rm mcount.d
	

# need rules for mig generated stuff... esp when not in directory and
# no Makedep available yet
comm.o:	comm.c ss.h
uxpass.o: uxpass.c midwayux.h

#
# Rules for to compile vm_allocate
#
vm.o:	vm.c XPager.h
	$(CC) $(CFLAGS) -c $*.c
	touch Makedep; md -file Makedep -std -rm $(MD_DIRS) $*.d


#
#
# Rules for smexec;  [used by ? --2sep92mjz]
#
smexecd.h smexecdUser.c: smexecd.defs
	-rm smexecd.migout
	mig -v smexecd.defs > smexecd.migout

ss.h ssUser.c: ss.defs
	-rm ss.migout
	mig -v ss.defs > ss.migout

midwayux.h midwayuxUser.c: midwayux.defs
	-rm midwayux.migout
	mig -v midwayux.defs > midwayux.migout

# Why is this here? --2sep92 mjz
netname.h netnameUser.c: netname.defs
	-rm netname.migout
	mig -v netname.defs > netname.migout

# 
# Rules for xpager
#


XPager.h XPagerServer.c : xpager.defs
	-rm xpager.migout
	mig -v xpager.defs > xpager.migout

# I am not sure about this either --2sep92mjz
memory_objectServer.c: memory_object.defs
	-rm memory_object.migout
	mig -v memory_object.defs > memory_object.migout

#
# Rules for version.c
#
#version.o: version.c gen_version
#	
#version.c: gen_version
#	./gen_version
#
#gen_version: gen_version.o
#	$(CC) -o gen_version gen_version.o $(LIBFLAGS)

#
#
#

-include Makedep

