#
# $RCSfile: Makefile,v $ 
# $Revision: 1.109 $
# $Date: 1993/07/01 18:56:47 $
#
MODULE = client
PARENT = src
PATHTOROOT=..
LOCALRCSFILES=
LOCALCLEANFILES=sm_staff.h sm_client.h cdbx shutserver sm_client.h.awk
MAKEFILES = Makefile makefile.subdir 
OTHERTAGS = $(PATHTOROOT)/include/tags $(PATHTOROOT)/common/tags
LIBS=$(PATHTOROOT)/common/common.o $(PATHTOROOT)/config/config.o

LITTLEMAKEFILE=

#
FILESH=

RESULTS = sm_staff.h sm_client.h libsm_client.a

#
#BASELINE= 
# 	BASELINE should be defined in your environment and you should use make -e!
#

#
# modules to get from the baseline
#
MOD_BASELINE =

#
# modules in the local work space
#
MOD_WORKSPACE = bf btree clog fi include io lg lhash\
	lm msg sm smint trace trans util version

SM_CLIENT_O_FILES = bf/bf.o btree/btree.o\
	 clog/clog.o msg/msg.o fi/fi.o io/io.o \
	 lhash/lhash.o lg/lg.o lm/lm.o \
	 sm/sm.o smint/smint.o trace/trace.o trans/trans.o \
	 version/version.o util/util.o 

GINCLUDE=$(PATHTOROOT)/include
CLIENTINCLUDE=$(PATHTOROOT)/client/include
# 
# Source files for creating sm_client.h 
SM_H =  \
		$(CLIENTINCLUDE)/forward.h           \
		$(GINCLUDE)/checking.h $(GINCLUDE)/ess.h          \
		$(GINCLUDE)/msgstats.h \
		$(GINCLUDE)/list.h \
		$(GINCLUDE)/io.h       $(GINCLUDE)/object.h       \
		$(GINCLUDE)/tid.h      $(CLIENTINCLUDE)/trans_globals.h\
		$(CLIENTINCLUDE)/serverinfo.h           \
		$(GINCLUDE)/distr.h \
		$(GINCLUDE)/softwareVersion.h \
		$(GINCLUDE)/adminmsg.h \
		$(CLIENTINCLUDE)/bf.h           \
		$(CLIENTINCLUDE)/bf_extfuncs.h           \
		$(CLIENTINCLUDE)/volume.h           \
		$(CLIENTINCLUDE)/scan.h     $(CLIENTINCLUDE)/load.h         \
		$(CLIENTINCLUDE)/file.h     $(GINCLUDE)/error.h        \
		$(GINCLUDE)/sm_macro.h \
		$(GINCLUDE)/lock.h \
		$(GINCLUDE)/global_trace.h \
		$(CLIENTINCLUDE)/trace.h \
		$(CLIENTINCLUDE)/sm_globals.h   \
		$(CLIENTINCLUDE)/sm_params.h	\
		$(CLIENTINCLUDE)/sm_state.h	\
		$(CLIENTINCLUDE)/sm_user.h $(CLIENTINCLUDE)/btree.h\
		$(CLIENTINCLUDE)/sm_extfuncs.h	


LINKS=$(PATHTOROOT)/admin/shutserver 
COPIES=$(BASELINE)/$(PARENT)/$(MODULE)/cdbx 

#
# This dependency must precede makefile.common, 
#  and RESULTS **must** precede $(LINKS) so that we don't get
#	circular dependencies.
#
$(MODULE) workspace.mod:	 $(RESULTS) $(LINKS)

include $(PATHTOROOT)/makefile.common

#
# Targets specific to this directory
#

touch: touch.local
touch.local:
	touch $(RESULTS)

install: libsm_client.a
#	
	-chmod +w $(LIBDIR)/libsm_client.a
	rm -f $(LIBDIR)/libsm_client.a
	cp libsm_client.a $(LIBDIR)
	ranlib $(LIBDIR)/libsm_client.a
	chmod -w $(LIBDIR)/libsm_client.a
#	
	-chmod +w $(INCLUDEDIR)/sm_client.h
	-rm -f $(INCLUDEDIR)/sm_client.h
	cp sm_client.h $(INCLUDEDIR)
	chmod -w $(INCLUDEDIR)/sm_client.h 

