I have a makefile.
I need to build a set of targets under C:/bin/ from the source files under src1 and src2.
let them be required in the order say
${DEST_DIR}/a.o ${DEST_DIR}/b.o ${DEST_DIR}/c.o ${DEST_DIR}/d.o
in some part of makefile
DEST_DIR = C:/bin
SRC_DIR1 = C:/src1
SRC_DIR2 = C:/src2
and i've the rules for them as follows
#rule#1
${DEST_DIR}/%.o : ${SRC_DIR1}/%.c
#the command required to build the target
echo "Source: $< Target: $@ "
#rule#2
${DEST_DIR}/%.o : ${SRC_DIR2}/%.c
#the command required to build the target
echo "Source: $< Target: $@ "
Let a.c and b.c are in SRC_DIR1 and c.c and d.c are in SRC_DIR2
When I build it builds fine going to rule#1 for a.o and b.o, then rule#2 for c.o and d.o
I didn't expect it'd be fine. Because I was expecting it to go for rule#1 for c.o and throw an error saying "no rule to make target c.c". But it goes for rule#2 and builds c.o from c.c in SRC_DIR2.
Can someone explain me how it works? How does the wild card character %
work in this case and how rule matching occurs?