I have the following makefile
# project name (generate executable with this name)
TARGET = tp3
CC = gcc -std=c99 -c
# compiling flags here
CFLAGS = -Wall -I. -Werror-implicit-function-declaration
LINKER = gcc -o
# linking flags here
LFLAGS = -Wall
# debug flags here
DFLAGS = -g -DDEBUG
SOURCES := $(shell find . -type f -name '*.c')
INCLUDES := $(shell find . -type f -name '*.h')
OBJECTS := $(SOURCES:.c=.o)
rm = rm -rf
$(TARGET): obj
@$(LINKER) $(TARGET) $(LFLAGS) $(OBJECTS)
@echo "Linking complete!"
obj: $(SOURCES) $(INCLUDES)
@$(CC) $(CFLAGS) -DNDEBUG $(SOURCES)
@echo "Compilation complete!"
#debug:
# gcc $(DFLAGS) $(SOURCES) -o $(TARGET)
dobj: $(SOURCES) $(INCLUDES)
@$(CC) $(CFLAGS) $(DFLAGS) $(SOURCES)
@echo "dlinking complete!"
debug: dobj
@$(LINKER) $(TARGET) $(LFLAGS) $(DFLAGS) $(OBJECTS) -o $(TARGET)
@echo "dcompilation complete!"
run:
./tp3
clean:
@$(rm) $(TARGET) $(OBJECTS) *.dSYM
@echo "Cleanup complete!"
Problem is: I have files inside the folder CMM/CMM and OBJECTS assumes the objects to also be in the CMM/CMM folder, but the compiler is putting them in the root folder. How can I either get the compiler to compile the .o files in CMM/CMM or tell the pattern replacer OBJECTS := $(SOURCES:.c=.o) that everything is in the root folder?
makeinvocation (something like$(MAKE) -C $(dir)rule). Certainly you could make appropriate changes to your central Makefile and define additional rules to compile certain source files into a chosen location.