-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
72 lines (55 loc) · 1.54 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
NAME := libasm.a
SDIR := ./srcs
ODIR := ./objs
SRCS := ft_write.s ft_read.s ft_strlen.s ft_strcpy.s ft_strcmp.s ft_strdup.s
_OBJ := $(SRCS:.s=.o)
OBJ := $(patsubst %, $(ODIR)/%, $(_OBJ))
.PHONY: all clean fclean re
all: $(NAME)
$(NAME): $(OBJ)
@echo "Creating $@"
@ar crs $@ $^
$(ODIR)/%.o: $(SDIR)/%.s
@mkdir -p $(ODIR)
@echo "Compiling $<"
@nasm -f elf64 -Werror -o $@ $<
clean:
@rm -rf $(ODIR)
fclean : clean
@rm -f $(NAME)
re: fclean all
TEST_NAME := test_libasm
LIBASM_NAME := libasm.a
LIBASM_PATH := $(LIBASM_NAME)
CC := gcc
CFLAGS := -Wall -Werror -Wextra -fsanitize=address
TEST_SRC_DIR := tests
TEST_INC_DIR := tests
TEST_OBJ_DIR := test_objs
TEST_SRCS := main.c \
utils.c \
test_ft_read.c \
test_ft_strcmp.c \
test_ft_strcpy.c \
test_ft_strdup.c \
test_ft_strlen.c \
test_ft_write.c
TEST_INCS := $(TEST_INC_DIR)/libasm.h $(TEST_INC_DIR)/ft_test.h
TEST_OBJS := $(addprefix $(TEST_OBJ_DIR)/, $(TEST_SRCS:.c=.o))
MD := mkdir -p
.PHONY: build-test test clean-test fclean-test docker-test
build-test: re $(TEST_NAME)
$(TEST_NAME): $(TEST_OBJS)
@$(CC) $(CFLAGS) -o $@ $^ -L. -lasm
$(TEST_OBJ_DIR)/%.o: $(TEST_SRC_DIR)/%.c $(TEST_INCS)
@$(MD) $(TEST_OBJ_DIR)
@$(CC) $(CFLAGS) -o $@ -c $< -I $(TEST_INC_DIR)
test: build-test
@./$(TEST_NAME)
clean-test: clean
@rm -rf $(TEST_OBJ_DIR)
fclean-test: fclean clean-test
@rm -f $(TEST_NAME)
docker-test:
@docker build --platform linux/amd64 -t libasm:latest -f ./tests/Dockerfile .
@docker run --platform linux/amd64 -it --rm libasm:latest