
MAKE   = @MAKE@
SHELL  = /bin/sh
RM     = /bin/rm
CP     = /bin/cp

NOF77             = @NOF77@
top_srcdir        = @top_srcdir@
srcdir            = @srcdir@

# Build directories
includebuild_dir  = @includebuild_dir@
libbuild_dir      = @libbuild_dir@
binbuild_dir      = @binbuild_dir@
sbinbuild_dir     = @sbinbuild_dir@

LOGVIEWERS        = @LOGVIEWERS@

@VPATH@

MPE_HEADERS = @MPE_HEADERS@

all: build_include build_libs_progs mpereconfig linktest_all logviewers

build_include:
	-@if [ -n "$(includebuild_dir)" ] ; then \
	      if [ ! -d $(includebuild_dir) ] ; then \
	          mkdir -p $(includebuild_dir) ; \
	      fi ; \
	      cd $(top_srcdir)/include ; \
	      for file in $(MPE_HEADERS) ; do \
	          if [ -f $$file -a ! -f $(includebuild_dir)/$$file ] ; then \
	              $(CP) $$file $(includebuild_dir) ; \
	          fi ; \
	      done ; \
	  fi

build_libs_progs:
	@( cd src ; $(MAKE) )

# If you change this, ALSO change it in the sbin/mpeinstall.in !
mpereconfig: ${top_srcdir}/bin/mpereconfig.in config.status
	-$(RM) -f ${binbuild_dir}/mpereconfig
	-$(RM) -f ${binbuild_dir}/mpereconfig.dat
	@cat ${top_srcdir}/bin/mpereconfig.in | \
	        sed -e "s%\#MPE_BUILD\#%$(libbuild_dir)/..%g" \
	            -e "s%\#PREFIX\#%$(prefix)%g" \
	            -e "s%\#top_srcdir\#%$(top_srcdir)%g" \
                    -e "s%\#bindir\#%$(bindir)%g" \
                    -e "s%\#binbuild_dir\#%$(binbuild_dir)%g" \
	        > ${binbuild_dir}/mpereconfig
	@chmod 775 ${binbuild_dir}/mpereconfig
	@sed -e 's%$$top_srcdir/$$file%$$file%g' \
	     -e 's%$$top_srcdir/$${file}%$${file}%g' \
	        config.status \
	     > ${binbuild_dir}/mpereconfig.dat
	@-chmod 775 ${binbuild_dir}/mpereconfig.dat

####### Linkage Tests
linktest_all: linktest_C linktest_f77

linktest_C:
	@( cd contrib/test; $(MAKE) linktest_C )

linktest_f77:
	@if [ $(NOF77) = 0 ] ; then \
	    ( cd contrib/test; $(MAKE) linktest_f77 ) \
	 fi
	@echo

#  For backward compatibility
linktest: linktest_C

#  For backward compatibility
fortran_test: linktest_f77
########

#  Tagets to build all log viewers, jumpshot-X ...  
logviewers:
	@-if [ -s ./viewers/Makefile -a "$(LOGVIEWERS)" = "1" ] ; then \
	      ( cd ./viewers ; $(MAKE) ) \
	  fi

install:
	@if [ -n "$(PREFIX)" ] ; then \
	     ./sbin/mpeinstall -prefix=$(PREFIX) ; \
	 else \
	     ./sbin/mpeinstall ; \
	 fi

uninstall:
	@./sbin/mpeuninstall

rmprog:
	@-$(RM) -f bin/mpereconfig bin/mpereconfig.dat

clean: rmprog
	@( cd src ; $(MAKE) clean )
	@-for dir in contrib/life contrib/mandel contrib/mastermind \
	             contrib/test share/examples ; do \
	      if [ -s $$dir/Makefile ] ; then \
	          ( cd $$dir ; $(MAKE) clean ) ; \
	      fi ; \
	  done

distclean: rmprog
	( cd src ; $(MAKE) distclean )
	@-for dir in contrib/life contrib/mandel contrib/mastermind \
	             contrib/test share/examples ; do \
	      if [ -s $$dir/Makefile ] ; then \
	          ( cd $$dir ; $(MAKE) distclean ) ; \
	      fi ; \
	  done
	@-$(RM) -f sbin/mpeinstall sbin/mpeuninstall
	@-$(RM) -f Makefile mpeconf.h config.log config.status

configure: configure.in aclocal.m4
	autoheader
	autoconf
