Create a gist now

Instantly share code, notes, and snippets.

@pallas /Makefile
Last active Aug 23, 2017

What would you like to do?
Basic Makefile template
default: all
DEBUG ?= -g -ggdb -DDEBUG
ifeq ($(DEBUG),)
override DEBUG := -DNDEBUG
endif
override LDFLAGS += -lstdc++
override CFLAGS += $(DEBUG) -MD -MP
override CXXFLAGS += $(DEBUG) -MD -MP
PROGRAMS := \
test \
#
COMMON := \
#
DEPENDS = $(PROGRAMS:=.d) $(COMMON:=.d)
-include $(DEPENDS)
OBJECTS = $(PROGRAMS:=.o) $(COMMON:=.o)
$(PROGRAMS) : %: %.o $(COMMON:=.o)
.PHONY: all
all: $(PROGRAMS)
.PHONY: clean
clean:
rm -rf $(PROGRAMS) $(OBJECTS) $(DEPENDS)
$(PROGRAMS) $(OBJECTS): | $(filter clean,$(MAKECMDGOALS))
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment