0

I am trying to write a make file that compiles all of my C files under the source directory into the same file structure in /build/obj

For example one of my c files might be /source/foo/bar.c

And I want that to compile and be put in /build/obj/foo/bar.o

Here is what I've got so far while I was experimenting:

FILES = $(shell find source/ -type f -name '*.c')
OBJS = $(patsubst $(SOURCE)/%.c,$(OBJ)/%.o, $(FILES))

all: build/obj/foo/bar.o
    echo "DONE"

%.o:
    echo $(patsubst build/obj, source, $@)

However the patsubst function doesn't seem to be working with the automatic variable $@, instead I get "build/obj/foo/bar.o".

Is there a reason why automatic variables don't work with functions in make? If so how do I fix it?

1

1 Answer 1

3

patsubst does nothing without a pattern, try $(patsubst build/obj/%,source/%,$@)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.