Skip to content

Instantly share code, notes, and snippets.

@wvovaw
Last active May 7, 2021 15:56
Show Gist options
  • Save wvovaw/e2295d1f07ed3520f815a5854750dfa6 to your computer and use it in GitHub Desktop.
Save wvovaw/e2295d1f07ed3520f815a5854750dfa6 to your computer and use it in GitHub Desktop.
Makefile for small C++ projects
# Add name of the program as target
TARGET = out
CXX = g++
# Add libs
LIBS = -lm
CPPFLAGS = -std=c++17 -pedantic -Wall -Wno-deprecated-declarations -Os
OBJS = $(patsubst %.cpp, %.o, $(wildcard *.cpp))
INCS = $(wildcard *.h)
all : options ${TARGET}
debug: CPPFLAGS += -g -DDEBUG
debug: options ${TARGET}
%.o: %.c $(INCS)
$(CXX) $(CPPFLAGS) -c $< -o $@
.PRECIOUS: $(TARGET) $(OBJS)
$(TARGET) : $(OBJS)
$(CXX) $(OBJS) -Wall $(LIBS) -o $@
options:
@echo "----- Build options -----"
@echo "CPPFLAGS = ${CPPFLAGS}"
@echo "CXX = ${CXX}"
@echo "INCS = ${INCS}"
@echo "LIBS = ${LIBS}"
@echo "OBJS = ${OBJS}"
@echo "-------------------------"
clean:
-rm -f *.o
-rm -f $(TARGET)
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment