refactor: fix the makefile problems

This commit is contained in:
airone01
2026-01-24 18:46:05 +01:00
parent 22de4eb11a
commit 856739af67
9 changed files with 119 additions and 31 deletions

2
.gitignore vendored
View File

@@ -55,4 +55,6 @@ dkms.conf
*.dwo *.dwo
/libunit /libunit
/real_tests/real_tests
/tests/tests

View File

@@ -1,48 +1,57 @@
NAME = libunit.a NAME = libunit.a
TNAME = libunit
AR = ar rcs AR = ar rcs
CXX = cc CC = cc
CXXFLAGS = -Wall -Wextra -Werror -MMD -MP CCFLAGS = -Wall -Wextra -Werror -MMD -MP
CXXFLAGS += -g3 CCFLAGS += -I$(LIBFT_DIR) -I. -Iframework
CXXFLAGS += -I$(LIBFT_DIR) -I. -Iframework
LDFLAGS = -Llibft -lunit -lft -L. LDFLAGS = -Llibft -lunit -lft -L.
LIBFT_DIR = libft LIBFT_DIR = libft
LIBFT_A = $(LIBFT_DIR)/libft.a LIBFT_A = $(LIBFT_DIR)/libft.a
SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.c 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) 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) all: $(NAME)
$(NAME): $(OBJ) | $(LIBFT_A) $(NAME): $(OBJ) | $(LIBFT_A)
$(AR) $(NAME) $(OBJ) $(AR) $(NAME) $(OBJ)
$(TNAME): $(NAME) $(TOBJ) | $(LIBFT_A) $(NAME)
$(CXX) $(CXXFLAGS) $(TOBJ) $(LDFLAGS) -o $(TNAME)
%.o: %.c Makefile %.o: %.c Makefile
$(CXX) $(CXXFLAGS) -c $< -o $@ $(CC) $(CCFLAGS) -c $< -o $@
$(LIBFT_A): $(LIBFT_A):
$(MAKE) -C $(LIBFT_DIR) $(MAKE) -C $(LIBFT_DIR)
clean: clean:
$(MAKE) -C $(LIBFT_DIR) fclean $(RM) $(OBJ) $(SRC:.c=.d)
$(RM) $(OBJ) $(TOBJ) $(SRC:.c=.d) $(TSRC:.c=.d) $(MAKE) -C $(TESTD) clean
$(MAKE) -C $(RTESTD) clean
fclean: clean fclean: clean
$(RM) $(NAME) $(TNAME) $(RM) $(NAME)
$(MAKE) -C $(TESTD) fclean
$(MAKE) -C $(RTESTD) fclean
re: fclean re: fclean
$(MAKE) all $(MAKE) all
test: $(TNAME) $(TESTB):
./$(TNAME) $(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 .PHONY: all clean fclean re

View File

@@ -6,14 +6,14 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 14:38:40 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 #ifndef UTIL_UNIT_H
# define UTIL_UNIT_H # define UTIL_UNIT_H
# include "libft/libft.h" # include "libft.h"
# include <sys/types.h> # include <sys/types.h>
# include <unistd.h> # include <unistd.h>
@@ -66,8 +66,4 @@ void clear_tests(t_unit_test **head_ptr);
int launch_tests(t_unit_test *test_list, int launch_tests(t_unit_test *test_list,
const char *fn_name); const char *fn_name);
// LAUNCHERS
int strlen_launcher(void);
int libunit_launcher(void);
#endif // !UTIL_UNIT_H #endif // !UTIL_UNIT_H

36
real_tests/Makefile Normal file
View File

@@ -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

5
real_tests/main.c Normal file
View File

@@ -0,0 +1,5 @@
#include "tests.h"
int main(void) {
strlen_launcher();
}

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:30 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" # include "libunit.h"
// LAUNCHERS
int strlen_launcher(void);
// strlen // strlen
int test_basic(void); int test_basic(void);
int test_null(void); int test_null(void);

36
tests/Makefile Normal file
View File

@@ -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

5
tests/main.c Normal file
View File

@@ -0,0 +1,5 @@
#include "tests.h"
int main(void) {
libunit_launcher();
}

View File

@@ -6,7 +6,7 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:30 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" # include "libunit.h"
// LAUNCHERS // LAUNCHERS
int strlen_launcher(void); int libunit_launcher(void);
// libunit // libunit
int test_ok(void); int test_ok(void);
@@ -24,8 +24,4 @@ int test_ko(void);
int test_sigsegv(void); int test_sigsegv(void);
int test_sigbus(void); int test_sigbus(void);
// strlen
int test_basic(void);
int test_null(void);
#endif // !TESTS_H #endif // !TESTS_H