Skip to content

Commit

Permalink
[ADD] Basic Makefile and libft cp.
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicosia committed Nov 22, 2022
1 parent 27b697c commit e9bacc6
Show file tree
Hide file tree
Showing 97 changed files with 3,988 additions and 0 deletions.
147 changes: 147 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lumenthi <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2017/12/22 14:06:43 by lumenthi #+# #+# #
# Updated: 2022/11/22 18:09:12 by lnicosia ### ########.fr #
# #
# **************************************************************************** #

NAME = ft_malcolm

CC = gcc
FLAGS = -Wall -Werror -Wextra -O3 -flto
LDFLAGS = -lpthread -lm

GREEN = '\033[4;32m'
RED = '\033[4;31m'
BLANK = '\033[0m'
YELLOW = '\033[4;33m'
CYAN = '\033[4;38;5;51m'
WARNING = '\033[1;33m'
RESET = '\033[0m'
COMPILE_COLOR = '\033[0;33m'

TICK = '\033[1;32m~\033[0m'
CROSS = '\033[1;31mx\033[0m'

###### FOLDERS ######

LIBDIR = libft
SRCDIR = sources
HEADDIR = headers
OBJDIR = objs

#####################

#####################

###### LIBRARY ######

LIBFT = $(LIBDIR)/libft.a

#####################

###### HEADERS ######

HEADS = malcolm.h
HEADERS = $(addprefix $(HEADDIR)/, $(HEADS))

#####################

###### SOURCES ######

SRCS = main.c \

SOURCES = $(addprefix $(SRCDIR)/, $(SRCS))

#####################

###### OBJECTS ######

OBJS = $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))

#####################

###### DEPENDENCIES ######

DEP = $(OBJS:.o=.d)

#####################

TODOS=$(shell grep -nr "TODO" $(SRCDIR) $(HEADDIR) | wc -l)

SHOULD_COUNT=1
FILES_TO_COMPILE = 0
ifeq ($(SHOULD_COUNT), 1)
FILES_TO_COMPILE:=$(shell make -n SHOULD_COUNT=0 | grep "gcc -c" | wc -l)
endif

all:
@ $(MAKE) -s -C $(LIBDIR)
@ $(MAKE) --no-print-directory $(NAME)

###### BINARY COMPILATION ######

$(NAME): $(LIBFT) $(OBJS) ${HEADERS}
@ printf "[Linking] "
$(CC) $(OBJS) -o $(NAME) $(LIBFT) $(LDFLAGS)
@ printf " %b | Compiled %b%b%b\n" $(TICK) $(GREEN) $(NAME) $(BLANK)
@ if [ $(TODOS) -gt 0 ]; then\
printf "%b[WARNING]%b You have %d TODOs pending, run make todo to check them.\n"\
$(WARNING) $(BLANK) $(TODOS);\
fi

###############################

$(LIBFT):
@ $(MAKE) -s -C $(LIBDIR)

-include $(DEP)

I = 1
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@ mkdir -p $(OBJDIR)
@ printf "[$(I)/$(FILES_TO_COMPILE)] "
$(CC) -c -MMD -MF $(patsubst %.o,%.d,$@) $(FLAGS) -I$(HEADDIR) -I$(LIBDIR) -o $@ $<
$(eval I=$(shell echo $$(($(I) + 1))))

$(DEPDIR)/%.d: $(SRCDIR)/%.c
@ mkdir -p $(DEPDIR)
$(CC) -c -MMD $(FLAGS) -I$(HEADDIR) -I$(LIBDIR) -o $@ $<

clean:
@ $(MAKE) -s -C $(LIBDIR) clean
@ test -d $(OBJDIR) && \
rm -rf $(OBJDIR) && \
printf " %b | " $(TICK) && \
printf "Removed %bobjects%b folders\n" $(YELLOW) $(BLANK) \
|| (printf " %b | " $(CROSS) && \
printf "No %bobjects%b folders\n" $(YELLOW) $(BLANK))

fclean: clean
@ test -f $(LIBFT) && \
rm -rf $(LIBFT) && \
printf " %b | " $(TICK) && \
printf "Removed %blibft%b library\n" $(RED) $(BLANK) \
|| (printf " %b | " $(CROSS) && \
printf "No %blibft%b library\n" $(RED) $(BLANK))
@ test -f $(NAME) && \
rm -rf $(NAME) && \
printf " %b | " $(TICK) && \
printf "Removed %b%b%b binary\n" $(RED) $(NAME) $(BLANK) \
|| (printf " %b | " $(CROSS) && \
printf "No %b%b%b binary\n" $(RED) $(NAME) $(BLANK))

re: fclean # Make -j support
@ $(MAKE) all

todo:
@ printf "%b" $(WARNING)
@ grep -nr "TODO" $(SRCDIR) $(HEADDIR) || true
@ printf "%b" $(BLANK)

.PHONY: all clean fclean re todo
Binary file added ft_malcolm
Binary file not shown.
4 changes: 4 additions & 0 deletions headers/malcolm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef MALCOLM_H
# define MALCOLM_H

#endif
153 changes: 153 additions & 0 deletions libft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lumenthi <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/01/04 10:37:11 by lumenthi #+# #+# #
# Updated: 2022/10/11 11:10:04 by lumenthi ### ########.fr #
# #
# **************************************************************************** #

.PHONY: all clean fclean re

CC = gcc
FLAGS = -Werror -Wall -Wextra -fPIC

NAME = libft.a

GREEN = '\033[4;32m'
YELLOW = '\033[4;33m'
BLANK = '\033[0m'
RED = '\033[4;31m'

