patch lib; main test; Makefile path

This commit is contained in:
Xamora 2025-02-19 17:10:04 +01:00
parent 608ea5c5dc
commit 40e3e0543a
6 changed files with 31 additions and 7 deletions

View file

@ -1,18 +1,19 @@
CC := gcc
LD := $(CC)
LDFLAGS :=
LDFLAGS := -shared
CFLAGS := $(shell cat compile_flags.txt | sed -z "s/\n/ /g")
SRC := $(wildcard src/*.c)
LIB := lib/lib.a
OBJ_DIR := build
OBJ := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(SRC)))
DIR := .
RAW_NAME:= libft_malloc
RAW_NAME:= ft_malloc
LIB_NAME:= lib$(RAW_NAME)
ifeq ($(HOSTTYPE),)
HOSTTYPE := $(shell uname -m)_$(shell uname -s)
endif
NAME := $(RAW_NAME).so
NAME_L := $(RAW_NAME)_$(HOSTTYPE).so
NAME := $(LIB_NAME).so
NAME_L := $(LIB_NAME)_$(HOSTTYPE).so
all: $(NAME)
@ -27,13 +28,19 @@ $(OBJ_DIR)/%.o: %.c
clean:
@rm -rf $(OBJ_DIR)
@rm -f main.o
fclean: clean
@rm -f $(DIR)/$(NAME)
@rm -f $(DIR)/$(NAME_L)
@rm -f main
re:
@make --no-print clean
@make --no-print all
main: $(NAME)
export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(shell pwd)/
$(CC) main.c -L. -l$(RAW_NAME) -o main
.PHONY: all clean re

1
README.md Normal file
View file

@ -0,0 +1 @@
need to set **LIB_LIBRARY_PATH=.**

View file

@ -4,6 +4,10 @@
#include <unistd.h>
#include <sys/resource.h>
/*typedef struct {
u16 byte;
} meta_t ;*/
void free(void *ptr);
void *malloc(size_t size);
void *realloc(void *ptr, size_t size);

9
main.c Normal file
View file

@ -0,0 +1,9 @@
#include <stddef.h>
#include "inc/malloc.h"
int
main(void) {
void* test = malloc(4);
(void)test;
return 0;
}

2
main.sh Executable file
View file

@ -0,0 +1,2 @@
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD
gcc main.c -L. -lft_malloc -o main

View file

@ -1,4 +1,3 @@
#include "libft/libft.h"
char *memory = nullptr;
void *
@ -6,7 +5,9 @@ malloc(size_t size) {
if (!memory)
memory = mmap(nullptr, 4096 * 10, 0, PROT_READ | PROT_WRITE, 0, 0);
for (i32 i = 0; i < ft_get_size(size); i++) {
for (size_t i = 0; i < size; i++) {
ft_printf("test");
}
return memory;
}