Please help with C++ Makefile and % Operator

M

matthias_k

Hello,

I am currently working on a Makefile mechanism which can for most
parts create dependencies automatically and look for sources in
other folders than "." .

As a basis, I have been adopting some mechanisms of the way the CDT
plugin for Eclipse handles this. However, at one point, I really don't
get what it's doing:

<snip>
# Makefile

[...]

-include $(SUBDIRS:%=%/subdir.mk)

[...]
</snip>


<snip>
# code is a subdir containing code
# code/subdir.mk

# Each subdirectory must supply rules for building sources it contributes
code/%.o: code/%.cpp
@echo 'Building file: $<'
$(CC) $(CFLAGS) -o $@ $< && \
echo -n $(@:%.o=%.d) '' > $(@:%.o=%.d) && \
$(CC) -MM -MG -P -w $(CFLAGS) $< >> $(@:%.o=%.d)
@echo 'Finished building: $<'
@echo ' '
</snip>

Okay, I know that in that include directive, all entries in SUBDIRS
are substituted in a way that "/subdir.mk" is attached to the end.
However my question is:
What does that mysterious % Operator do? I have searched the net with no
results. I have searched the bash manpage but it doesn't seem to be a
shell variable either.

Can you tell?

Thanks in advance,
- Matthias
 
V

Victor Bazarov

matthias_k said:
I am currently working on a Makefile mechanism which can for most
parts create dependencies automatically and look for sources in
other folders than "." .

[...]

Try gnu.utils.* or the newsgroup for your OS. Makefiles are OT here.
Thank you.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top