# Generated automatically from Makefile.in by configure.
# top level makefile for p4

P4ARCH = LINUX
MAKE   = make --no-print-directory

SHELL=/bin/sh

top_srcdir  = /usr/rels/mpich-1.2.0/mpid/ch_p4/p4
srcdir      = /usr/rels/mpich-1.2.0/mpid/ch_p4/p4
libbuild_dir = /usr/rels/mpich-1.2.0/lib

MFLAGS = 
#MFLAGS = -i    # for alliant fx/8
  
P4_DIRS = lib alog usc include bin servers 

EXAMPLES_DIRS = contrib messages monitors

ALL_DIRS = $(P4_DIRS) $(EXAMPLES_DIRS) \
           lib_f messages_f contrib_f doc usc/usctest misc

DIRS = $(ALL_DIRS)

RM = /bin/rm

all:
	@echo making p4 on architecture=$(P4ARCH)
#	@$(MAKE) makefiles P4ARCH=$(P4ARCH)
	@$(MAKE) $(MFLAGS) links P4ARCH=$(P4ARCH)
	@for dir in $(DIRS) ;\
	  do \
	  echo " " ;\
	  echo making p4 in directory $$dir ;\
	  (cd $$dir; $(MAKE) $(MFLAGS) default) ;\
	  done 

p4:
	@echo making p4 on architecture=$(P4ARCH)
	@$(MAKE) makefiles P4ARCH=$(P4ARCH)
	@$(MAKE) $(MFLAGS) links P4ARCH=$(P4ARCH)
	@for dir in $(P4_DIRS) ;\
	  do \
	  echo " " ;\
	  echo making p4 in directory $$dir ;\
	  (cd $$dir; $(MAKE) $(MFLAGS) default) ;\
	  done 

#
# Make sure the MAKE is the last statement in the (cd xxx; make) to ensure
# that an error causes the make to abort right there
# The following code duplicates part of the build and creates an unnecessary 
# libp4 in a local directory.
#	@for dir in $(P4_DIRS) ;\
#	  do \
#	  echo " " ;\
#	  echo making p4 in directory $$dir ;\
#	  (cd $$dir; $(MAKE) $(MFLAGS) default) ;\
#	  done 
p4inmpi: 
	@echo making p4 on architecture=$(P4ARCH)
	@$(MAKE) $(MFLAGS) p4links P4ARCH=$(P4ARCH)
	(cd lib;  $(MAKE) $(MFLAGS) MPIARCH=$(MPIARCH) \
		MPILIBNAME=$(MPILIBNAME) p4inmpi)
	(cd alog; $(MAKE) $(MFLAGS) MPIARCH=$(MPIARCH) \
		MPILIBNAME=$(MPILIBNAME) p4inmpi)
	(cd usc;  $(MAKE) $(MFLAGS) MPIARCH=$(MPIARCH) \
		MPILIBNAME=$(MPILIBNAME) p4inmpi)

p4links:
#	@if [ -f lib/p4_config.h ] ;\
#	then\
#	    true ;\
#	else\
#	    make config_hdr P4ARCH=$(P4ARCH) ;\
#	fi
	@if [ -f include/alog.h ] ;\
	then\
	    true ;\
	else\
	    (cd include ;\
	    ln -s ${top_srcdir}/alog/alog.h . ;\
	    ln -s ${top_srcdir}/alog/alog_evntdfs.h . ;\
	    ) ;\
	fi
	@if [ -f include/usc.h ] ;\
	then\
	    true ;\
	else\
	    (cd include ;\
	    ln -s ${top_srcdir}/usc/usc.h . ;\
	    ln -s ${top_srcdir}/usc/usc_sys.h . ;\
	    ) ;\
	fi
	@if [ -f include/p4.h ] ;\
	then\
	    true ;\
	else\
	    (cd include ;\
	    ln -s ${top_srcdir}/lib/p4.h . ;\
	    ln -s ${top_srcdir}/lib/p4_MD.h . ;\
	    ln -s ${top_srcdir}/lib/p4_defs.h . ;\
	    ln -s ${top_srcdir}/lib/p4_funcs.h . ;\
	    ln -s ${top_srcdir}/lib/p4_globals.h . ;\
	    ln -s ${top_srcdir}/lib/p4_macros.h . ;\
	    ln -s ${top_srcdir}/lib/p4_mon.h . ;\
	    ln -s ${top_srcdir}/lib/p4_patchlevel.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sock_util.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sr.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sys.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sys_funcs.h . ;\
	    ln -s ${top_srcdir}/lib/sfcdchi.h . ;\
	    ln -s ../p4_config.h . ;\
	    ) ;\
	fi

