diff --git a/.gitignore b/.gitignore index e313e7e..c6911d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.so .vscode /bld +/out diff --git a/Makefile b/Makefile deleted file mode 100644 index 28d88d5..0000000 --- a/Makefile +++ /dev/null @@ -1,165 +0,0 @@ -# **************************************************************************** # -# # -# ::: :::::::: # -# 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).so - - -# 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 - -MLC_HEADER := $(INC_DIR)/ft_malloc.h -TST_HEADER := $(INC_DIR)/tests.h -TST_RUNNER_HEADER := $(INC_DIR)/t.h -HEADERS := $(MLC_HEADER) \ - $(TST_HEADER) \ - $(TST_RUNNER_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 - -MALLOC_SRC = malloc.c - -SRC := $(MALLOC_SRC) - - -# project object files - -OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o)) - - -# project test files - -TEST_BIN = malloc_test - -MALLOC_TESTS = malloc_tests.c -MALLOC_TESTS += $(MALLOC_SRC) - -TEST_SRC = tests.c \ - $(MALLOC_TESTS) - -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) -shared $(OBJ) -o $(NAME) $(LINK_FLAGS) - -$(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) -fpic -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 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ebb351f --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +PWD=$(pwd) +OUT_DIR="$PWD/out" +BLD_DIR="$PWD/bld" + +meson $BLD_DIR --includedir=$OUT_DIR --libdir=$OUT_DIR --bindir=$OUT_DIR --prefix=$OUT_DIR +ninja -C $BLD_DIR +ninja -C $BLD_DIR install \ No newline at end of file diff --git a/meson.build b/meson.build index 3057c41..935140a 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,27 @@ -project('malloc', 'c') +project( + 'malloc', + 'c', + default_options: [ + 'buildtype=release', + ], +) + +add_global_arguments( + '-Wall', + '-Wextra', + '-Werror', + '-Wpointer-arith', + '-Wcast-align', + '-Wwrite-strings', + '-Wunreachable-code', + '-Winit-self', + '-Wmissing-field-initializers', + '-Wno-unknown-pragmas', + '-Wstrict-prototypes', + '-Wundef', + '-Wold-style-definition', + language: 'c', +) inc = include_directories('inc') subdir('inc') diff --git a/src/free.c b/src/free.c index 394db36..7932342 100644 --- a/src/free.c +++ b/src/free.c @@ -2,5 +2,6 @@ void free(void *used) { + (void)used; return ; } diff --git a/src/meson.build b/src/meson.build index 151a4ff..063f400 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,4 +4,9 @@ srcs = [ 'realloc.c', ] -ft_malloc = shared_library('ft_malloc', srcs, include_directories: inc) \ No newline at end of file +ft_malloc = shared_library( + 'ft_malloc', + srcs, + include_directories: inc, + install: true, +) \ No newline at end of file diff --git a/src/realloc.c b/src/realloc.c index 4c78ac7..cf25e51 100644 --- a/src/realloc.c +++ b/src/realloc.c @@ -2,5 +2,7 @@ void *realloc(void *ptr, size_t size) { + (void)ptr; + (void)size; return (NULL); } \ No newline at end of file diff --git a/t/malloc_tests.c b/t/malloc_tests.c index d3fc58b..36f552c 100644 --- a/t/malloc_tests.c +++ b/t/malloc_tests.c @@ -1,6 +1,6 @@ #include "t.h" -int return_null_on_zero_size() +int return_null_on_zero_size(void) { _IS(1 == 1); _END("return null on zero size"); diff --git a/inc/t.h b/t/t.h similarity index 100% rename from inc/t.h rename to t/t.h