sk0102 sk0102 - 2 months ago 8
Linux Question

Dynamic get C file in Makefile

I'am trying to create a Makefile that has a target in src folder, but my target .c file is generated by script.

I am trying to use wildcard or %.c to get all generated .c file, but it always return empty string.

obj: GEN_C
$(CC) -c $(wildcard src/*.c)

GEN_C:
generate_c.sh


I get to know other project makefile that get dynamic file use $($(CC_FILES).c=.o), but in this case i don't know which name .c will be generated.

thanks.

Answer

Why do you use the wildcard function?

Delay the evaluation by using the wildcard in the shell.

obj: GEN_C
    $(CC) -c src/*.c

GEN_C:
    generate_c.sh
Comments