Sources :=	$(wildcard *.[ch]pp)
CPPFiles :=	$(wildcard *.cpp)
Objects :=	$(patsubst %.cpp,%.o,$(CPPFiles))
Target :=	${patsubst %.cpp,%,${shell grep -l '\<main *(' $(CPPFiles)}}

CC :=		mpic++
CXX :=		mpic++
CXXFLAGS :=	-g -Ofast -std=c++11 -Wno-literal-suffix
CPPFLAGS :=	-std=c++11
LDFLAGS :=	-std=c++11
LDLIBS :=	-lgmp

.PHONY:		all depend clean realclean
all:		Makefile $(Target)
depend: ;	gcc-makedepend $(CPPFLAGS) $(CPPFiles)
Makefile:	$(Sources)
		gcc-makedepend $(CPPFLAGS) $(CPPFiles)
clean: ;	rm -f $(Objects)
realclean:	clean
		rm -f $(Target)

$(Target):	$(Objects)
		$(CXX) -o $@ $(LDFLAGS) $(Objects) $(LOADLIBES) $(LDLIBS)

# DO NOT DELETE
primes.o: primes.cpp primes.hpp
mpi-primes.o: mpi-primes.cpp primes.hpp integer.hpp
