I would like the following makefile to be capable of compiling multiple executables:
CXX = clang++
CXXFLAGS = -g -Wall --std=c++11
OBJS = two_rung.o three_rung.o dumbinterp.o interp.o writeLadderMPO.o
PROG = two_rung three_rung dumbinterp interp
SOURCES = two_rung.cc three_rung.cc dumbinterp.cc interp.cc writeLadderMPO.cc
HEADS = writeLadderMPO.h
INCLUDES = -I $(HOME)/ITensor
LIBS = -L $(HOME)/ITensor/lib -litensor -lstdc++ -framework Accelerate
all: $(PROG)
$(PROG): $(OBJS)
$(CXX) $(INCLUDES) -o $(PROG) $(OBJS) $(LIBS)
%.o: %.cc $(HEADS)
$(CXX) $(INCLUDES) -c -o $(OBJS) $(SOURCES)
The executables are denoted by PROG. When I try to make one of these executables, for example interp, I get instead
Computer:folder username$ make interp
clang++ -I /Users/username/ITensor -c -o two_rung.o three_rung.o dumbinterp.o interp.o writeLadderMPO.o two_rung.cc three_rung.cc dumbinterp.cc interp.cc writeLadderMPO.cc
Which is to say, Make is just tossing all the files in when I call them as variables, which totally makes perfect sense. But I want it to behave like:
clang++ -I /Users/username/ITensor -c -o interp.o interp.cc
and then
clang++ -I /Users/username/ITensor -o interp interp.o -L $(HOME)/ITensor/lib -litensor -lstdc++ -framework Accelerate
How do I get Make to do this? Thanks!
makeuse implicit rules for that. Just addINCLUDEStoCXXFLAGSandmakeshould do the right thing (which you don't do).