From 856739af67c22505052533ac4586f40db308d5b5 Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:46:05 +0100 Subject: [PATCH] refactor: fix the makefile problems --- .gitignore | 2 ++ Makefile | 45 +++++++++++++++++++++++++++------------------ framework/libunit.h | 8 ++------ real_tests/Makefile | 36 ++++++++++++++++++++++++++++++++++++ real_tests/main.c | 5 +++++ real_tests/tests.h | 5 ++++- tests/Makefile | 36 ++++++++++++++++++++++++++++++++++++ tests/main.c | 5 +++++ tests/tests.h | 8 ++------ 9 files changed, 119 insertions(+), 31 deletions(-) create mode 100644 real_tests/Makefile create mode 100644 real_tests/main.c create mode 100644 tests/Makefile create mode 100644 tests/main.c diff --git a/.gitignore b/.gitignore index db12e57..32dd980 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,6 @@ dkms.conf *.dwo /libunit +/real_tests/real_tests +/tests/tests diff --git a/Makefile b/Makefile index a4d146f..7df0dd0 100644 --- a/Makefile +++ b/Makefile @@ -1,48 +1,57 @@ NAME = libunit.a -TNAME = libunit AR = ar rcs -CXX = cc -CXXFLAGS = -Wall -Wextra -Werror -MMD -MP -CXXFLAGS += -g3 -CXXFLAGS += -I$(LIBFT_DIR) -I. -Iframework +CC = cc +CCFLAGS = -Wall -Wextra -Werror -MMD -MP +CCFLAGS += -I$(LIBFT_DIR) -I. -Iframework LDFLAGS = -Llibft -lunit -lft -L. LIBFT_DIR = libft LIBFT_A = $(LIBFT_DIR)/libft.a SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.c -TSRC = main.c real_tests/ft_strlen/00_launcher.c real_tests/ft_strlen/01_basic.c real_tests/ft_strlen/02_null.c real_tests/ft_strlen/03_large.c -TSRC += tests/libunit/00_launcher.c tests/libunit/01_ok.c tests/libunit/02_ko.c tests/libunit/03_sigsegv.c tests/libunit/04_sigbus.c OBJ = $(SRC:.c=.o) -TOBJ = $(TSRC:.c=.o) + +TESTD = tests +TESTB = $(TESTD)/tests +TESTM = $(TESTD)/Makefile +RTESTD = real_tests +RTESTB = $(RTESTD)/real_tests +RTESTM = $(RTESTD)/Makefile all: $(NAME) $(NAME): $(OBJ) | $(LIBFT_A) $(AR) $(NAME) $(OBJ) -$(TNAME): $(NAME) $(TOBJ) | $(LIBFT_A) $(NAME) - $(CXX) $(CXXFLAGS) $(TOBJ) $(LDFLAGS) -o $(TNAME) - %.o: %.c Makefile - $(CXX) $(CXXFLAGS) -c $< -o $@ + $(CC) $(CCFLAGS) -c $< -o $@ $(LIBFT_A): $(MAKE) -C $(LIBFT_DIR) clean: - $(MAKE) -C $(LIBFT_DIR) fclean - $(RM) $(OBJ) $(TOBJ) $(SRC:.c=.d) $(TSRC:.c=.d) + $(RM) $(OBJ) $(SRC:.c=.d) + $(MAKE) -C $(TESTD) clean + $(MAKE) -C $(RTESTD) clean fclean: clean - $(RM) $(NAME) $(TNAME) + $(RM) $(NAME) + $(MAKE) -C $(TESTD) fclean + $(MAKE) -C $(RTESTD) fclean re: fclean $(MAKE) all -test: $(TNAME) - ./$(TNAME) +$(TESTB): + $(MAKE) -C $(TESTD) --include $(SRC:.c=.d) $(TSRC:.c=.d) +$(RTESTB): + $(MAKE) -C $(RTESTD) + +test: $(TESTB) $(RTESTB) + $(TESTB) + $(RTESTB) + +-include $(SRC:.c=.d) .PHONY: all clean fclean re diff --git a/framework/libunit.h b/framework/libunit.h index 17e7d3e..5e859c6 100644 --- a/framework/libunit.h +++ b/framework/libunit.h @@ -6,14 +6,14 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 14:38:40 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:15:23 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 18:40:36 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef UTIL_UNIT_H # define UTIL_UNIT_H -# include "libft/libft.h" +# include "libft.h" # include # include @@ -66,8 +66,4 @@ void clear_tests(t_unit_test **head_ptr); int launch_tests(t_unit_test *test_list, const char *fn_name); -// LAUNCHERS -int strlen_launcher(void); -int libunit_launcher(void); - #endif // !UTIL_UNIT_H diff --git a/real_tests/Makefile b/real_tests/Makefile new file mode 100644 index 0000000..4bfae62 --- /dev/null +++ b/real_tests/Makefile @@ -0,0 +1,36 @@ +NAME = real_tests +CC = cc +CCFLAGS = -Wall -Wextra -Werror -MMD -MP + +SRC = main.c +SRC += ft_strlen/00_launcher.c ft_strlen/01_basic.c ft_strlen/02_null.c ft_strlen/03_large.c +OBJ = $(SRC:.c=.o) + +LIBS = -L.. -lunit -L../libft -lft +INC = -I. -I../framework -I../libft + +all: $(NAME) + +test: $(NAME) + ./$(NAME) + +%.o: %.c Makefile + $(CC) $(CCFLAGS) $(INC) -c $< -o $@ + +$(NAME): $(OBJ) | libunit + $(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME) + +libunit: + $(MAKE) -C .. + +clean: + $(RM) $(OBJ) $(SRC:.c=.d) + +fclean: clean + $(RM) $(NAME) + +re: fclean all + +-include $(SRC:.c=.d) + +.PHONY: all clean fclean re libunit diff --git a/real_tests/main.c b/real_tests/main.c new file mode 100644 index 0000000..ac63287 --- /dev/null +++ b/real_tests/main.c @@ -0,0 +1,5 @@ +#include "tests.h" + +int main(void) { + strlen_launcher(); +} diff --git a/real_tests/tests.h b/real_tests/tests.h index f9298e0..a9ec790 100644 --- a/real_tests/tests.h +++ b/real_tests/tests.h @@ -6,7 +6,7 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:33:14 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 18:40:48 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,9 @@ # include "libunit.h" +// LAUNCHERS +int strlen_launcher(void); + // strlen int test_basic(void); int test_null(void); diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..9d930f5 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,36 @@ +NAME = tests +CC = cc +CCFLAGS = -Wall -Wextra -Werror -MMD -MP + +SRC = main.c +SRC += libunit/00_launcher.c libunit/01_ok.c libunit/02_ko.c libunit/03_sigsegv.c libunit/04_sigbus.c +OBJ = $(SRC:.c=.o) + +LIBS = -L.. -lunit -L../libft -lft +INC = -I. -I../framework -I../libft + +all: $(NAME) + +test: $(NAME) + ./$(NAME) + +%.o: %.c Makefile + $(CC) $(CCFLAGS) $(INC) -c $< -o $@ + +$(NAME): $(OBJ) | libunit + $(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME) + +libunit: + $(MAKE) -C .. + +clean: + $(RM) $(OBJ) $(SRC:.c=.d) + +fclean: clean + $(RM) $(NAME) + +re: fclean all + +-include $(SRC:.c=.d) + +.PHONY: all clean fclean re libunit diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..3f9c5f9 --- /dev/null +++ b/tests/main.c @@ -0,0 +1,5 @@ +#include "tests.h" + +int main(void) { + libunit_launcher(); +} diff --git a/tests/tests.h b/tests/tests.h index 24a4f2d..bc413c6 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -6,7 +6,7 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:16:20 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 18:41:02 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ # include "libunit.h" // LAUNCHERS -int strlen_launcher(void); +int libunit_launcher(void); // libunit int test_ok(void); @@ -24,8 +24,4 @@ int test_ko(void); int test_sigsegv(void); int test_sigbus(void); -// strlen -int test_basic(void); -int test_null(void); - #endif // !TESTS_H