There are a few different questions already related to what I'm trying to do, such as this, this, and this. However, I've looked at what is there and what they link to and I'm still not able to get it to work.
I have the following make file (I had some help with this here). It builds .os in a build directory from .cpps in a source directory. I want to adjust this so that if the headers are updated, then it properly re-compiles those so I don't have to make clean
the whole thing (most particularly the ones from the INC_DIR1
folder).
CC = g++
CFLAGS = -g -Wall
INC_DIR1 = include
INC_DIR2 = C:/CPPFiles/CPP_Extra_Libraries/armadillo-4.200.0/include
INC_DIR = $(INC_DIR1) $(INC_DIR2)
INCLUDES = $(foreach d, $(INC_DIR), -I$d)
BUILD_DIR = build
SRC_DIR = test
SRC = $(wildcard */*.cpp)
VPATH = $(SRC_DIR)
OBJS = $(addprefix $(BUILD_DIR)/, $(notdir $(SRC:.cpp=.o)))
MAIN = armadillo_extra_functions_test
.PHONY: depend clean
all: $(BUILD_DIR) $(MAIN)
@echo compilation complete
$(BUILD_DIR):
mkdir -p $@
$(BUILD_DIR)/%.o: %.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS)
clean:
$(RM) *.o *~ $(MAIN) $(BUILD_DIR)/*.o
depend: $(SRC)
makedepend $(INCLUDES) $^
The latest thing I tried was to remove the depend
and makedepend
statements and then replace the $(BUILD_DIR/%.o: %.cpp
statement with
DEPS = $(patsubst %.o, %.d, $(OBJS))
-include $(DEPS)
$(BUILD_DIR)/%.o: %.cpp
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
$(CC) -c $(CFLAGS) -MMD $< > $(DEPS)
Without the last line of these adjustments, the make file runs, though it will not update headers. However, when I add in the last line I get an error about the $(BUILD_DIR)/%.d
files not being there.