Last active
May 7, 2021 15:56
-
-
Save wvovaw/e2295d1f07ed3520f815a5854750dfa6 to your computer and use it in GitHub Desktop.
Makefile for small C++ projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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