libsm_client.a: $(LIBS) workspace.mod.recursive libsm_client.a.nodepend

libsm_client.a.nodepend:
	-rm -f libsm_client.a
	-echo $(AR) libsm_client.a 
	$(AR) crl libsm_client.a\
		$(LIBS) `find $(MOD_WORKSPACE) $(MOD_BASELINE) -name "*.o" -print` 
	ranlib libsm_client.a

getbaseline:	getbaselinelocal
getbaselinelocal: links include $(COPIES)
	@echo getting $@ in $(MODULE)
	-ln -s $(BASELINE)/$(PARENT)/$(MODULE)/sm_client.o .
	-ln -s $(BASELINE)/$(PARENT)/$(MODULE)/sm_client.h .
	-ln -s $(BASELINE)/$(PARENT)/$(MODULE)/tags .
	(cd include; $(MAKE) getbaseline)

baseline.mod : $(SM_CLIENT_O_FILES) 
	(cd ../config; $(MAKE) )
	@echo "making $(MODULE) debug modules"
	@for i in ${MOD_WORKSPACE} ; \
		do (cd $$i; $(MAKE) "CC = $(CC)" $$i.o); done;
	@echo ld -r ~~~ -o sm_client.o
	ld -r $(SM_CLIENT_O_FILES) -o sm_client.o
	@echo making libsm_client.a
	@$(MAKE) libsm_client.a.nodepend
	@$(MAKE) sm_client.h
	@$(MAKE) sm_staff.h
	@echo making shutserver
	@(cd ../admin; $(MAKE) "CC = $(CC)" $@)

shutserver: sm_client.o
	@(cd admin; $(MAKE) "CC = $(CC)" $@; )

sm_client.h: $(SM_H)
	@echo making sm_client.h
	@/bin/rm -f $@
	@echo "#ifndef _SM_CLIENT_H_" > $@
	@echo "#define _SM_CLIENT_H_" >> $@
	@echo "#include <stdio.h>" >> $@
	@echo "#include <setjmp.h>" >> $@
	@echo "#include <sys/types.h>" >> $@
	@echo "#include <netinet/in.h>" >> $@
	@awk '/BEGIN visible to user/,/END visible to user/' $(SM_H) >> $@
	@echo "#endif" >> $@

sm_staff.h: $(SM_H)
	@echo making sm_staff.h
	@/bin/rm -f $@
	@echo "#ifndef _SM_STAFF_H" > $@
	@echo "#define _SM_STAFF_H" >> $@
	@awk '/BEGIN visible to staff/,/END visible to staff/' $(SM_H) >> $@
	@echo "#endif" >> $@

sm_client.h.awk:
	@/bin/rm -f $@
	@echo "#Awk script to make sm.h" > $@
	@echo '$$0 ~ /BEGIN visible to user/, $$0 ~ /END visible to user/' >> $@

sm_Einterp.h: sm_Einterp.h.awk $(SM_H)
	/bin/rm -f $@
	@echo "#ifndef _SM_EINTERP_H_" > $@
	@echo "#define _SM_EINTERP_H_" >> $@
	@echo "#include <stdio.h>" >> $@
	@echo "#include <setjmp.h>" >> $@
	@echo "#include <sys/types.h>" >> $@
	@echo "#include <netinet/in.h>" >> $@
	awk -f sm_Einterp.h.awk $(SM_H) >> $@
	@echo "#endif" >> $@

sm_Einterp.h.awk:
	/bin/rm -f $@
	echo "#Awk script to make sm.h" > $@
	echo '$$0 ~ /BEGIN visible to user/, $$0 ~ /END visible to user/' >> $@
	echo '$$0 ~ /BEGIN visible to E/, $$0 ~ /END visible to E/' >> $@

link load loadall: libsm_client.a.nodepend
#	@echo ld -r ~~~ -o sm_client.o
#	@ld -r $(OFILES) $(PATHTOROOT)/common/common.o -o sm_client.o

depend: localdepend

localdepend:
	/bin/rm makefile.depend
	touch makefile.depend
	for i in `echo $(MOD_WORKSPACE)`;\
		do\
			echo "libsm_client.a:	$$i/$$i.o" >> makefile.depend;\
			echo "$$i/$$i.o:; cd $$i; \$$(MAKE) workspace.mod" >> makefile.depend;\
			done;


include makefile.depend
