-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
67 lines (53 loc) · 1.43 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
NAME = ls
EXT =
CC = clang
RM = rm -f
MKDIR = mkdir -p
DEBUG = 0
ifeq ($(DEBUG), 1)
DEBUG_FLAGS = -fsanitize=address -g
else
MAKEFLAGS = -j --output-sync=recurse --no-print-directory
DEBUG_FLAGS = -O2 -flto -fPIE
endif
WARNING_FLAGS = -Wall -Wextra -Werror -Wpointer-arith -Wfloat-equal -fpermissive
PROTECT_FLAGS = -fno-exceptions -fstack-protector-all
COMMON_FLAGS = -std=c99 -MMD -pipe
CFLAGS = $(DEBUG_FLAGS) $(COMMON_FLAGS) $(PROTECT_FLAGS) $(WARNING_FLAGS)
BIN_DIR = bin
SRC_DIR = src
TESTS_DIR = tests
BUILD_DIR = build
INC_DIR = include
SRCS = src/main.c\
src/parser.c\
src/browsing.c\
src/directory.c\
src/entry.c\
src/print.c\
src/utils.c\
BIN_PATH = $(BIN_DIR)/$(NAME)
OBJS = $(subst $(SRC_DIR), $(BUILD_DIR), $(SRCS:%.c=%.o))
DEPS = $(OBJS:.o=.d)
VPATH = $(SRC_DIR):$(INC_DIR):$(BUILD_DIR)
CURRENT_DIR = $(shell pwd)
all: $(BIN_PATH)
$(BIN_PATH): $(OBJS)
@if [ ! -d $(dir $@) ] ; then $(MKDIR) $(dir $@); fi
$(CC) $(CFLAGS) -I $(INC_DIR) $(OBJS) -o $(BIN_PATH)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@if [ ! -d $(dir $@) ] ; then $(MKDIR) $(dir $@); fi
$(CC) $(CFLAGS) -I $(INC_DIR) -c $< -o $@
clean:
$(RM) $(OBJS)
$(RM) $(DEPS)
$(RM) -rd $(BUILD_DIR)
fclean: clean
$(RM) $(BIN_PATH)
$(RM) -rd $(BIN_DIR)
re:
$(MAKE) fclean
$(MAKE) all
-include $(DEPS)
-include $(TEST_DEPS)
.PHONY: all, clean, fclean, re