Created
October 9, 2012 12:14
-
-
Save aprell/3858449 to your computer and use it in GitHub Desktop.
Makefile rule generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rule generation | |
# Project must define PROGS, SRCS, and *_SRCS to specify targets and prerequisites | |
OBJS = $(SRCS:.c=.o) | |
define RULE_template | |
$(1): $$($(subst -,_,$(1))_SRCS:.c=.o) $$($(subst -,_,$(1))_PREREQS) | |
$$(CC) -o $$@ $$(filter %.o,$$^) $$(LDFLAGS) $$(IMPORTS) $$($(subst -,_,$(1))_LIBS:%=-l%) | |
endef | |
# Default clean target | |
define RULE_clean | |
clean: | |
rm -f $(1) $$(OBJS) $$(DEPS) | |
endef | |
all: $(PROGS) | |
$(foreach prog,$(PROGS),$(eval $(call RULE_template,$(prog)))) | |
$(eval $(call RULE_clean,$(PROGS))) | |
.PHONY: all clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment