From 241fa411c32233a7a58f2092e93e40d612019f0b Mon Sep 17 00:00:00 2001 From: Gregory Date: Mon, 22 Apr 2019 22:36:15 +0300 Subject: [PATCH] base makefile, gitignore --- .editorconfig | 6 ++ .gitignore | 3 + Makefile | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0481b6f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +indent_style = tab +indent_size = 4 +trim_trailing_whitespace = true \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b721050 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.a +.vscode \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d4b21e --- /dev/null +++ b/Makefile @@ -0,0 +1,155 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2018/02/18 16:06:01 by gtertysh #+# #+# # +# Updated: 2019/01/19 15:21:01 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +ifeq ($(HOSTTYPE),) + HOSTTYPE := $(shell uname -m)_$(shell uname -s) +endif + + +# name of the main target + +NAME := libft_malloc_$(HOSTTYPE) + + +# project directories + +ROOT := $(shell pwd) +SRC_DIR := $(ROOT)/src/ +OBJ_DIR := $(ROOT)/obj/ +INC_DIR := $(ROOT)/inc/ +LIB_DIR := $(ROOT)/lib/ +TST_DIR := $(ROOT)/t/ + + +# project headers + +TST_HEADER := $(INC_DIR)/t.h +HEADERS := $(TST_HEADER) + + +# libraries + +LIBFT_DIR := $(LIB_DIR)libft/ +LIBFT_INC := -I $(LIBFT_DIR)includes/ +LIBFT_LIB := -lft -L $(LIBFT_DIR) +LIBFT = $(LIBFT_DIR)libft.a + + +# project source files + +SRC := malloc.c + + +# project object files + +OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o)) + + +# project test files + +TEST_BIN = malloc_test + +TEST_SRC = tests.c + +TEST_OBJ = $(addprefix $(OBJ_DIR), $(TEST_SRC:.c=.o)) + + +# compilation flags + +CC_FLAGS = -Wall -Wextra -Werror + +CC_FLAGS += -Wpointer-arith +CC_FLAGS += -Wcast-align +CC_FLAGS += -Wwrite-strings +CC_FLAGS += -Wunreachable-code +CC_FLAGS += -Winit-self +CC_FLAGS += -Wmissing-field-initializers +CC_FLAGS += -Wno-unknown-pragmas +CC_FLAGS += -Wstrict-prototypes +CC_FLAGS += -Wundef +CC_FLAGS += -Wold-style-definition + + +# for debug + +ifeq ($(DEBUG),true) + +CC_FLAGS += -g +CC_FLAGS += -O0 + +endif + + +# linking flags + +LINK_FLAGS = $(LIBFT_LIB) + + +# header flags + +HEADER_FLAGS = -I $(INC_DIR) \ + $(LIBFT_INC) + + +# compiler + +CC := clang + + +# rules + +$(NAME): $(OBJ) + $(CC) $(OBJ) $(LINK_FLAGS) -o $(NAME) + +$(TEST_BIN): $(TEST_OBJ) + $(CC) $(TEST_OBJ) $(LINK_FLAGS) -o $(TEST_BIN) + +$(TEST_OBJ) $(OBJ): | $(OBJ_DIR) + +$(OBJ_DIR): + mkdir $(OBJ_DIR) + +$(OBJ_DIR)%.o: %.c $(LIBFT) $(HEADERS) + $(CC) -c $< -o $@ $(CC_FLAGS) $(HEADER_FLAGS) + +$(LIBFT): + $(MAKE) -C $(LIBFT_DIR) + +all: $(NAME) + +check: $(TEST_BIN) + clear + ./$(TEST_BIN) + +clean: + rm -f $(OBJ) + rm -f $(TEST_OBJ) + $(MAKE) -C $(LIBFT_DIR) clean + +fclean: clean + rm -f $(NAME) + rm -f $(TEST_BIN) + $(MAKE) -C $(LIBFT_DIR) fclean + +re: fclean all + +multi: + $(MAKE) $(LIBFT) + $(MAKE) $(NAME) + + +# special stuff + +vpath %.c $(SRC_DIR) \ + $(TST_DIR) + +.PHONY: all check clean fclean re multi \ No newline at end of file