Created
March 30, 2019 14:16
-
-
Save OrangeTide/a09a8572e9d1260dac945536d509125c to your computer and use it in GitHub Desktop.
Primitive modular Makefile
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
all :: | |
clean :: ; $(RM) $(TARGETS) $(foreach t,$(TARGETS),$(OBJS_$t)) | |
.PHONY : all clean | |
## Configuration | |
CFLAGS = -Wall -W -O2 -g | |
# a really aggressive strip-all for ARM | |
STRIP = strip -s -w -R .comment\* -R .note\* -R .gnu.hash -R .ARM.exidx -R .ARM.attributes | |
## Rules | |
%.o : %.c | |
$(COMPILE.c) $(if $(PKGS),$(shell pkg-config --cflags $(PKGS))) $(OUTPUT_OPTION) $< | |
% : %.o | |
$(LINK.o) $(if $(PKGS),$(shell pkg-config --libs $(PKGS))) $^ $(LOADLIBES) $(LDLIBS) -o $@ | |
$(STRIP) $@ | |
% : %.c | |
$(LINK.c) $(if $(PKGS),$(shell pkg-config --cflags --libs $(PKGS))) $^ $(LOADLIBES) $(LDLIBS) -o $@ | |
$(STRIP) $@ | |
# each project is defined by a .mk file | |
include $(wildcard *.mk) | |
# establish default rule | |
all :: $(TARGETS) |
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
TARGETS += hello | |
OBJS_hello = hello.o util.o | |
hello : $(OBJS_hello) | |
hello : PKGS += x11 xext | |
hello : LDLIBS += -lm | |
TARGET += testprog | |
OBJS_testprog = testprog.o util.o | |
testprog : $(OBJS_testprog) | |
testprog : CFLAGS += -DTESTMODE=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment