snippetMinor
How do I simplify the following slice of a Makefile?
Viewed 0 times
themakefilefollowingsimplifyhowslice
Problem
Considering the following Makefile:
How can I simplify it so that it only depends on a list of directories, such as:
%.o: %.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
Audio/%.o: Audio/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
Game/%.o: Game/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
Generation/%.o: Generation/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
Input/%.o: Input/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
Particle/%.o: Particle/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
Screen/%.o: Screen/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
Utility/%.o: Utility/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -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/Solution
All of these rules
are redundant! Your first pattern rule
already covers them all.
Audio/%.o: Audio/%.cpp
$(C) $(CF) -c %%CODEBLOCK_0%%lt; -o $@
# etc.are redundant! Your first pattern rule
%.o: %.cpp
$(C) $(CF) -c %%CODEBLOCK_1%%lt; -o $@already covers them all.
Code Snippets
Audio/%.o: Audio/%.cpp
$(C) $(CF) -c $< -o $@
# etc.%.o: %.cpp
$(C) $(CF) -c $< -o $@Context
StackExchange Code Review Q#32249, answer score: 3
Revisions (0)
No revisions yet.