I'm trying to create a makefile that will find all existing .c and .cpp files then compile them.
I have used How to place object files in separate subdirectory as a template and combined it with How to make a makefile for C and C++, with sources in subdirectories. Assume I have defined all the variables (I just left them out since they are unnecessary).
The error I keep getting is make: *** No rule to make target 'obj/<randoCfile>.c', needed by '<target>'. Stop.
SOURCES := $(call rwildcard,$(SRCDIR),*.c)
SOURCES += $(call rwildcard,$(SRCDIR),*.cpp)
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:%.c=%.c.o))
OBJECTS += $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:%.cpp=%.cpp.o))
#Default Make
all: $(TARGET)
#Remake
remake: cleaner all
#Make the Directories
directories:
@mkdir -p $(TARGETDIR)
@mkdir -p $(BUILDDIR)
#Clean only Objecst
clean:
@$(RM) -rf $(BUILDDIR)
#Full Clean, Objects and Binaries
cleaner: clean
@$(RM) -rf $(TARGETDIR)
#Link
$(TARGET): $(OBJECTS)
$(CC) -o $(TARGETDIR)/$(TARGET) $^ $(LIB)
$(BUILDDIR)/%.c.o:
$(CC) $(INC) $(CFLAGS) -c -o $@ $<
$(BUILDDIR)/%.cpp.o:
$(CXX) $(INC) $(CXXFLAGS) -c -o $@ $<
#Non-File Targets
.PHONY: all remake clean cleaner resources
Any suggestions as to how to fix my problem?
I'm running on Windows (which is why I'm using a wildcard as opposed to the shell(find...)
that was in one of the examples I found.