Skip to content

Instantly share code, notes, and snippets.

@keuv-grvl
Created January 27, 2017 13:07
Show Gist options
  • Save keuv-grvl/4cc561bdbeeea5cb748a6850fd8bd7f2 to your computer and use it in GitHub Desktop.
Save keuv-grvl/4cc561bdbeeea5cb748a6850fd8bd7f2 to your computer and use it in GitHub Desktop.
Generic make file to comple C++11 project
# Config
DEBUG := 0
BUILDDIR := build
SOURCEDIR := src
PREFIX :=
# End config
CXX := g++
CXXFLAGS := -fopenmp -MMD -Wall -Wextra -ansi -pedantic -std=c++11
LDFLAGS := -lpthread -lboost_system -fopenmp -Wl,-rpath=$(PREFIX)/lib/
INC := -I$(PREFIX)/include/ -I$(PREFIX)/
SOURCES := $(shell find $(SOURCEDIR) -name '*.cpp')
OBJECTS := $(SOURCES:%.cpp=$(BUILDDIR)/%.o)
EXECUTABLE:= myexec
ifneq ($(DEBUG),0)
CXXFLAGS += -g -O0
else
CXXFLAGS += -O3
endif
ifeq (${PREFIX},)
$(error Error: PREFIX is not defined (PREFIX=/path/to/dir/ make))
endif
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS)
$(BUILDDIR)/%.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INC) -o $@ -c $<
install: $(EXECUTABLE)
mkdir -p $(PREFIX)/bin/
cp $(EXECUTABLE) $(PREFIX)/bin/
clean:
rm -fr $(BUILDDIR) $(EXECUTABLE)
DEPS := $(OBJECTS:.o=.d)
-include $(DEPS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment