#
# $RCSfile: Makefile,v $ 
# $Revision: 1.61 $ $Date: 1993/05/05 21:28:02 $
#
#
# USE 
#	make -e 
# BASELINE MUST BE DEFINED in your environment!
# CC, LOCK, CFLAGS, DEBUG_FLAGS can also be taken from you environment.
#

# 
# BEGIN macros required by makefile.common
#
MODULE = src
PARENT = 
PATHTOROOT=.

RESULTS =  mksedscript
FILESC =  mksedscript.c
FILESO =  mksedscript.o
FILESH	=
SPECIALINCLUDE=
LOCALCLEANFILES= 
LOCALRCSFILES = structclass.awk mtags.csh
LOCK=-q

MAKEFILES = \
	Makefile \
	makefile.subdir.common makefile.common\
	makefile.install makefile.options makefile.tags \
	makefile.sed 

# no longer need this complex baseline stuff around here.
# LITTLEMAKEFILE=true

#
# MOD_BASELINE lists the modules you want to get from the baseline (in .o form)
#
MOD_BASELINE =

#
# MOD_WORKSPACE lists the modules you want fiddle with - get source, etc.
#  	Order is not really significant but recursive makes will address
#   the subdirectories in the order listed here, so it's only a matter
#	of personal preference...  any inter-directory dependencies cause
#	make to cd to prerequisite's directory and make the prerequisite. 
# NB: server and client depend on common, so common should be first in the
#	 list.
# NB: formatvolume depends on client so it should follow client in the list.
# NB: diskproc depends on server so it should follow server in the list.
#
# NB: *** If diskproc is in the workspace, serverlib must be also.
# ******* If serverlib is in the workspace, so must be diskproc,  formatvolume,
# ******* and server, an anything else that uses the library.
# ******* If client is in the workspace, so must be admin, and anything else
# ******* that uses the client library (libsm_client.a).
#
MOD_WORKSPACE = include common config client admin serverlib server formatvolume diskproc

OTHERTAGS=
LOCK=-q

#
# END macros required by makefile.common
#

# needed because mksedscript precedes makefile.common:
default: workspace.mod

#
# the next rule must preceed inclusion of makefile.common
#
mksedscript.orig:
	$(CC) $(CFLAGS) mksedscript.c -o mksedscript

include $(PATHTOROOT)/makefile.common

workspace workspace.1level: install_directories
install_directories:	$(BINDIR) $(LIBDIR) $(INCLUDEDIR)
$(BINDIR) $(LIBDIR) $(INCLUDEDIR):
	mkdir $@

install: 
	for i in `echo $(MOD_WORKSPACE) $(MOD_BASELINE)` ; \
		do (cd $$i; $(MAKE) install); done;

#
# Developers run binary_release to prepare binaries for a release
# shutserver and sm_server have to be re-made by the customer.
#
# For this purpose, we assume that the only things in $(LIBDIR),
# $(BINDIR) and $(INCLUDEDIR) are ours, and that the dirs are
# ../bin, ../lib, ../include.
# For customer purposes, they can be anything, including /bin, /lib, etc
# so targets that customers use had better explicitly reference the
# files that go in there (no $(BINDIR)/*, etc).
#
binary_release: br_part3 install br_part1 br_part2 br_part4 br_part5

br_part1:
#	 install was done; clean up extra copies 
	for i in `echo $(MOD_WORKSPACE) $(MOD_BASELINE)` ; \
		do (cd $$i; $(MAKE) cleaninstall); done;

br_part2:
#	 make the include files read-only
	-chmod -w $(INCLUDEDIR)/*.h

br_part3:
#	 make the necessary things writable
	chmod +w config/*.c
	chmod +w makefile.install
	chmod +w makefile.options
	cat makefile.options |\
		sed -e 's/^DEBUGFLAGS.*$$/DEBUGFLAGS = $(RELEASE_FLAGS)/' > tmp$$$$;\
	mv tmp$$$$ makefile.options

br_part4:
#	 blow away the old .sm_config in ../lib
#	 and get the latest one.
	-rm -f $(LIBDIR)/.sm_config
	cp ../tests/.sm_config $(LIBDIR)
	chmod +w $(LIBDIR)/.sm_config

br_part5:
#	 get rid of the binaries that the customer will have
#	 to re-make based on local config info.
	-rm -f $(BINDIR)/sm_server
	-rm -f $(BINDIR)/shutserver

#
# Customers use this to generate binaries from the libraries
# installed by "make binary_release"
#
binary_install: bi_part1 bi_part2 bi_part3 bi_part4 

bi_part1:
	(cd config; $(MAKE) )

bi_part2:
#	 replace config.o in the client library
#	 (not necessary in server lib)
	chmod +w $(LIBDIR)/libsm_client.a
	ar r $(LIBDIR)/libsm_client.a config/config.o
	ranlib $(LIBDIR)/libsm_client.a 
	chmod -w $(LIBDIR)/libsm_client.a

bi_part3:
#	 server/sm_server shouldn't be there, unless
#	 customer has explicitly re-made in there.
	-rm -f server/sm_server
	(cd server; make binary_install_exec)
#	 leave libsm_server.a in $(LIBDIR) so customer can
#	 change config and re-make binary_install.

bi_part4:
#	 admin/shutserver shouldn't be there, unless
#	 customer has explicitly re-made in there.
	-rm -f admin/shutserver
	(cd admin; make binary_install_exec)

#
#
# Get baseline in every module. The root has nothing of its own to get
# from the baseline.
getbaseline: $(MOD_BASELINE) $(MOD_WORKSPACE)
	for i in `echo $(MOD_BASELINE)`;\
		do (cd $$i; $(MAKE) getbaseline) ;done;
	for i in `echo $(MOD_WORKSPACE)`;\
		do (cd $$i; $(MAKE) getbaselineparts) ;done;


tags: tags.clean
tags.clean:
	for i in `echo $(MOD_WORKSPACE)`;\
		do (cd $$i; \
			mv tags tags.save;\
			rm -f `find . -type f -name "tags" -print`;\
			mv tags.save tags)  ; done;
	find . -name "tags.check" -exec rm -f {} \;

baseline.mod:
	for i in `echo $(MOD_WORKSPACE)`;\
		do (cd $$i; $(MAKE) baseline.mod); done;

source_release: br_part3

include makefile.depend
