Added ft_printf as a submodule.
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 3 Oct 2023 16:46:16 +0000 (18:46 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 3 Oct 2023 16:48:55 +0000 (18:48 +0200)
Quite some changes where made in Makefile to make it work
and it is not pretty.
Update to libft.h by the ft_printf function prototype.

.gitmodules [new file with mode: 0644]
Makefile
ft_printf [new submodule]
libft.h

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..f29e137
--- /dev/null
@@ -0,0 +1,4 @@
+[submodule "ft_printf"]
+       path = ft_printf
+       url = git://78.102.58.167/ft_printf
+       branch = inLibft
index 1867830e5f6d6e8c70220e0f44ef1320f38c33b7..b9c0162ddfb15ffb7e2341214c35f57cd034cc62 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,27 +4,52 @@ AR = ar
 
 RM = rm -f
 
-INCDIR = .
 SRCDIR = .
-# SOURCES = $(addprefix $(SRCDIR)/, ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c)
+INCDIR = $(SRCDIR)
 SOURCES = $(shell find $(SRCDIR) -maxdepth 1 -name "*.c")
 OBJECTS = $(SOURCES:.c=.o)
 
+# Temporary dir to extract all sub-libraries to
+LIBTEMP = .libtemp
+# This finds all the directories except hidden ones and '.' (assumes only visible dirs are project ones)
+# It may prove better to find dirs with Makefiles inside
+COMPLEX_PROJECTS := $(shell find $(SRCDIR) -maxdepth 1 -not -path '*/.*' -not -name . -type d)
+
+COMPLEX_LIBS = $(foreach DIR, $(COMPLEX_PROJECTS:./%=%), ./$(DIR)/$(DIR).a)
+
 NAME = libft.a
 
 all : $(NAME)
 
-$(NAME) : $(OBJECTS)
-       $(AR) rcs $(NAME) $(OBJECTS)
+$(NAME) : $(OBJECTS) $(COMPLEX_LIBS) $(LIBTEMP)
+       for lib in $(COMPLEX_LIBS) ; do \
+               $(AR) x $$lib --output $(LIBTEMP) ; \
+       done
+       $(AR) rcs $(NAME) $(OBJECTS) $(shell find $(LIBTEMP) -type f)
 
 %.o : %.c
        $(CC) $(CFLAGS) -o $@ -c $< -I $(INCDIR)
 
+$(COMPLEX_LIBS) :
+       $(MAKE) -C $(shell dirname $@)
+
+$(LIBTEMP):
+       mkdir -p $(LIBTEMP)
+
 clean :
-       $(RM) $(OBJECTS) $(BONUS_OBJECTS)
+       $(RM) $(OBJECTS)
+       $(RM) -r $(LIBTEMP)
+       for subpr in $(COMPLEX_PROJECTS) ; do \
+               $(MAKE) -C $$subpr clean ; \
+       done
 
-fclean : clean 
+fclean :
        $(RM) $(NAME)
+       $(RM) $(OBJECTS)
+       $(RM) -r $(LIBTEMP)
+       for subpr in $(COMPLEX_PROJECTS) ; do \
+               $(MAKE) -C $$subpr fclean ; \
+       done
 
 re : fclean
        $(MAKE) all
diff --git a/ft_printf b/ft_printf
new file mode 160000 (submodule)
index 0000000..7f5ddfc
--- /dev/null
+++ b/ft_printf
@@ -0,0 +1 @@
+Subproject commit 7f5ddfc2e05cf67a9aa52e77fb6fab96439b0d65
diff --git a/libft.h b/libft.h
index 2a9f9ec08feea685690161da51ada2c786350b51..4178e773e55c84b7983bbcf774b1942fdb0db149 100644 (file)
--- a/libft.h
+++ b/libft.h
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/08/15 12:58:15 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/09/15 18:43:23 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/10/03 16:28:50 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -67,6 +67,7 @@ void  ft_putchar_fd(char c, int fd);
 void   ft_putstr_fd(char *s, int fd);
 void   ft_putendl_fd(char *s, int fd);
 void   ft_putnbr_fd(int n, int fd);
+int            ft_printf(const char *format, ...);
 
 typedef struct s_list
 {