Skip to content

Commit 34e8498

Browse files
committed
update: project files are now stored in src and include folders, Makefile improved to avoid relink, norminette and Makefile workflows added
1 parent d7ba10f commit 34e8498

12 files changed

Lines changed: 284 additions & 76 deletions

File tree

.github/workflows/makefile.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Makefile
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
check-makefile:
8+
name: Makefile
9+
runs-on: ubuntu-latest
10+
if: ${{ github.repository != 'sdevsantiago/42_project_template' }}
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Prerequisites
16+
run: sudo apt install build-essential
17+
18+
- name: Show Make Version
19+
run: make --version
20+
21+
- name: Run Makefile
22+
run: make > makefile-report.txt
23+
24+
- name: Upload Makefile report
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: makefile-report
28+
path: makefile-report.txt
29+

.github/workflows/norminette.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Norminette
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
check-norminette:
8+
name: Norminette
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: '3.x'
18+
19+
- name: Install Norminette
20+
run: pip install --upgrade norminette
21+
22+
- name: Show Version
23+
run: norminette --version
24+
25+
- name: Run Norminette
26+
run: norminette -R CheckForbiddenSourceHeader -R CheckDefine -R CheckLine -R CheckVariableName -R CheckFunctionName --use-gitignore > norminette-report.txt
27+
28+
- name: Upload Norminette report
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: norminette-report
32+
path: norminette-report.txt

.gitignore

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
1-
# Libraries
2-
/lib
1+
# VS Code
2+
.vscode/
3+
4+
# Build path
5+
build/
6+
7+
# Prerequisites
8+
*.d
39

10+
# Object files
411
*.o
5-
libftprintf.a
12+
*.ko
13+
*.obj
14+
*.elf
15+
16+
# Linker output
17+
*.ilk
18+
*.map
19+
*.exp
20+
21+
# Precompiled Headers
22+
*.gch
23+
*.pch
24+
25+
# Libraries
26+
lib/
27+
*.lib
28+
*.a
29+
*.la
30+
*.lo
31+
32+
# Shared objects (inc. Windows DLLs)
33+
*.dll
34+
*.so
35+
*.so.*
36+
*.dylib
37+
38+
# Executables
39+
*.exe
40+
*.out
41+
*.app
42+
*.i*86
43+
*.x86_64
44+
*.hex
45+
46+
# Debug files
47+
*.dSYM/
48+
*.su
49+
*.idb
50+
*.pdb
51+
52+
# Kernel Module Compile Results
53+
*.mod*
54+
*.cmd
55+
.tmp_versions/
56+
modules.order
57+
Module.symvers
58+
Mkfile.old
59+
dkms.conf
60+
61+
# debug information files
62+
*.dwo

Makefile

Lines changed: 107 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,91 +6,150 @@
66
# By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2024/10/29 19:07:42 by sede-san #+# #+# #
9-
# Updated: 2025/04/22 21:40:19 by sede-san ### ########.fr #
9+
# Updated: 2025/08/25 16:58:29 by sede-san ### ########.fr #
1010
# #
1111
# **************************************************************************** #
1212

1313
# ******************************* Output files ******************************* #
14-
# Library name
15-
NAME = ft_printf.a
14+
15+
# Project name
16+
NAME = libftprintf.a
1617

1718
# ************************** Compilation variables *************************** #
19+
1820
# Compiler
1921
CC = cc
2022

2123
# Compilation flags
22-
CFLAGS = -Wall -Wextra -Werror
24+
CFLAGS = -Wall -Wextra -Werror -Wunreachable-code # -Ofast
2325

24-
# ****************************** Source files ******************************** #
25-
SRC = \
26-
ft_printf.c
26+
# Additional headers
27+
HEADERS = -I $(INCLUDE_PATH) -I $(LIBFT_INCLUDE_PATH)
28+
29+
# Debug flags, execute with DEBUG=1 -> make DEBUG=1
30+
DFLAGS = -g3
31+
ifeq ($(DEBUG), 1)
32+
CFLAGS += $(DFLAGS)
33+
endif
2734

