# Generic C and C++ Makefile project template # Contains targets for `release', `debug', and `clean'. PROJECT=naka DESCRIPTION=Find a file within another file(s) AUTHOR=Avril (Flanchan) LICENSE=GPL3+ VERSION_MAJ=0 VERSION_MIN=0 VERSION_BF=0 VERSION_REV=0 VERSION:=$(VERSION_MAJ).$(VERSION_MIN).$(VERSION_BF).$(VERSION_REV) COMP_TIME:=$(shell date -u +%s) SRC_C = $(wildcard src/*.c) $(wildcard src/tests/*.c) SRC_CXX = $(wildcard src/*.cpp) INCLUDE=include # Set compile-time features # # Available features # * PARALLEL - Enable multithreaded processing (currently unimplemented.) FEATURES?= META_FLAGS:=-D_PROJECT_AUTHOR="\"$(AUTHOR)\"" -D_PROJECT_DESCRIPTION="\"$(DESCRIPTION)\"" -D_PROJECT_NAME="\"$(PROJECT)\"" \ -D_PROJECT_LICENSE="\"$(LICENSE)\"" \ -D_VERSION_MAJOR=$(VERSION_MAJ) -D_VERSION_MINOR=$(VERSION_MIN) \ -D_VERSION_BUGFIX=$(VERSION_BF) -D_VERSION_REVISION=$(VERSION_REV) \ -D_PROJECT_COMPILED=$(COMP_TIME) COMMON_FLAGS+= -W -Wall -fno-strict-aliasing $(addprefix -I,$(INCLUDE)) $(META_FLAGS) $(addprefix -D_FEATURE_,$(FEATURES)) ARCH?=native OPT_FLAGS+= -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \ -floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \ -fno-stack-check CXX_OPT_FLAGS+= $(OPT_FLAGS) -felide-constructors CFLAGS += $(COMMON_FLAGS) --std=gnu11 CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 -fno-exceptions LDFLAGS += STRIP=strip RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS) $(addprefix -march=,$(ARCH)) RELEASE_CXXFLAGS?= -O3 -flto $(CXX_OPT_FLAGS) $(addprefix -march=,$(ARCH)) RELEASE_LDFLAGS?= -O3 -flto DEBUG_CFLAGS?= -O0 -g -DDEBUG DEBUG_CXXFLAGS?= $(DEBUG_CFLAGS) DEBUG_LDFLAGS?= # Objects OBJ_C = $(addprefix obj/c/,$(SRC_C:.c=.o)) OBJ_CXX = $(addprefix obj/cxx/,$(SRC_CXX:.cpp=.o)) OBJ = $(OBJ_C) $(OBJ_CXX) # Phonies .PHONY: release release: | dirs $(PROJECT)-release .PHONY: debug debug: | dirs $(PROJECT)-debug # Targets dirs: @mkdir -p obj/c{,xx}/src{,/tests} obj/c/%.o: %.c $(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS) obj/cxx/%.o: %.cpp $(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS) $(PROJECT)-release: CFLAGS+= $(RELEASE_CFLAGS) $(PROJECT)-release: CXXFLAGS += $(RELEASE_CXXFLAGS) $(PROJECT)-release: LDFLAGS += $(RELEASE_LDFLAGS) $(PROJECT)-release: $(OBJ) $(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS) $(STRIP) $@ $(PROJECT)-debug: CFLAGS+= $(DEBUG_CFLAGS) $(PROJECT)-debug: CXXFLAGS += $(DEBUG_CXXFLAGS) $(PROJECT)-debug: LDFLAGS += $(DEBUG_LDFLAGS) $(PROJECT)-debug: $(OBJ) $(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS) clean-rebuild: rm -rf obj clean: clean-rebuild rm -f $(PROJECT)-{release,debug,pgo}