#
# $RCSfile: Makefile,v $ 
# $Revision: 2.57 
# $ $Date: 1996/05/04 21:55:33 $
#
MODULE = serverlib
PARENT= src
PATHTOROOT=..
EXECS=
FILESC=
FILESH=
FILESO=
SPECIALINCLUDE=
LOCALCLEANFILES=formatdisk
LOCALRCSFILES=
MAKEFILES = Makefile makefile.subdir 
LITTLEMAKEFILE=true
#
#modules to get from the baseline
#
MOD_BASELINE =

#
#modules in the local work space
#
MOD_WORKSPACE = admin analyze bf bitmap bm btree cl common disk\
	distr fi include io log lg lhash lm mr msg recover redo resource\
	sharedcode sm sync thread trace trans util undo 

#
# SPECIALFILESO is a list of *all* the subdir $(MODULE).o files
# 	It's needed for making a server library ** in the baseline** directory
# 	w/o doing a 'find' (as is done with target $(SLIB)).
#   If we were to use the target $(SLIB) in the baseline, we'd get
#	"multiply  defined" errors for everything.
SPECIALFILESO =  admin/admin.o analyze/analyze.o \
		  bitmap/bitmap.o bm/bm.o bf/bf.o btree/btree.o\
		  cl/cl.o common/common.o \
		  disk/disk.o distr/distr.o fi/fi.o io/io.o redo/redo.o log/log.o lg/lg.o \
		  lhash/lhash.o lm/lm.o mr/mr.o msg/msg.o recover/recover.o \
		  resource/resource.o \
		  sm/sm.o thread/thread.o trace/trace.o trans/trans.o \
		  sync/sync.o undo/undo.o util/util.o sharedcode/sharedcode.o 


COPIES = $(BASELINE)/$(PARENT)/$(MODULE)/formatdisk

LINKS = $(PATHTOROOT)/formatvolume/formatvol$(SUFFIX) \
	$(PATHTOROOT)/diskproc/$(DISKRW) \
	$(PATHTOROOT)/server/$(SERVER) 

OTHERTAGS=$(PATHTOROOT)/include/tags $(PATHTOROOT)/common/tags\
	$(PATHTOROOT)/diskproc/tags\
	$(PATHTOROOT)/formatvolume/tags\
	$(PATHTOROOT)/server/tags

#
# This should be a library, but it's sooooo big that we haven't enough
# disk space for the temp files required by ar(1).
#
SLIB = libsm_server.a

defaultTarget: workspace.mod

include makefile.depend

#
# $(SLIB) ***MUST*** appear before $(LINKS) in this dependency
# or we can get a circular dependency (with the targets of the links
# depending on libsm_server.a)
# For the same reason, this dependency must come before makefile.common
# is included, because makefile.common has a workspace.mod depending on LINKS.
#

include $(PATHTOROOT)/makefile.common

workspace.mod:	 $(SLIB) sdbx $(LINKS)

$(SLIB):  workspace.mod.recursive $(PATHTOROOT)/common/common.o link
	@echo making $(MODULE) with flags $(DEBUGFLAGS)

link load loadall:
	-rm -f $(SLIB)
	$(AR) crl $(SLIB) $(PATHTOROOT)/common/common.o \
		`find $(MOD_WORKSPACE) $(BASELINE_OBJS) -name "*.o" -print`
	ranlib $(SLIB)

cleaninstall:
	-rm -f $(SLIB)

install:
#	
	-chmod +w $(LIBDIR)/$(SLIB)
	rm -f $(LIBDIR)/$(SLIB)
	cp $(SLIB) $(LIBDIR)
	ranlib $(LIBDIR)/$(SLIB)
	chmod -w $(LIBDIR)/$(SLIB)


getbaseline: links $(COPIES) include
	-ln -s $(BASELINE)/$(PARENT)/$(MODULE)/tags .
	-ln -s $(BASELINE)/$(PARENT)/$(MODULE)/$(SLIB) .
	(cd include; $(MAKE) getbaseline)

sdbx:
	rm -f $@
	echo  dbx \\ > $@
	for i in `echo $(MOD_WORKSPACE)`; do ( \
		echo -I $(PATHTOROOT)/$(MODULE)/$$i \\ >> $@ \
	); done;
	for i in `echo $(MOD_BASELINE)`; do ( \
		echo -I $(BASELINE)/$(PARENT)/$(MODULE)/$$i \\ >> $@ \
	); done;
	@echo \$$\* >> $@
	@chmod +x $@


baseline.mod :
	@echo "making $(MODULE) "
	@for i in ${MOD_WORKSPACE}; \
		do (cd $$i; $(MAKE) "CC = $(CC)" $$i.o); done;
	@echo ld -r ~~~ -o $(SLIB)
	ld -r $(SPECIALFILESO) -o $(SLIB)

formatvol : $(SLIB)
	@(cd $(PATHTOROOT)/formatvolume; $(MAKE) "CC = $(CC)" $@; )

diskrw : $(SLIB)
	@(cd $(PATHTOROOT)/diskproc; $(MAKE) "CC = $(CC)" $@; )

mr_stub :
	(cd mrserver; $(MAKE) "CC = $(CC)" $@; )

touch: touch.local
touch.local:
	touch $(SLIB) 

depend: localdepend

#
# The following causes $(SLIB) to be remade if any of the subdirs
# were remade since $(SLIB) was last made.  But it doesn't make
# $(SLIB) depend on the sources in the subdirs.  This is about all
# we can do,  short of naming every source file in the whole bloomin'
# library.
#
localdepend:
	touch makefile.depend
	for i in `echo $(MOD_WORKSPACE)`;\
		do\
			echo "$(SLIB):	$$i/$$i.o" >> makefile.depend;\
			echo "$$i/$$i.o:; cd $$i; \$$(MAKE) workspace.mod" >> makefile.depend;\
			done;

