# **************************************************************************** # # # # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # # Updated: 2024/02/15 17:58:38 by maiboyer ### ########.fr # # # # **************************************************************************** # define_module = $(addprefix $(1)/, $(2)) BUILD_DIR = build SRC_DIR = src INCLUDE_DIR = include LIBS_DIR = . GENERIC_DIR = GENERIC_INCLUDE = NAME = push_swap ifeq ($(MAKECMDGOALS), bonus) CFLAGS += -DBONUS=1 BUILD_DIR := $(BUILD_DIR)/bonus/ NAME = checker endif LIB_NAME ?= TARGET = $(NAME) CC ?= clang CFLAGS += -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -Wno-unused-command-line-argument -MMD BONUS_FILES = LIBS_NAME = SUBJECT_URL = 'https://cdn.intra.42.fr/pdf/pdf/118610/en.subject.pdf' GENERIC_FILES = SRC_FILES = \ app/actual_main \ app/best_index_to_move \ app/best_move \ app/do_move \ app/find_place \ app/iter_find \ app/main \ app/main_bonus \ app/moves \ app/moves/push \ app/moves/rev_rotate \ app/moves/rotate \ app/moves/swap \ app/rotate \ app/run_with_items \ app/sort2 \ app/sort3 \ app/sort5 \ app/state \ app/target \ bonus/move1 \ buffered_str/mod \ char/isalnum \ char/isalpha \ char/isascii \ char/isdigit \ char/islower \ char/isprint \ char/isspace \ char/isupper \ char/tolower \ char/toupper \ convert/atoi \ convert/itoa \ convert/str_to_i16 \ convert/str_to_i16_utils \ convert/str_to_i32 \ convert/str_to_i32_utils \ convert/str_to_i64 \ convert/str_to_i64_utils \ convert/str_to_i8 \ convert/str_to_i8_utils \ convert/str_to_u16 \ convert/str_to_u16_utils \ convert/str_to_u32 \ convert/str_to_u32_utils \ convert/str_to_u64 \ convert/str_to_u64_utils \ convert/str_to_u8 \ convert/str_to_u8_utils \ fs/close \ fs/open \ fs/putchar_fd \ fs/putendl_fd \ fs/putnbr_fd \ fs/putstr_fd \ fs/read \ fs/read_to_vec \ fs/write \ gnl/get_next_line \ hash/hasher \ hash/hash_signed \ hash/hash_unsigned \ hash/sip/sip13 \ hash/sip/sip_utils \ hash/sip/sip_utils2 \ img/qoi/qoi_decode \ img/qoi/qoi_encode \ img/qoi/qoi_fs \ img/qoi/qoi_utils \ list/list_add_back \ list/list_add_front \ list/list_alloc_node \ list/list_free_all \ list/list_free_one \ list/list_get_last \ list/list_iter \ list/list_map \ list/list_size \ mem/mem_alloc \ mem/mem_alloc_array \ mem/mem_compare \ mem/mem_copy \ mem/mem_find \ mem/mem_find_bytes \ mem/mem_move \ mem/mem_set \ mem/mem_set_zero \ num/u16/rotate \ num/u32/rotate \ num/u64/from_bytes \ num/u64/rotate \ num/u8/rotate \ num/usize/rotate \ printf/formatter/char \ printf/formatter/decimal \ printf/formatter/hex \ printf/formatter/oct \ printf/formatter/ptr \ printf/formatter/unsigned_decimal \ printf/formatter/utils \ printf/formatter/utils2 \ printf/formatter/utils3 \ printf/formatter/utils_numbers \ printf/matchers \ printf/printf \ printf/vprintf \ string/str_clone \ string/str_find_chr \ string/str_find_rev_chr \ string/str_find_str \ string/str_iter \ string/str_join \ string/str_l_cat \ string/str_l_copy \ string/str_len \ string/str_map \ string/str_n_compare \ string/str_n_find_str \ string/str_split \ string/str_substring \ string/str_trim \ vec/vec_buf_str \ vec/vec_buf_str_functions2 \ vec/vec_buf_str_functions3 \ vec/vec_i64 \ vec/vec_i64_bool \ vec/vec_i64_bool_functions2 \ vec/vec_i64_bool_functions3 \ vec/vec_i64_bool_sort \ vec/vec_i64_functions2 \ vec/vec_i64_functions3 \ vec/vec_i64_sort \ vec/vec_u8 \ vec/vec_u8_functions2 \ vec/vec_u8_functions3 BONUS = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(BONUS_FILES))) SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) \ $(addsuffix .c,$(addprefix $(GENERIC_DIR)/,$(GENERIC_FILES))) BONUS_OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(BONUS_FILES))) OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) \ $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES))) DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) \ $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES))) LIBS = $(addprefix $(LIBS_DIR)/,$(LIBS_NAME)) INCLUDES = $(addprefix -I,$(INCLUDE_DIR) $(GENERIC_INCLUDE) $(LIBS) $(addsuffix /include,$(LIBS))) COL_GRAY = \\e[90m COL_WHITE = \\e[37m COL_GREEN = \\e[32m COL_BOLD = \\e[1m COL_RESET = \\e[0m .PHONY: remove_name clean all fclean bonus format re generate_filelist subject get_lib all: $(NAME) bonus: all @printf \\n$(COL_GRAY)Building\ Output\ \(with\ bonus\)\ $(COL_WHITE)$(COL_BOLD)%-28s$(COL_RESET)\ \ $(NAME) @printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n get_lib: @printf $(LIB_NAME)/$(NAME) $(NAME): $(OBJ) libs_build @printf \\n$(COL_GRAY)Building\ Output\ $(COL_WHITE)$(COL_BOLD)%-28s$(COL_RESET)\ \ $(NAME) @$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME) @#ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) @printf $(COL_GREEN)done$(COL_RESET)\\n libs_build: @- $(foreach LIB,$(LIBS),\ printf \\n; \ printf $(COL_GRAY)Building\ library\ $(COL_RESET); \ printf $(COL_WHITE)$(COL_BOLD)%-25s$(COL_RESET)\\n $(LIB); \ make LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory all; \ printf \\n; \ ) $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) @printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$< @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ @printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n $(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c @mkdir -p $(dir $@) @printf $(COL_GRAY)Building\ $(COL_BOLD)$(COL_WHITE)%-50s\ $(LIB_NAME)$< @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ @printf $(COL_RESET)$(COL_GREEN)done$(COL_RESET)\\n clean: @- $(foreach LIB,$(LIBS), \ make clean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\ ) @- $(if $(LIB_NAME),,\ printf $(COL_WHITE)Clearing\ Artefacts\ ; \ printf $(COL_GRAY)\%-25s$(COL_RESET)\ \($(BUILD_DIR)\); \ rm -rf $(BUILD_DIR); \ printf $(COL_GREEN)done$(COL_RESET)\\n; \ ) @echo >/dev/null fclean: clean @- $(foreach LIB,$(LIBS), \ make fclean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\ ) @printf $(COL_WHITE)Clearing\ Output\ $(COL_GRAY)%-28s$(COL_RESET)\ \ \($(LIB_NAME)$(NAME)\) @rm -f $(BUILD_DIR)$(NAME) @rm -f push_swap @rm -f checker @printf $(COL_GREEN)done$(COL_RESET)\\n re: fclean all generate_filelist: @/usr/bin/env zsh -c "tree -iFf --noreport output | rg '^output/src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./gen.list @/usr/bin/env zsh -c "tree -iFf --noreport src | rg '^src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./src.list format: @zsh -c "c_formatter_42 **/*.c **/*.h" subject: subject.txt @bat --plain subject.txt subject.txt: @curl $(SUBJECT_URL) | pdftotext -layout -nopgbrk - subject.txt fuck_raphael: @echo "Oh que oui~~~\net jte nioc" -include $(DEPS)