I am working on creating a Makefile for my ProjectEuler solutions. I need to compile each solution into a separate binary for personal timing purposes. Is it possible to pass the name of the rule to the -o option to remove some repeated code?
CXX = g++
CXXFLAGS = -std=c++0x
INC = -Iinclude/ -I../tools/
binaries=01sum35\
02evenfibs\
03largestprimefactor\
04largestpallyproduct\
05smallestmultiple\
06sumsquaredifference\
07tenthousandfirstprime\
08largestproductinseries\
09specialpythagtriplet
all: $(binaries)
01sum35:
$(CXX) $(CXXFLAGS) 01sum35.cc $(INC) -o 01sum35
02evenfibs:
$(CXX) $(CXXFLAGS) 02evenfibs.cc $(INC) -o 02evenfibs
03largestprimefactor:
$(CXX) $(CXXFLAGS) 03largestprimefactor.cc $(INC) -o 03largestprimefactor
04largestpallyproduct:
$(CXX) $(CXXFLAGS) 04largestpallyproduct.cc ../tools/tools.cc $(INC) -o 04largestpallyproduct
05smallestmultiple:
$(CXX) $(CXXFLAGS) 05smallestmultiple.cc $(INC) -o 05smallestmultiple
06sumsquaredifference:
$(CXX) $(CXXFLAGS) 06sumsquaredifference.cc $(INC) -o 06sumsquaredifference
07tenthousandfirstprime:
$(CXX) $(CXXFLAGS) 07tenthousandfirstprime.cc ../tools/tools.cc $(INC) -o 07tenthousandfirstprime
08largestproductinseries:
$(CXX) $(CXXFLAGS) 08largestproductinseries.cc ../tools/tools.cc $(INC) -o 08largestproductinseries
09specialpythagtriplet:
$(CXX) $(CXXFLAGS) 09specialpythagtriplet.cc $(INC) -o 09specialpythagtriplet
clean:
rm -f $(binaries)