
cflags    = $(CFLAGS)
cppflags  = $(CFLAGS)
fflags    = $(CFLAGS)

cc        = cc
ccomp     = $(cc)  -c -I$(inc) $(cflags)
clink     = $(cc)

cpp       = g++
cppcomp   = $(cpp) -c -I$(inc) $(cppflags)
cpplink   = $(cpp)

for       = f77
fcomp     = $(for) -c -I$(inc) $(fflags)
flink     = $(for)

lexflags  =
lex       = lex $(lexflags)

yaccflags =
yacc      = yacc $(yaccflags)

mkdir     = mkdir

comp      = $(ccomp)
link      = $(cc)

ar        = ar -crl
ranlib    = ranlib

tag       = $(CMTCONFIG)

src       = ../src/
inc       = ../src/
mgr       = ../mgr/
cmt       = ../cmt/
bin       = ../$(tag)/

build_strategy = rebuild_makefiles
build_dependencies = echo


#---------------------------------------------
# Controlling the verbosity of Make
#

ifdef QUIET
LEX_QUIET = 1
YACC_QUIET = 1
C_QUIET = 1
CPP_QUIET = 1
FORTRAN_QUIET = 1
JAVA_QUIET = 1
LINK_QUIET = 1
LIB_QUIET = 1
CLEANUP_QUIET = 1
silent = @
echo = @/bin/echo 
else
silent =
echo = @- echo 
endif

ifdef LEX_QUIET
lex_silent = @
lex_echo = @/bin/echo rebuilding 
else
lex_silent =
lex_echo = $(echo)
endif

ifdef YACC_QUIET
yacc_silent = @
yacc_echo = @/bin/echo rebuilding 
else
yacc_silent =
yacc_echo = $(echo)
endif

ifdef C_QUIET
c_silent = @
c_echo = @/bin/echo rebuilding 
else
c_silent =
c_echo = $(echo)
endif

ifdef CPP_QUIET
cpp_silent = @
cpp_echo = @/bin/echo rebuilding 
else
cpp_silent =
cpp_echo = $(echo)
endif

ifdef FORTRAN_QUIET
fortran_silent = @
fortran_echo = @/bin/echo rebuilding 
else
fortran_silent =
fortran_echo = $(echo)
endif

ifdef JAVA_QUIET
java_silent = @
java_echo = @/bin/echo rebuilding 
else
java_silent =
java_echo = $(echo)
endif

ifdef LINK_QUIET
link_silent = @
link_echo = @/bin/echo rebuilding 
else
link_silent =
link_echo = $(echo)
endif

ifdef LIB_QUIET
lib_silent = @
lib_echo = @/bin/echo rebuilding 
else
lib_silent =
lib_echo = $(echo)
endif

ifdef CLEANUP_QUIET
cleanup_silent = @
cleanup_echo = @/bin/echo removing 
else
cleanup_silent =
cleanup_echo = $(echo)
endif

cmtexe = $(CMTROOT)/$(CMTBIN)/cmt.exe

SHELL     = /bin/sh

all :: setup.make checkuses

##	@if [ ! "`${CMTROOT}/mgr/cmt show uses | grep 'found'`" = "" ] ; then \

checkuses :
	@if test "$(build_strategy)" = "rebuild_makefiles"; then \
	  echo "Checking configuration"; \
	  a=`${CMTROOT}/mgr/cmt show strategies | grep keep_makefiles`; \
	  if test "$${a}" = ""; then \
	    /bin/rm -f constituents.make setup.make $(tag).make; \
	  fi; \
	  $(cmtexe) check configuration -tag=$(tag); \
	  touch checkuses; \
	fi

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

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

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

cmt_path.make :: checkuses
	@if test "$(build_strategy)" = "rebuild_makefiles"; then \
	  echo "Rebuilding $@"; \
	  /bin/rm -f cmt_path.make; echo '#'`$(cmtexe) show path -tag=$(tag) -quiet` >cmt_path.make; \
	fi

###	  $(cmtexe) check_files cmt_path.make.tmp cmt_path.make;

-include cmt_path.make

setup.make : cmt_path.make requirements # $(CMTROOT)/mgr/cmt
	@if test "$(build_strategy)" = "rebuild_makefiles"; then \
	  echo "Rebuilding $@"; \
	  $(cmtexe) build make_setup -tag=$(tag) ; \
	fi

-include setup.make

$(gmake_hosts) ::
	rsh $@ "sh -c '(cd `$(cmtexe) show pwd`; . setup.sh; gmake $(MAKEFLAGS) $(target))'"

$(make_hosts) ::
	rsh $@ "sh -c '(cd `$(cmtexe) show pwd`; . setup.sh; make $(MAKEFLAGS) $(target))'"

everywhere :: $(everywhere)

clean :: checkuses

##	@echo clean done

check ::
	@echo check done

help :: dirs setup.make
	@echo '--------------------------------------------------------------------------'
	@echo 'You may select one of the following make targets :'
	@echo ' '
	@echo 'help        : this help'
	@echo 'all         : rebuild everything according to the $$(constituents) macro'
	@echo '              (this is the default target)'
	@echo 'clean       : remove everything that can be rebuilt'
	@echo 'configclean : remove configuration files (*.make)'
	@echo ' '
	@groups=`$(cmtexe) show groups`; \
	  echo "all $${groups} : "
	@echo '              rebuild all constituents of one of these groups'
	@echo ' '
	@all=""; \
	  for c in `$(cmtexe) show constituent_names` ; do \
	    if test ! "$${all}" = ""; then all="$${all} "; fi; \
	    all="$${all}$${c}" ; \
	  done; \
	  echo "$${all} : "
	@echo '              rebuild one of these constituents'
	@echo ' '
	@echo 'check :'
	@echo '              run all applications defined with the -check option'
	@echo ' '
	@echo 'everywhere [target=...] : '
	@echo '              o Rebuild on all plateforms specified in the $$(everywhere) macro'
	@echo '              o Use "cmt show macro everywhere -tag=<site>" to check it'
	@echo '              o The "target" option permits to transmit a target to the remote site'

always ::

#constituents.make : requirements
#	@$(CMTROOT)/mgr/cmt build constituents_makefile

#include constituents.make

.DEFAULT ::
	@echo "No action for $@"

