-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (51 loc) · 1.26 KB
/
Makefile
File metadata and controls
70 lines (51 loc) · 1.26 KB
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
SHELL = /bin/sh
CFLAGS := ${CFLAGS}
CC ?= gcc
LD ?= gcc
INC_FLAGS := -Ilib/libft
LIBS := -Llib/libft -lft -lreadline
UNAME = $(shell uname -s)
ifeq ($(UNAME), Linux)
NPROC := $(shell nproc)
else
NPROC := $(shell sysctl -n hw.ncpu)
INC_FLAGS += -I$(HOME)/.brew/opt/readline/include
LIBS += -L$(HOME)/.brew/opt/readline/lib
endif
MAKEFLAGS += --output-sync=target
MAKEFLAGS += --no-print-directory
NAME ?= minishell
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name '*.c')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS += $(addprefix -I,$(INC_DIRS))
LIB := lib/libft/libft.a
CFLAGS += -Wall -Wextra -Werror
#CFLAGS += -O2 -march=native
#CFLAGS += -g3
all:
@$(MAKE) -j$(NPROC) $(NAME)
$(NAME): $(LIB) $(OBJS)
@echo Linking $@
@$(CC) $(CFLAGS) $(INC_FLAGS) $(OBJS) $(LIBS) -o $(NAME)
$(BUILD_DIR)/%.c.o: %.c
@echo Compiling $@
@mkdir -p $(dir $@)
@$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
$(LIB):
@$(MAKE) -C lib/libft
@echo Libft done
clean:
@rm -rf $(BUILD_DIR)
@$(MAKE) -C lib/libft clean
@echo Clean done
fclean:
@rm -rf $(BUILD_DIR)
@rm -f $(NAME)
@$(MAKE) -C lib/libft fclean
@echo Fclean done
re: fclean
@$(MAKE) -j$(NPROC) $(NAME)
.PHONY: all clean fclean re