I am not entirely sure if what I am doing is possible in make, but I will give it a go.
So normally I can have a pattern matching rule like so
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
and if my understanding is correct, each target, like obj/file.o
will be paired (depend on) with its respective prerequisite src/file.c
.
Now, in my situation, I have a lot of nested directories under my src directory. So I was able to make/find a recursive command such that I can group all the source files together. An example looks like
SOURCES := [src/main.c src/dir1/a.c src/dir2/b.c]
and using the pattern substitution I was able to get a list of all the object files (without their nested directories) in the object directory like so
OBJECTS := [obj/main.o obj/a.o obj/b.o]
My problem is, I want a similar pattern rule like my first pattern where I can somehow say
obj/main.o depends on src/main.c
obj/a.o depends on src/dir1/a.c
...
and not have to write out all the targets and prerequisites explicitly.
Is this type of pattern matching possible in make?
This may be a duplicate, but I had an issue trying to articulate my problem while searching, so apologies in advance.