-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
65 lines (52 loc) · 1.62 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
NAME = mpsh
FOLDER_SRC = src/
FOLDER_TYPES = src/types/
FOLDER_LP = src/lp/
ALL_FOLDERS = $(FOLDER_SRC) $(FOLDER_LP) $(FOLDER_TYPES)
FILES_SRC = utils.c env.c builtin.c \
command.c completion.c \
parsing.c main.c
FILES_TYPES = array.c list.c \
hashmap.c hashset.c
FILES_LP = lexer.c parser.c
FILES_YF = lexer.l parser.y
FILES_SRC_FP = $(addprefix $(FOLDER_SRC), $(FILES_SRC))
FILES_TYPES_FP = $(addprefix $(FOLDER_TYPES), $(FILES_TYPES))
FILES_LP_FP = $(addprefix $(FOLDER_LP), $(FILES_LP))
FILES_YP_FP = $(addprefix $(FOLDER_LP), $(FILES_YF))
FILES = $(FILES_TYPES_FP) $(FILES_SRC_FP) $(FILES_LP_FP)
LDLIBS = -lreadline -std=gnu99
LDLIBS_OBJ =
OBJ = $(FILES:%.c=%.o)
DEPNAME = $(OBJ)
CC = gcc
LEX = flex
YACC = bison
FLAGS = -Wall -Wextra -Wno-unused-parameter -g $(foreach d, $(ALL_FOLDERS), -I $(d))
all: gen $(NAME)
gen:
@echo "Generating lexer"
@$(LEX) -t src/lp/lexer.l > src/lp/lexer.c
@echo "Lexer generated in src/lp/lexer.c"
@echo "Generating parser"
@$(YACC) -d src/lp/parser.y -o src/lp/parser.c
@echo "Parser generated in src/lp/parser.c"
@echo "Start compiling objects"
@echo "Compiling lexer"
@$(CC) $(FLAGS) -c src/lp/lexer.c -o src/lp/lexer.o $(LDLIBS) $(LDLIBS_OBJ)
@echo "Compiling parser"
@$(CC) $(FLAGS) -c src/lp/parser.c -o src/lp/parser.o $(LDLIBS) $(LDLIBS_OBJ)
%.o: %.c
@echo "Compiling $?"
@$(CC) $(FLAGS) -c $? -o $@ $(LDLIBS) $(LDLIBS_OBJ)
$(NAME): $(DEPNAME)
@echo "Build excutable $(NAME)"
@$(CC) $(FLAGS) $(OBJ) -o $(NAME) $(LDLIBS)
@echo "Done."
clean:
@echo "Clean objects"
@rm -rf $(OBJ) $(FILES_LP_FP)
fclean: clean
@echo "Clean executable $(NAME)"
@rm -rf $(NAME)
re: fclean all