links:
	@if [ -f include/alog.h ] ;\
	then\
	    true ;\
	else\
	    (cd include ;\
	    ln -s ${top_srcdir}/alog/alog.h . ;\
	    ln -s ${top_srcdir}/alog/alog_evntdfs.h . ;\
	    ) ;\
	fi
	@if [ -f include/usc.h ] ;\
	then\
	    true ;\
	else\
	    (cd include ;\
	    ln -s ${top_srcdir}/usc/usc.h . ;\
	    ln -s ${top_srcdir}/usc/usc_sys.h . ;\
	    ) ;\
	fi
	@if [ -f include/p4.h ] ;\
	then\
	    true ;\
	else\
	    (cd include ;\
	    ln -s ${top_srcdir}/lib/p4.h . ;\
	    ln -s ${top_srcdir}/lib/p4_MD.h . ;\
	    ln -s ${top_srcdir}/lib/p4_defs.h . ;\
	    ln -s ${top_srcdir}/lib/p4_funcs.h . ;\
	    ln -s ${top_srcdir}/lib/p4_globals.h . ;\
	    ln -s ${top_srcdir}/lib/p4_macros.h . ;\
	    ln -s ${top_srcdir}/lib/p4_mon.h . ;\
	    ln -s ${top_srcdir}/lib/p4_patchlevel.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sock_util.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sr.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sys.h . ;\
	    ln -s ${top_srcdir}/lib/p4_sys_funcs.h . ;\
	    ln -s ${top_srcdir}/lib/sfcdchi.h . ;\
	    ln -s ${top_srcdir}/p4_config.h . ;\
	    ) ;\
	fi
	@if [ -f messages_f/p4f.h ] ;\
	then\
		true ;\
	else\
		(cd messages_f; ln -s ${top_srcdir}/lib_f/p4f.h . ; cd ..) ;\
	fi
	@if [ -f contrib_f/p4f.h ] ;\
	then\
		true ;\
	else\
		(cd contrib_f; ln -s ${top_srcdir}/lib_f/p4f.h . ; cd ..) ;\
	fi


clean:  
	@for dir in $(DIRS) ;\
	  do \
	  echo cleaning $$dir ;\
	  (cd $$dir; $(MAKE) clean) ;\
	  done
	$(RM) -f *~ *.o *.bak

dist:	realclean   

realclean:
	@for dir in $(DIRS) ;\
	  do \
	  if test -s $$dir/Makefile ; then \
	  echo cleaning $$dir ;\
	  (cd $$dir; $(MAKE) realclean) ; fi ;\
	  done
	$(RM) -f *~ *.o *.bak Makefile mdepcflags

Makefiles: makefiles

INSTALLDIR = ./$(P4ARCH)
install:
	@echo installing p4 in $(INSTALLDIR)
	@if [ -d $(INSTALLDIR) ] ;\
	then\
	    echo 'using existing directory $(INSTALLDIR)' ;\
	else\
	    mkdir $(INSTALLDIR) ;\
	fi
	@cp Makefile $(INSTALLDIR)
##	@mkdir $(INSTALLDIR)/util
##	@cp util/* $(INSTALLDIR)/util
	@mkdir $(INSTALLDIR)/include
	@cp include/*.h $(INSTALLDIR)/include
	@mkdir $(INSTALLDIR)/lib
	@cp lib/libp4.a $(INSTALLDIR)/lib
	@grep RANLIB util/defs.MD > $(INSTALLDIR)/lib/makeranlib
	@echo "doran:" >> $(INSTALLDIR)/lib/makeranlib
	@echo '	$$(RANLIB) libp4.a' >> $(INSTALLDIR)/lib/makeranlib
	@(cd  $(INSTALLDIR)/lib; $(MAKE) -f makeranlib doran; $(RM) makeranlib)
	@mkdir $(INSTALLDIR)/bin
	@cp bin/* $(INSTALLDIR)/bin
	@mkdir $(INSTALLDIR)/examples
	@cp messages/sr_test.c messages/sr_user.h  \
	  messages/systest.c messages/makefile.proto \
	  messages/run_ipsc messages/run_ncube messages/run_delta \
	  messages/sr_test.pg messages/systest.pg $(INSTALLDIR)/examples
	@sed -e "s@P4_HOME_DIR = ..@P4_HOME_DIR = $(INSTALLDIR)@" \
	  $(INSTALLDIR)/examples/makefile.proto >  $(INSTALLDIR)/temp
	@mv $(INSTALLDIR)/temp  $(INSTALLDIR)/examples/makefile.proto
	@$(MAKE) makefiles DIRS=$(INSTALLDIR)/examples
	@(cd $(INSTALLDIR)/examples; $(MAKE) sr_test systest)
	@mkdir $(INSTALLDIR)/lib_f
	@cp lib_f/libp4_f.a lib_f/*.h $(INSTALLDIR)/lib_f
	@grep RANLIB util/defs.MD > $(INSTALLDIR)/lib_f/makeranlib
	@echo "doran:" >> $(INSTALLDIR)/lib_f/makeranlib
	@echo '	$$(RANLIB) libp4_f.a' >> $(INSTALLDIR)/lib_f/makeranlib
	@(cd  $(INSTALLDIR)/lib_f; $(MAKE) -f makeranlib doran; $(RM) makeranlib)
	@mkdir $(INSTALLDIR)/examples_f
	@cp messages_f/sr_test.f messages_f/p4f.h  \
	  messages_f/makefile.proto \
	  messages_f/sr_test.pg $(INSTALLDIR)/examples_f
	@sed -e "s@P4_HOME_DIR = ..@P4_HOME_DIR = $(INSTALLDIR)@" \
	  $(INSTALLDIR)/examples_f/makefile.proto >  $(INSTALLDIR)/temp
	@mv $(INSTALLDIR)/temp  $(INSTALLDIR)/examples_f/makefile.proto
	@$(MAKE) makefiles DIRS=$(INSTALLDIR)/examples_f
	@(cd $(INSTALLDIR)/examples_f; $(MAKE) sr_test)
	@echo installed p4 in $(INSTALLDIR)
