Makefile: add fclean and relink patch; start patching calloc

This commit is contained in:
Xamora 2026-09-20 05:35:56 +02:00
parent 0247990d2b
commit ddaaeaee6d
4 changed files with 27 additions and 19 deletions

View file

@ -9,7 +9,8 @@ OBJ_CC := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o, $(MAIN)))
OBJ_AS := $(addprefix $(OBJ_DIR)/, $(patsubst %.s,%.o, $(SRC)))
DIR := .
NAME := main
LIB_NAME:= asm
LIB_NAME := asm
PATH_LIB_NAME := $(OBJ_DIR)/lib$(LIB_NAME).a
LD := $(CC)
LDFLAGS := -L$(OBJ_DIR) -l$(LIB_NAME) -fPIC -fPIE
@ -17,10 +18,12 @@ LDFLAGS := -L$(OBJ_DIR) -l$(LIB_NAME) -fPIC -fPIE
all: $(NAME)
$(NAME): $(OBJ_CC) $(OBJ_AS)
ar rcs $(OBJ_DIR)/lib$(LIB_NAME).a $(OBJ_AS)
$(NAME): $(PATH_LIB_NAME) $(OBJ_CC)
$(LD) $(OBJ_CC) $(LDFLAGS) -o $(DIR)/$(NAME)
$(PATH_LIB_NAME): $(OBJ_AS)
ar rcs $(PATH_LIB_NAME) $(OBJ_AS)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<
@ -30,9 +33,9 @@ $(OBJ_DIR)/%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
clean:
@rm -f $(NAME)
@rm -rf $(OBJ_DIR)
re:
@make --no-print clean
@make --no-print all
fclean: clean
@rm -f $(NAME)
re: fclean all

2
main.c
View file

@ -185,6 +185,8 @@ test_calloc() {
char *empty = ft_calloc(0, 0);
printf("empty: %p\n", empty);
char *overflow = ft_calloc();
char *buf = ft_calloc(10, 1);
strcpy(buf, "test");
printf("test: %s_%p\n", buf, buf);

1
main.h
View file

@ -7,6 +7,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <limit.h>
// DONE
extern size_t ft_strlen(const char *s);

View file

@ -9,7 +9,9 @@ section .text
push rbx
mov rbx, rdi
mov rdi, rbx
mul rbx, rsi
xor rdi, rdi
cmovno rdi, rbx; Move if not overflow
call malloc wrt ..plt
cmp rax, 0