TICK = '\033[1;32m~\033[0m'
CROSS = '\033[1;31mx\033[0m'

NPROC = $(shell nproc)

INCLUDES = libft.h

SRCS = ft_atoi.c \
ft_atoi_base.c \
ft_bzero.c \
ft_isalnum.c \
ft_isalpha.c \
ft_isascii.c \
ft_isdigit.c \
ft_isprint.c \
ft_itoa.c \
ft_memalloc.c \
ft_memccpy.c \
ft_memchr.c \
ft_memcmp.c \
ft_memcpy.c \
ft_memdel.c \
ft_memmove.c \
ft_memset.c \
ft_putchar.c \
ft_putchar_fd.c \
ft_putendl.c \
ft_putendl_fd.c \
ft_putnbr.c \
ft_putnbr_fd.c \
ft_putstr.c \
ft_putstr_fd.c \
ft_strcat.c \
ft_strchr.c \
ft_strclr.c \
ft_strcpy.c \
ft_strdel.c \
ft_strdup.c \
ft_strequ.c \
ft_striter.c \
ft_striteri.c \
ft_strjoin.c \
ft_strlcat.c \
ft_strlen.c \
ft_strmap.c \
ft_strmapi.c \
ft_strncat.c \
ft_strncpy.c \
ft_strnequ.c \
ft_strnew.c \
ft_strnstr.c \
ft_strrchr.c \
ft_strsplit.c \
ft_strstr.c \
ft_strsub.c \
ft_strtrim.c \
ft_tolower.c \
ft_toupper.c \
ft_strcmp.c \
ft_strncmp.c \
ft_lstnew.c \
ft_lstdelone.c \
ft_lstdel.c \
ft_lstadd.c \
ft_lstpush.c \
ft_lstiter.c \
ft_lstmap.c \
ft_power.c \
ft_count_words.c \
ft_sqrt.c \
ft_intlen.c \
ft_isspace.c \
ft_realloc.c \
ft_strchr_index.c \
ft_strswap.c \
get_next_line.c \
ft_charjoin.c \
ft_delete.c \
ft_printtab.c \
ft_isprintable.c \
ft_strjoinl.c \
ft_putaddress.c \
ft_exit.c \
ft_puthex.c \
ft_strisnum.c \
ft_getopt.c \
is_arg_an_opt.c \
ft_strbegin.c \
print_packet.c \
ft_ceil.c \
ft_getlen.c \
ft_random.c \
ft_strjoin_free.c \
ft_rmchar.c \
time_utils.c \
ft_abs.c

OBJDIR = objs
OBJS = $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))

all:
@ $(MAKE) -s $(NAME)

$(OBJDIR)/%.o: %.c
@ mkdir -p $(OBJDIR)
$(CC) -c $(FLAGS) -o $@ $<

$(NAME): $(OBJS)
@ ar rc $(NAME) $(OBJS)
@ ranlib $(NAME)
@ printf " %b | Compiled %blibft%b\n" $(TICK) $(GREEN) $(BLANK)

clean:
@ test -d $(OBJDIR) && \
rm -rf $(OBJDIR) && \
printf " %b | " $(TICK) && \
printf "Removed %blibft%b object folder\n" $(YELLOW) $(BLANK) \
|| (printf " %b | " $(CROSS) && \
printf "No %blibft%b object folder\n" $(YELLOW) $(BLANK))

fclean: clean
@ test -f $(NAME) && \
rm -rf $(NAME) && \
printf " %b | " $(TICK) && \
printf "Removed %blibft%b library\n" $(RED) $(BLANK) \
|| (printf " %b | " $(CROSS) && \
printf "No %blibft%b library\n" $(RED) $(BLANK))

re: fclean all
1 change: 1 addition & 0 deletions libft/auteur
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lumenthi
14 changes: 14 additions & 0 deletions libft/ft_abs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int ft_abs(int nb)
{
return ((nb > 0) ? nb : -nb);
}

long ft_labs(long nb)
{
return ((nb > 0) ? nb : -nb);
}

long long ft_llabs(long long nb)
{
return ((nb > 0) ? nb : -nb);
}
69 changes: 69 additions & 0 deletions libft/ft_atoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lumenthi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/14 13:20:06 by lumenthi #+# #+# */
/* Updated: 2017/11/17 10:57:34 by lumenthi ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

int ft_atoi(const char *str)
{
int i;
int sign;
int nb;

i = 0;
nb = 0;
sign = 1;
while (str[i] == '\n' || str[i] == '\f' || str[i] == '\v' ||
str[i] == '\r' || str[i] == '\t' || str[i] == ' ')
i++;
if (str[i] == '-')
sign = -1;
if (str[i] == '+' || str[i] == '-')
{
if (str[i + 1] < '0' || str[i + 1] > '9')
return (0);
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
nb = nb * 10 + (str[i] - '0');
i++;
}
return (nb * sign);
}

long long ft_atoll(const char *str)
{
int i;
int sign;
long long nb;

i = 0;
nb = 0;
sign = 1;
while (str[i] == '\n' || str[i] == '\f' || str[i] == '\v' ||
str[i] == '\r' || str[i] == '\t' || str[i] == ' ')
i++;
if (str[i] == '-')
sign = -1;
if (str[i] == '+' || str[i] == '-')
{
if (str[i + 1] < '0' || str[i + 1] > '9')
return (0);
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
nb = nb * 10 + (str[i] - '0');
i++;
}
return (nb * sign);
}
Loading

0 comments on commit e9bacc6

Please sign in to comment.