#!/usr/bin/env gmake

#####################################################################
# PARPP3D++                                                         #
# A parallel 3D Navier-Stokes-solver.                               #
#                                                                   #
# PARALLEL VERSION OF PP3D                                          #
# FROM THE FINITE ELEMENT ANALYSIS & SOLUTION PACKAGE               #
# FEATFLOW (www.featflow.de)                                        #
#                                                                   #
# WRITTEN IN C++                                                    #
#                                                                   #
# Makefile for communication library, Version 2.0                   #
#                                                                   #
#####################################################################

# Location of parpp3d++
SRCDIR   = ..

include $(SRCDIR)/Makefile.inc

# List of all object files
OBJ = $(SRCLIST_COMTOOL:%.cc=$(OBJDIR)/%.o)

# Set additional include path
INC_ADD = -I$(COMTOOL) -I$(SRCDIR) -I$(LINLIB)


# default target: compile the library
default:        $(OBJDIR)/libcom.a

# 'make debug' will compile without optimisation and with debug symbols
debug:
	@$(MAKE) OPT=NO

lib:            $(OBJDIR)/libcom.a

libcom:         $(OBJDIR)/libcom.a

libcom.a:       $(OBJDIR)/libcom.a

$(OBJDIR)/libcom.a: $(OBJ)
	$(AR) $@ $(OBJ)
	$(RANLIB) $@

clean:          clean_lib

# Clean all object files for current architecture
clean_lib:
	-rm -f $(OBJ)
	-rm -f $(OBJDIR)/libcom.a

# Clean all object files for all architectures
purge:          clean
	-(cd $(dir $(OBJDIR)) && \
	    rm -f $(SRCLIST_COMTOOL:%.cc=*/%.o) \
		  $(SRCLIST_COMTOOL:%.cc=*/%.ti) */libcom.a )


# Dependencies of each object file
$(OBJDIR)/CComTool.o: \
	CComTool.cc CComTool.h $(SRCDIR)/coutput.h $(SRCDIR)/Errorcodes.h \
	$(SRCDIR)/Global.h $(SRCDIR)/MyTypes.h $(SRCDIR)/typecasts.h \
	$(HDRS_LINLIB)

$(OBJDIR)/MComTool.o: \
	MComTool.cc blist.h CComTool.h Const.h MComTool.h $(SRCDIR)/coutput.h \
	$(SRCDIR)/Errorcodes.h $(SRCDIR)/Global.h $(SRCDIR)/MyTypes.h \
	$(SRCDIR)/typecasts.h $(HDRS_LINLIB)

#$(OBJDIR)/PerformInfo.o: \
#       PerformInfo.cc PerformInfo.h $(SRCDIR)/MyTypes.h $(LINLIB)/DateTime.h \
#       $(LINLIB)/Output.h

$(OBJDIR)/blist.o: \
	blist.cc blist.h Const.h $(SRCDIR)/coutput.h $(SRCDIR)/Errorcodes.h \
	$(SRCDIR)/Global.h $(SRCDIR)/MyTypes.h $(SRCDIR)/typecasts.h \
	$(HDRS_LINLIB)

# Compile statement for each object file
$(OBJ):
	-@test -d $(OBJDIR) || mkdir -p $(OBJDIR)
	$(CPP) $(DEFINES) $(CFLAGSCPP) $(INC_ADD) $(INC) -c $< -o $@

# For explanation of phony targets see
# http://www.gnu.org/software/make/manual/html_mono/make.html#SEC41
.PHONY: default lib libcom libcom.a clean clean_lib purge