28-
CHARACTER_STRING_PATH = character_string_types
35+
# Make command with no-print-directory flag
36+
MAKE += --no-print-directory
2937

30-
SRC += \
31-
$(CHARACTER_STRING_PATH)/ft_printf_putchar.c \
32-
$(CHARACTER_STRING_PATH)/ft_printf_putstr.c
38+
# ***************************** Style variables ****************************** #
3339

34-
INTEGER_PATH = integer_types
40+
# Define color codes
41+
RED = \033[0;31m
42+
GREEN = \033[0;32m
43+
YELLOW = \033[0;33m
44+
BLUE = \033[0;34m
45+
RESET = \033[0m # No Color
3546

36-
SRC += \
37-
$(INTEGER_PATH)/ft_printf_putint.c \
38-
$(INTEGER_PATH)/ft_printf_putuint.c
47+
# Emojis
48+
EMOJI_BROOM = 🧹
49+
EMOJI_CHECK = ✅
50+
EMOJI_CROSS = ❌
51+
EMOJI_WRENCH = 🔧
52+
EMOJI_BOX = 📦
3953

40-
MEMDIR_PATH = memdir_types
54+
# ****************************** Source files ******************************** #
55+
56+
# Source files path
57+
SRC_PATH = src
58+
59+
# Source files
60+
SRC = \
61+
$(SRC_PATH)/ft_printf.c \
62+
$(SRC_PATH)/character_string_types/ft_printf_putchar.c \
63+
$(SRC_PATH)/character_string_types/ft_printf_putstr.c \
64+
$(SRC_PATH)/integer_types/ft_printf_putint.c \
65+
$(SRC_PATH)/integer_types/ft_printf_putuint.c \
66+
$(SRC_PATH)/memdir_types/ft_printf_putptr.c
4167

42-
SRC += \
43-
$(MEMDIR_PATH)/ft_printf_putptr.c
68+
# Include path
69+
INCLUDE_PATH = ./include
4470

4571
# ****************************** Object files ******************************** #
46-
OBJ = $(SRC:.c=.o)
4772

48-
# Compile object files
49-
%.o: %.c
50-
$(CC) $(CFLAGS) -c $< -o $@
73+
# Object files path
74+
OBJS_PATH = build
75+
76+
# Source files and destination paths
77+
OBJS = $(SRC:$(SRC_PATH)/%.c=$(OBJS_PATH)/%.o)
78+
79+
# Compile as object files
80+
$(OBJS_PATH)/%.o: $(SRC_PATH)/%.c
81+
@mkdir -p $(@D)
82+
@$(CC) $(CFLAGS) -c $< -o $@ $(HEADERS)
83+
@echo "$< compiled"
5184

5285
# ********************************* Rules ************************************ #
86+
5387
# Compile all
54-
all: $(NAME)
88+
all: libft $(NAME)
89+
.PHONY: all
5590

56-
$(NAME): libft $(OBJ)
57-
cp $(LIBFT) $(NAME)
58-
ar rcs $(NAME) $(OBJ)
59-
mv $(NAME) libftprintf.a
91+
# Compile project
92+
$(NAME): $(OBJS)
93+
@echo "$(YELLOW)$(EMOJI_BOX) Linking...$(RESET)"
94+
ar rcs $(NAME) $(OBJS) $(LIBFT_BIN)
95+
@echo "$(GREEN)$(EMOJI_CHECK) Linked.$(RESET)"
6096

6197
# Clean object files
6298
clean:
63-
$(MAKE) -C $(LIBFT_PATH) clean
64-
rm -f $(OBJ)
99+
@echo "$(RED)$(EMOJI_BROOM) Cleaning object files...$(RESET)"
100+
@rm -rf $(OBJS_PATH)
101+
@echo "$(GREEN)$(EMOJI_CHECK) Object files cleaned.$(RESET)"
102+
.PHONY: clean
65103

66-
# Clean object files and library
104+
# Clean object files and binaries
67105
fclean: clean
68-
rm -rf $(LIB_PATH)
69-
rm -f $(OBJ)
70-
rm -f libftprintf.a
106+
@echo "$(RED)$(EMOJI_BROOM) Cleaning binaries...$(RESET)"
107+
@rm -f $(NAME)
108+
@if [ -d $(LIBFT_PATH) ]; then \
109+
$(MAKE) -C $(LIBFT_PATH) fclean; \
110+
fi
111+
@echo "$(GREEN)$(EMOJI_CHECK) Binaries cleaned.$(RESET)"
112+
.PHONY: fclean
71113

72114
# Recompile
73115
re: fclean all
116+
.PHONY: re
117+
118+
# ********************************* Libraries ******************************** #
74119

75-
# ****************************** Libraries ********************************** #
120+
# Compile libraries
121+
lib:
122+
@$(MAKE) libft
123+
.PHONY: lib
76124

125+
# Compile file with libraries
126+
LIBS = $(LIBFT_BIN)
127+
128+
# Libraries path
77129
LIB_PATH = lib
78130

79-
LIBFT_PATH = $(LIB_PATH)/Libft
131+
# ** Libft ** #
132+
133+
LIBFT = Libft
134+
LIBFT_REPO = https://github.com/sdevsantiago/Libft.git
135+
LIBFT_PATH = $(LIB_PATH)/$(LIBFT)
136+
LIBFT_INCLUDE_PATH = $(LIBFT_PATH)
137+
LIBFT_BIN = $(LIBFT_PATH)/libft.a
80138

81-
LIBFT = $(LIBFT_PATH)/libft.a
139+
libft: $(LIBFT_BIN)
82140

83-
libft:
84-
if [ ! -d $(LIBFT_PATH) ]; then \
85-
git clone https://github.com/sdevsantiago/Libft.git $(LIBFT_PATH); \
86-
$(MAKE) -C $(LIBFT_PATH) all bonus; \
87-
elif [ ! -x $(LIBFT) ]; then \
88-
$(MAKE) -C $(LIBFT_PATH) re bonus; \
141+
$(LIBFT_BIN):
142+
@if [ ! -d $(LIBFT_PATH) ]; then \
143+
echo "$(YELLOW)$(EMOJI_WRENCH) Cloning $(LIBFT)...$(RESET)"; \
144+
git clone $(LIBFT_REPO) $(LIBFT_PATH); \
145+
rm -rf $(LIBFT_PATH)/.git; \
146+
echo "$(GREEN)$(EMOJI_CHECK) $(LIBFT) cloned...$(RESET)"; \
147+
fi
148+
@if [ ! -f $(LIBFT_BIN) ]; then \
149+
echo "$(YELLOW)$(EMOJI_WRENCH) Compiling $(LIBFT)...$(RESET)"; \
150+
$(MAKE) -C $(LIBFT_PATH) all clean; \
151+
echo "$(GREEN)$(EMOJI_CHECK) $(LIBFT) compiled.$(RESET)"; \
89152
else \
90-
cd $(LIBFT_PATH); \
91-
git pull; \
92-
cd -; \
153+
echo "$(GREEN)$(EMOJI_CHECK) $(LIBFT) already compiled.$(RESET)"; \
93154
fi
94-
95-
# *********************************** Phony ********************************** #
96-
.PHONY = all clean fclean re
155+
.PHONY: libft

include/ft_printf.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_printf.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/10/29 18:21:23 by sede-san #+# #+# */
9+
/* Updated: 2025/08/25 03:17:19 by sede-san ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef FT_PRINTF_H
14+
# define FT_PRINTF_H
15+
16+
# include "libft.h"
17+
# include <stdarg.h>
18+
# include <stdint.h>
19+
20+
// ft_printf.c
21+
int ft_printf(char const *format, ...);
22+
23+
#endif

0 commit comments

Comments
 (0)