Skip to content

Instantly share code, notes, and snippets.

@fresc81
Created November 21, 2017 20:19
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 fresc81/db578991c91129703cb166f20db533ed to your computer and use it in GitHub Desktop.
Save fresc81/db578991c91129703cb166f20db533ed to your computer and use it in GitHub Desktop.
Generic C++ Makefile with support for multiple executables
APPS := nmdbg bla
nmdbg_OBJS := blubb.o
nmdbg_LIBS := -lboost_regex
bla_OBJS := blubb.o
CXX := g++-6
CXXFLAGS := -I3rdparty/json/src -Iinclude -Isrc
LD := g++-6
LDFLAGS := -Llib
LIBS := -lboost_filesystem -lboost_system
.PHONY: all clean
all:: bin/ build/ $(addprefix bin/,$(APPS))
@printf '\033[32mbuilt all\033[0m\n'
clean:
@printf '\033[31mcleaning\033[0m\n'
rm -rf bin build
bin/:
@printf '\033[36mcreating $@\033[0m\n'
mkdir bin
build/:
@printf '\033[36mcreating $@\033[0m\n'
mkdir build
build/%.o: src/%.cpp
@printf '\033[33mcompiling $@ from $^\033[0m\n'
$(CXX) -std=c++11 $(CXXFLAGS) -c $< -o $@
.SECONDEXPANSION:
.SECONDARY: build/%.o
.PRECIOUS: build/%.o bin/%
bin/%: build/%.o $$(addprefix build/,$$($$*_OBJS))
@printf '\033[1;35mlinking $@ from $^\033[0m\n'
$(LD) -std=c++11 $(LDFLAGS) $^ $($*_LIBS) $(LIBS) -o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment