chore: Makefile and file structure
This commit is contained in:
parent
d1b44a53da
commit
e98394cc4c
|
@ -1,3 +1,9 @@
|
|||
# ft_nm
|
||||
ft_nm
|
||||
|
||||
# vim
|
||||
*.swp
|
||||
|
||||
# ---> C
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
NAME = ft_nm
|
||||
|
||||
SRC_FILES = main.c \
|
||||
|
||||
INC_FILES = ft_nm.h \
|
||||
|
||||
OBJ_FILES = $(SRC_FILES:.c=.o)
|
||||
|
||||
SRC_DIR = src/
|
||||
INC_DIR = inc/
|
||||
OBJ_DIR = obj/
|
||||
|
||||
SRC = $(addprefix $(SRC_DIR), $(SRC_FILES))
|
||||
INC = $(addprefix $(INC_DIR), $(INC_FILES))
|
||||
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILES))
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
|
||||
RED = \033[31m
|
||||
GREEN = \033[32m
|
||||
YELLOW = \033[33m
|
||||
BLUE = \033[34m
|
||||
CYAN = \033[36m
|
||||
WHITE = \033[0m
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ) $(INC)
|
||||
@$(CC) $(CFLAGS) -I $(INC_DIR) -c $(SRC)
|
||||
@mv $(OBJ_FILES) $(OBJ_DIR)
|
||||
@$(CC) $(CFLAGS) $(OBJ) -o $(NAME)
|
||||
@echo "$(GREEN)[OK]$(WHITE) $(NAME)"
|
||||
|
||||
$(OBJ_DIR)%.o: $(SRC_DIR)%.c
|
||||
@if [ ! -d ./obj ]; then \
|
||||
mkdir -p ./obj; \
|
||||
fi;
|
||||
@$(CC) $(CFLAGS) -I $(INC_DIR) -o $@ -c $<
|
||||
@echo "$(CYAN)[CC]$(WHITE) $<"
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef _FT_NM_H
|
||||
# define _FT_NM_H
|
||||
|
||||
# include <unistd.h>
|
||||
# include <sys/mman.h>
|
||||
# include <fcntl.h>
|
||||
# include <elf.h>
|
||||
# include <stdio.h>
|
||||
|
||||
#endif
|
|
@ -0,0 +1,26 @@
|
|||
#include "ft_nm.h"
|
||||
|
||||
int main(void) {
|
||||
int fd = open("ft_nm", O_RDONLY);
|
||||
void *ptr = NULL;
|
||||
Elf64_Ehdr *header;
|
||||
|
||||
ptr = mmap(NULL, 64, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (ptr != MAP_FAILED) {
|
||||
header = (Elf64_Ehdr *)ptr;
|
||||
write(1, ptr, 4);
|
||||
write(1, "\n", 1);
|
||||
write(1, header->e_ident, 4);
|
||||
write(1, "\n", 1);
|
||||
if (header->e_ident[EI_OSABI] == 0x00) {
|
||||
printf("This ELF is for System V! :)\n");
|
||||
}
|
||||
else if (header->e_ident[EI_OSABI] == 0x03) {
|
||||
printf("This ELF is for linux! :)\n");
|
||||
} else {
|
||||
printf("What's my purpose :(\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue