4
\$\begingroup\$

Considering the following Makefile:

%.o: %.cpp
    $(C) $(CF) -c $< -o $@

Audio/%.o: Audio/%.cpp
    $(C) $(CF) -c $< -o $@

Game/%.o: Game/%.cpp
    $(C) $(CF) -c $< -o $@

Generation/%.o: Generation/%.cpp
    $(C) $(CF) -c $< -o $@

Input/%.o: Input/%.cpp
    $(C) $(CF) -c $< -o $@

Particle/%.o: Particle/%.cpp
    $(C) $(CF) -c $< -o $@

Screen/%.o: Screen/%.cpp
    $(C) $(CF) -c $< -o $@

Utility/%.o: Utility/%.cpp
    $(C) $(CF) -c $< -o $@

How can I simplify it so that it only depends on a list of directories, such as:

SUBD = Audio/\
 Game/\
 Generation/\
 Input/\
 Particle/\
 Screen/\
 Utility/
\$\endgroup\$
3
\$\begingroup\$

All of these rules

Audio/%.o: Audio/%.cpp
        $(C) $(CF) -c $< -o $@

# etc.

are redundant! Your first pattern rule

%.o: %.cpp
        $(C) $(CF) -c $< -o $@

already covers them all.

\$\endgroup\$
  • \$\begingroup\$ So my first rule covers all the subdirectories as well? (and sub-sub directories)? \$\endgroup\$ – Shoe Oct 4 '13 at 17:51
  • \$\begingroup\$ Yes. If Audio/a/b/c/something.cpp exists, then it will use the first rule to make Audio/a/b/c/something.o if it needs Audio/a/b/c/something.o. \$\endgroup\$ – 200_success Oct 4 '13 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.