Last active
January 6, 2020 01:04
-
-
Save Airtnp/17db85424628e1c1a484b220737ba902 to your computer and use it in GitHub Desktop.
More general Makefile example
This file contains 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
PATH := $(PATH) | |
LIBRARY_PATH := $(LIBRARY_PATH) | |
LD_LIBRARY_PATH := $(LD_LIBRARY_PATH) | |
LD_RUN_PATH := $(LD_RUN_PATH) | |
TESTSRCS = $(wildcard test*.cpp) | |
PROJSRCS = $(wildcard project*.cpp) | |
SRCS = $(wildcard *.cpp) | |
SRCS = $(filter-out $(TESTSRCS), $(SRCS)) | |
OBJS = $(SRCS:%.cpp=%.o) | |
TARGETS = | |
TESTS = | |
ZIPFILES = $(SRCS) Makefile | |
ZIPFILENAME = submit.tar.gz | |
CC = gcc | |
CCSTD = -std=c99 | |
CCWFLAGS = -Wall -Wextra -Wshadow -Wpedantic --pedantic-errors -O2 $(CCSTD) | |
CCNFLAGS = -Wno-unused-value -Wno-unused-parameter -Wno-attributes -Wno-unused-variable | |
CCGDBFLAGS = -g | |
CCFLAGS = $(CCWFLAGS) $(CCNFLAGS) $(CCGDBFLAGS) | |
CXX = g++ | |
CXXSTD = -std=c++17 | |
CXXOPFLAGS = -Ofast -DNDEBUG \ | |
-march=native \ | |
-fwhole-program -flto \ | |
-fprefetch-loop-arrays \ | |
-Wno-coverage-mismatch \ | |
-fno-rtti \ | |
-fomit-frame-pointer \ | |
-falign-functions=16 -falign-loops=16 \ | |
-funsafe-loop-optimizations \ | |
-ffast-math -fno-stack-protector \ | |
CXXWFLAGS = -Wall -Wextra -Wshadow -Wpedantic --pedantic-errors | |
CXXADWFLAGS = -Wduplicated-cond -Wduplicated-branches \ | |
-Wlogical-op -Wnull-deference -Wold-style-cast \ | |
-Wuseless-cast -Wjump-misses-init \ | |
-Wdoule-promotion -Wformat=2 | |
# GCC7: -Wrestrict | |
CXXNFLAGS = -Wno-unused-value -Wno-unused-parameter -Wno-attributes -Wno-unused-variable | |
CXXSANFLAGS = -fsanitize=undefined,address,leak,bounds,bool,enum | |
CXXDBFLAGS = -g3 -Og -DDEBUG | |
CXXFLAGS = $(CXXWFLAGS) $(CXXNFLAGS) $(CXXSTD) | |
INCLUDES = | |
LDFLAGS = | |
LIBS = | |
RM = rm -fv | |
release: CXXFLAGS += $(CXXOPFLAGS) -fprofile-use | |
release: clean all | |
prerelease: CXXFLAGS += -O3 -DNDEBUG | |
prerelease: all | |
debug: EXECUTABLE := $(DEBUG) | |
debug: CXXFLAGS += $(CXXDBFLAGS) | |
debug: clean all | |
profile: CXXFLAGS += $(CXXOPFLAGS) -fprofile-generate | |
profile: clean all | |
all: $(TARGETS) | |
$(TARGETS): $(OBJS) | |
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(TARGETS) $(OBJS) $(LDFLAGS) $(LIBS) | |
$(OBJS) : $(SRCS) | |
$(CXX) $(CXXFLAGS) -c $** | |
.PHONY: all release debug profile clean alltests zip | |
.SUFFIXES: | |
zip: | |
rm -f $(ZIPFILES) | |
dos2unix $(ZIPFILES) | |
tar -vcz $(ZIPFILES) -f $(ZIPFILENAME) | |
clean: | |
$(RM) $(OBJS) $(TARGETS) $(TESTS) | |
distclean: clean | |
$(RM) $(TARGETS) | |
alltests: clean $(TESTS) | |
%.o: %.cpp | |
$(CXX) $(CXXFLAGS) -c $*.cpp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment