
#-- start of constituents_header ------

include ${CMTROOT}/src/Makefile.core

ifdef tag
CMTEXTRATAGS = $(tag)
else
tag       = $(CMTCONFIG)
endif

tags      = $(tag),$(CMTEXTRATAGS)

${PACKAGE}_tag = $(tag)

ifdef READONLY
cmt_local_tagfile = /tmp/CMT_$(${PACKAGE}_tag).make$(cmt_lock_pid)
else
cmt_local_tagfile = $(${PACKAGE}_tag).make
endif

-include $(cmt_local_tagfile)

ifdef READONLY
cmt_local_setup = /tmp/CMT_${PACKAGE}setup$(cmt_lock_pid).make
cmt_final_setup = /tmp/CMT_${PACKAGE}setup.make
else
cmt_local_setup = $(bin)${PACKAGE}setup$(cmt_lock_pid).make
cmt_final_setup = $(bin)${PACKAGE}setup.make
endif

#--------------------------------------------------------

##cmt_lock_setup = /tmp/lock$(cmt_lock_pid).make
cmt_temp_tag = /tmp/tag$(cmt_lock_pid).make

first :: $(cmt_local_tagfile)
	@echo $(cmt_local_tagfile) ok

##	@bin=`$(cmtexe) -quiet show macro_value bin`

$(cmt_local_tagfile) : ##$(cmt_lock_setup)
	@/bin/echo "------> (constituents.make) Rebuilding setup.make $(cmt_local_tagfile)"
	@if test -f $(cmt_local_tagfile); then /bin/rm -f $(cmt_local_tagfile); fi
	@$(cmtexe) -quiet -tag=$(tags) build tag_makefile >$(cmt_temp_tag)
	@mv $(cmt_temp_tag) $(cmt_local_tagfile)
	@bin=$(bin); \
	  if test ! -d $${bin} ; then $(mkdir) -p $${bin} ; fi; \
	  echo CMTCONFIG=$(CMTCONFIG); \
	  if test -f $(cmt_local_setup); then /bin/rm -f $(cmt_local_setup); fi; \
	  cmt_local_setup=$${bin}${PACKAGE}setup$(cmt_lock_pid).make; \
	  cmt_final_setup=$${bin}${PACKAGE}setup.make; \
	  trap '/bin/rm -f $${cmt_local_setup}' 0 1 2 15; \
	  $(cmtexe) -quiet -tag=$(tags) show setup >>$${cmt_local_setup}; \
	  if test ! -f $${cmt_final_setup}; then \
	    mv $${cmt_local_setup} $${cmt_final_setup}; \
	  else \
	    if /usr/bin/diff $${cmt_local_setup} $${cmt_final_setup} >/dev/null ; then \
	      echo "$${cmt_final_setup} untouched "; \
	    else \
	      mv $${cmt_local_setup} $${cmt_final_setup}; \
	    fi; \
	  fi
	@/bin/echo setup.make ok

config :: ## checkuses
	@exit 0

env.make ::
	printenv >env.make.tmp; $(cmtexe) -quiet check files env.make.tmp env.make

all :: build_library_links
	@echo "------> (constituents.make) all done"

javadirs ::
	@if test ! -d $(javabin) ; then $(mkdir) -p $(javabin) ; fi

srcdirs ::
	@if test ! -d $(src) ; then $(mkdir) -p $(src) ; fi

dirs ::
	@if test ! -r requirements ; then echo "No requirements file" ; fi; \
	  if test ! -d $(bin) ; then $(mkdir) -p $(bin) ; fi

build_library_links : dirs requirements
	@echo "------> (constituents.make) Rebuilding library links"; \
	if test ! -d $(bin) ; then $(mkdir) -p $(bin) ; fi; \
	$(build_library_links)

.DEFAULT ::

#	@if test "$@" = "$(cmt_lock_setup)"; then \
#	  /bin/rm -f $(cmt_lock_setup); \
#	  touch $(cmt_lock_setup); \
#	fi

#-- end of constituents_header ------
