Something went wrong. Try again.
Java--'s containers projects.intra.42.fr/projects/cpp-module-09
Something went wrong. Try again.
cpp_module_09 Makefile
8.2 kB · 213 lines
Makefile
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214############################################################################################### ## /$$$$$$ /$$ /$$ /$$ ## /$$__ $$ | $$$ /$$$ | $$ ## | $$ \__/ /$$$$$$ /$$$$$$$$ /$$ /$$ | $$$$ /$$$$ /$$$$$$ | $$ /$$ /$$$$$$ ## | $$ /$$__ $$|____ /$$/| $$ | $$ | $$ $$/$$ $$ |____ $$| $$ /$$/ /$$__ $$ ## | $$ | $$ \ $$ /$$$$/ | $$ | $$ | $$ $$$| $$ /$$$$$$$| $$$$$$/ | $$$$$$$$ ## | $$ $$| $$ | $$ /$$__/ | $$ | $$ | $$\ $ | $$ /$$__ $$| $$_ $$ | $$_____/ ## | $$$$$$/| $$$$$$/ /$$$$$$$$| $$$$$$$ | $$ \/ | $$| $$$$$$$| $$ \ $$| $$$$$$$ ## \______/ \______/ |________/ \____ $$ |__/ |__/ \_______/|__/ \__/ \_______/ ## /$$ | $$ ## ))) | $$$$$$/ Version 2.3.0 ## ((( \______/ ## +-----+ __..--''``---....___ _..._ __ ## | |] / // // // /// //_.-' .-/"; ` ``<._ ``.''_ `. / // / ## `-----' // // /// /// ///_.-' _..--.'_ \ `( ) ) // // ## / / // / /// / /// / (_..-' // (< _ ;_..__ ; `' / /// ## /// // / / // /// / / // // // `-._,_)' // / ``--...____..-' /// / // ## / // / /// // /// / / // // // /// // / /// // // /// / / /// / / /// // ###############################################################################################MAKEFLAGS += --no-print-directory
NAME =
_NAME_GOALS := $(or $(MAKECMDGOALS),all)_NAME_REQUIRED_TARGETS := all bonus debug sane re clean fcleanifneq ($(filter $(_NAME_REQUIRED_TARGETS),$(_NAME_GOALS)),)ifeq ($(NAME),)$(error NAME is not set)endifendif
ifndef IN_NIX_DEVELOP
BARE_GOALS := clean clean_self fclean helpNIX_GOALS := $(filter-out $(BARE_GOALS),$(or $(MAKECMDGOALS),all))
.PHONY: $(or $(MAKECMDGOALS),all) _nix_develop
$(filter $(BARE_GOALS),$(MAKECMDGOALS)): @$(MAKE) IN_NIX_DEVELOP=1 $@
ifneq ($(NIX_GOALS),)$(NIX_GOALS): _nix_develop @:_nix_develop: @nix develop --option warn-dirty false --quiet --command $(MAKE) $(NIX_GOALS)endif
else
MAKEFLAGS += -j$(shell nproc).PHONY: all bonus debug clean clean_self fclean re sane help version scan
MAKE_MODE ?= releaseMAKE_MODE_STAMP = obj/.mode_$(MAKE_MODE)LAST_MODE := $(or $(firstword $(patsubst obj/.mode_%,%,$(wildcard obj/.mode_*))),release)
# ColorsESC := $(shell printf '\033')GREEN = $(ESC)[32mBLUE = $(ESC)[34mRED = $(ESC)[31mRESET = $(ESC)[0m
# CompilerBASE_FLAGS = \ -Wall -Wextra -std=c++98 \ -Werror=vla -pedantic-errors -fstrict-flex-arrays=3 -Werror=int-conversion -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-cast -Wconversion \ -MMD -MP \ -flto=thinRELEASE_FLAGS = \ -Werror \ -O3 -march=nativeDEBUG_FLAGS = \ -gfull -O1 -fno-builtin -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -DDEBUG=trueSANE_FLAGS = \ -fsanitize=address,pointer-compare,pointer-subtract,leak,undefined,shift,shift-exponent,shift-base,integer-divide-by-zero,unreachable,vla-bound,null,signed-integer-overflow,bounds,alignment,float-divide-by-zero,float-cast-overflow,nonnull-attribute,returns-nonnull-attribute,bool,enum,pointer-overflow,builtin -fsanitize-address-use-after-scopeSCAN_BUILD_ARGS = \ -no-failure-reports -maxloop 128 -enable-checker nullability.NullableDereferenced -enable-checker nullability.NullablePassedToNonnull -enable-checker nullability.NullableReturnedFromNonnull -enable-checker optin.core.EnumCastOutOfRange -enable-checker optin.cplusplus.UninitializedObject -enable-checker optin.cplusplus.VirtualCall -enable-checker optin.performance.GCDAntipattern -enable-checker optin.performance.Padding -enable-checker optin.portability.UnixAPI -enable-checker optin.taint.GenericTaint -enable-checker optin.taint.TaintedAlloc -enable-checker optin.taint.TaintedDiv -enable-checker security.ArrayBound -enable-checker security.FloatLoopCounter -enable-checker security.PointerSub -enable-checker security.PutenvStackArray -enable-checker security.cert.env.InvalidPtr -enable-checker security.insecureAPI.DeprecatedOrUnsafeBufferHandling -enable-checker security.insecureAPI.strcpy -enable-checker valist.CopyToSelf -enable-checker valist.Uninitialized -enable-checker valist.Unterminated
# LibrariesLIB_DIRS =LIB_FILES =LDFLAGS = -fuse-ld=mold
# DirectoriesSRC = srcOBJ = obj/$(MAKE_MODE)INCLUDES = -Iinclude -Isrc $(foreach lib,$(LIB_DIRS),-I$(lib)/include)
# SourcesSRC_FILES := \ main.cpp
SRC_EXT := $(firstword $(sort $(suffix $(SRC_FILES))))ifneq ($(words $(sort $(suffix $(SRC_FILES)))),1) $(error Mixed source extensions are not supported: $(sort $(suffix $(SRC_FILES))))endififeq ($(SRC_EXT),.cpp) COMPILER = c++ BASE_FLAGS += -std=c++98else ifeq ($(SRC_EXT),.c) COMPILER = ccelse $(error Unsupported source extension: $(SRC_EXT) (expected .c or .cpp))endif
SRCS := $(addprefix $(SRC)/,$(SRC_FILES))OBJS := $(patsubst $(SRC)/%$(SRC_EXT),$(OBJ)/%.o,$(SRCS))DEPS := $(OBJS:.o=.d)
ifeq ($(MAKE_MODE),release) CFLAGS = $(BASE_FLAGS) $(RELEASE_FLAGS) LIB_TARGET = allelse ifeq ($(MAKE_MODE),debug) CFLAGS = $(BASE_FLAGS) $(DEBUG_FLAGS) LIB_TARGET = debug else ifeq ($(MAKE_MODE),sane) CFLAGS = $(BASE_FLAGS) $(DEBUG_FLAGS) $(SANE_FLAGS) LIB_TARGET = sane else $(error Unknown mode) endif endifendif
all: $(NAME) compile_commands.json
compile_commands.json: $(OBJS) @echo "$(BLUE)Generating compile_commands.json$(RESET)" @sed -e '1s/^/[/' -e '$$s/,$$/]/' $(OBJS:.o=.o.json) > $@
bonus: all
debug: @$(MAKE) MAKE_MODE=debug
sane: @$(MAKE) MAKE_MODE=sane
scan: @scan-build $(SCAN_BUILD_ARGS) $(MAKE) re
$(OBJ)/%.o: $(SRC)/%$(SRC_EXT) @mkdir -p $(@D) @echo "$(BLUE)Compiling$(RESET) $<..." @$(COMPILER) $(CFLAGS) $(INCLUDES) -MJ $@.json -c $< -o $@
libs: @set -e; \ for lib in $(LIB_DIRS); do \ echo "$(BLUE)Building $$lib in $(MAKE_MODE) mode...$(RESET)"; \ if [ "$(LIB_TARGET)" = "sane" ] && [ "$$lib" != "libft" ]; then \ $(MAKE) -C $$lib debug; \ else \ $(MAKE) -C $$lib $(LIB_TARGET); \ fi; \ done
$(MAKE_MODE_STAMP): @echo "$(GREEN)Building in $(MAKE_MODE) mode$(RESET)" @rm -f obj/.mode_* @mkdir -p obj @touch $@
$(NAME): $(MAKE_MODE_STAMP) $(OBJS) | libs @echo "$(GREEN)Linking$(RESET) $@..." @$(COMPILER) $(CFLAGS) $(OBJS) $(LIB_FILES) -o $@ $(LDFLAGS) @echo "$(GREEN)Successfully compiled $(NAME)!$(RESET)"
clean_self: @echo "$(RED)Cleaning$(RESET) $(NAME)'s object files..." @rm -rf obj
clean: clean_self @for lib in $(LIB_DIRS); do \ $(MAKE) -s -C $$lib clean; \ done
fclean: clean_self @echo "$(RED)Removing$(RESET) $(NAME)..." @rm -f $(NAME) @echo "$(RED)Removing$(RESET) compile_commands.json..." @rm -f compile_commands.json @for lib in $(LIB_DIRS); do \ $(MAKE) -s -C $$lib fclean; \ done
re: fclean @$(MAKE) MAKE_MODE=$(if $(filter command line,$(origin MAKE_MODE)),$(MAKE_MODE),$(LAST_MODE))
version: @echo "$(RED)Cozy Make version:$(RESET) 2.3.0" @$(COMPILER) --version
help: @echo "$(GREEN)Available targets:$(RESET)" @echo " $(BLUE)all $(RESET)- Build in release mode (default)" @echo " $(BLUE)bonus $(RESET)- Build in release mode with bonus" @echo " $(BLUE)debug $(RESET)- Build with debug symbols" @echo " $(BLUE)sane $(RESET)- Build with sanitizers" @echo " $(BLUE)scan $(RESET)- Build with scan-build" @echo " $(BLUE)clean $(RESET)- Remove object files" @echo " $(BLUE)fclean $(RESET)- Remove all build artifacts" @echo " $(BLUE)re $(RESET)- Rebuild in the last used mode or release unless specified" @echo " $(BLUE)version $(RESET)- Prints the version of Cozy Make and the compiler"
-include $(DEPS)
endif