# *************************************************************************
# *                                                                       *
# *  Makefile for HeteroMPI library                                       *
# *                                                                       *
# *                                                                       *
# *  Copyright (c) 2002 Department of Computer Science,                   *
# *                     University College Dublin, Ireland.               *
# *                                                                       *
# *  All rights reserved. We assume no responsibility for the use         *
# *  or reliability of our software.                                      *
# *                                                                       *
# *************************************************************************

include ../HSLmake.inc

HMPI_HOME_DIR 	= $(HMPI_HOME)
CC_INCLUDES	= -I$(MPCHOME)/h -I$(MPIDIR)/include -I./include

all: build do_install

build: build_src build_tools

build_third_party_software:
	@echo "#############################################################"
	@echo "Building third-party software"
	@echo "#############################################################"
	(cd ./Third_Party_Software/metis-4.0 && $(MAKE))

build_src:
	(cd src/heterompi && $(MAKE))

build_tools:
	@echo "#############################################################"
	@echo "Building tools"
	@echo "#############################################################"
	(cd ./tools && $(MAKE))
	(cd ./scripts && ./print_hmpi_info_file hmpi_version_info && chmod a+x hmpi_version_info)

do_install: build_tree copy_elements create_soft_links copy_third_party_software

build_tree:
	@echo "#############################################################"
	@echo "Installing into directory $(HMPI_HOME_DIR)"
	@echo "#############################################################"
	-mkdir -p $(HMPI_HOME_DIR)/bin
	-mkdir -p $(HMPI_HOME_DIR)/include
	-mkdir -p $(HMPI_HOME_DIR)/h
	-mkdir -p $(HMPI_HOME_DIR)/scripts

copy_elements:
	-/bin/cp ./tools/create_hmpiload $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpiload $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpiclean $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpiclean_mpcload $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpiloadclean $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpiclean_mpctopo $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpitopoclean $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpiautorun $(HMPI_HOME_DIR)/bin
	-/bin/cp ./tools/hmpibcast $(HMPI_HOME_DIR)/bin
	-/bin/cp ./include/hmpi.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hdpi.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_err.h $(HMPI_HOME_DIR)/include/ 
	-/bin/cp ./include/hmpi_ops.h $(HMPI_HOME_DIR)/include/ 
	-/bin/cp ./include/hmpi_internal.h $(HMPI_HOME_DIR)/include/ 
	-/bin/cp ./include/hmpi_partitioning_internal.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_partitioning.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_partitioning_types.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_partitioning_sets.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_partitioning_trees.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_partitioning_matrices.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_partitioning_graphs.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi_partitioning_graphs_wrappers.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./include/hmpi.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hdpi.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_err.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_ops.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_internal.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning_internal.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning_types.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning_sets.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning_trees.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning_matrices.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning_graphs.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./include/hmpi_partitioning_graphs_wrappers.h $(HMPI_HOME_DIR)/h
	-/bin/cp ./scripts/hmpi_version_info $(HMPI_HOME_DIR)/scripts/

create_soft_links:
	-ln -sf $(MPCHOME)/bin/mpcc $(HMPI_HOME_DIR)/bin/hmpicc
	-ln -sf $(MPCHOME)/bin/mpcrun $(HMPI_HOME_DIR)/bin/hmpirun

copy_third_party_software:
	-/bin/cp ./Third_Party_Software/metis-4.0/Lib/metis.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./Third_Party_Software/hmetis-1.5/Lib/hmetis.h $(HMPI_HOME_DIR)/include/
	-/bin/cp ./Third_Party_Software/metis-4.0/Lib/metis.h $(HMPI_HOME_DIR)/h/
	-/bin/cp ./Third_Party_Software/hmetis-1.5/Lib/hmetis.h $(HMPI_HOME_DIR)/h/

clean:
	(cd src/heterompi && $(MAKE) clean)
	(cd tools && $(MAKE) clean)
	(cd ./Third_Party_Software/metis-4.0 && $(MAKE) realclean)
	(cd ./Third_Party_Software/metis-4.0/DummyLibSrc && $(MAKE) clean)
	(cd ./Third_Party_Software/hmetis-1.5/DummyLibSrc && $(MAKE) clean)

%.o: %.c
	$(CC) $(OPT) $(CC_INCLUDES) -c -o $@ $<
