I have a makefile that compiles all the cpp files in the src folder. All of the cpp files are dependent on their .h files. So I have one rule to do all of that (I think).
But I want to remove the main.cpp from that list of source files, since it does not have a corresponding header file.
I have code that removes the main from the list of cpp files. Then I wrote a separate rule for compiling the main. I think this is where I have gone wrong.
Here is the makefile and the error.
CC := g++
CFLAGS := -g -O2
BIN_DIR := bin
BUILD_DIR := build
SRC_DIR := src
TARGET := wavfiletool.exe
MAIN := WavFileTool
SOURCES := $(wildcard src/*.cpp)
SOURCES := $(filter-out src/$(MAIN).cpp, $(SOURCES))
OBJECTS := $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
$(BIN_DIR)/$(TARGET): $(MAIN).o $(OBJECTS)
$(CC) $(OBJECTS) $(CFLAGS) -o $@
$(MAIN).o: $(MAIN).cpp
$(CC) $(CFLAGS) -c $(MAIN).cpp -o $(MAIN).o
$(OBJECTS): $(BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp : $(SRC_DIR)/%.h
@$(CC) $(CFLAGS) -c $< -o $@
ERROR:
make: Circular WavFileTool <- WavFileTool dependency dropped.
EDIT: When I remove the $(MAIN).o dependency from the target line, the error goes away.