I am trying to compile a c program with gnu make, so that the objective files created are put in a Build directory. My project directory look like this:
| root
|--> makefile
|--> BuildDir
|--> HeadersDir
| -> main.h
| .
| .
|--> Modules
| -> modules1.c
| .
| .
|--> Program
| -> program1.c
| .
| .
And I want all objective files created from Modules and Program source files to get saved inside BuildDir. So far I have this makefile
CC = gcc
CFLAGS = -Wall -Wextra -g3 -I./HeaderFiles
LDFLAGS = -lm
# Get all source files
SRCFILES := $(wildcard ./Programs/*.c)
SRCFILES += $(wildcard ./Modules/*.c)
# Generate objective files
OBJFILES = $(patsubst %.c, %.o, $(SRCFILES))
OBJFILES := $(subst ./Programs, ./Build, $(OBJFILES))
OBJFILES := $(subst ./Modules, ./Build, $(OBJFILES))
EXEC = travelMonitor
PARAMETERS =
all: $(OBJFILES) $(EXEC)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(EXEC): $(OBJFILES)
$(CC) $(CFLAGS) $(OBJFILES) -o $@
and that outputs:
make: *** No rule to make target 'Build/mainFunctions.o', needed by 'all'. Stop.
Can anyone help?