Skip to content

Instantly share code, notes, and snippets.

@pallas
Last active August 23, 2017 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pallas/9984634 to your computer and use it in GitHub Desktop.
Save pallas/9984634 to your computer and use it in GitHub Desktop.
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