Skip to content

Instantly share code, notes, and snippets.

@zeux
Created February 9, 2014 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeux/8906196 to your computer and use it in GitHub Desktop.
Save zeux/8906196 to your computer and use it in GitHub Desktop.
Create folders for output files using things you can learn from 'man make'
# Before
$(BUILD)/%.o: %
@mkdir -p $(dir $@)
$(CXX) $< $(CXXFLAGS) -MMD -MP -o $@
-include $(OBJECTS:.o=.d)
# After
.SECONDEXPANSION:
%/.sentinel:
mkdir -p $(dir $@)
@touch $@
$(OBJECTS): $(BUILD)/%.o: % $$(dir $$@).sentinel
$(CXX) $< $(CXXFLAGS) -MMD -MP -o $@
-include $(OBJECTS:.o=.d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment