-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
108 lines (80 loc) · 2.36 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
########################################################################
# tools
########################################################################
CC = gcc
YACC = bison
LEX = flex
AR = ar
########################################################################
# flags
########################################################################
# cflags
DEBUG = -g
ERROR = -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-function
PEDANTIC = -pedantic -pedantic-errors
STANDARD = -std=gnu99
OPTIMIZATION = -O3
CFLAGS = $(DEBUG) $(ERROR) $(PEDANTIC) $(STANDARD) $(OPTIMIZATION)
ARFLAGS = rcs
YFLAGS = -vyd
LFLAGS =
########################################################################
# files
########################################################################
# Source Directories
SRC_DIR = src
INCLUDE_DIR = include
LIB_DIR = lib
EXAMPLES_DIR = examples
# Test Directories
RCOMP_DIR = spec/rcomp
CHECK_DIR = spec/check
# Install Directories
INSTALL_PREFIX = /usr/local
# Sources
LIBMT_SRCS = $(wildcard $(SRC_DIR)/*.c)
# Objects
LIBMT_OBJS = $(addprefix $(SRC_DIR)/,mt_parser.o mt_lexer.o) $(LIBMT_SRCS:.c=.o)
########################################################################
# targets
########################################################################
all: libmt
libmt: $(LIB_DIR)/libmt.a
# Library Target
$(LIB_DIR)/libmt.a: $(LIBMT_OBJS)
$(AR) $(ARFLAGS) $@ $(LIBMT_OBJS)
# Parser Target
$(SRC_DIR)/mt_parser.o: $(SRC_DIR)/marktab.y
$(YACC) $(YFLAGS) $< -o $(SRC_DIR)/mt_parser.c
$(CC) $(CFLAGS) -c $(SRC_DIR)/mt_parser.c -o $@
@rm $(SRC_DIR)/mt_parser.c
# Lexer Target
$(SRC_DIR)/mt_lexer.o: $(SRC_DIR)/marktab.l
$(LEX) $(LFLAGS) -o $(SRC_DIR)/mt_lexer.c $<
$(CC) $(CFLAGS) -c $(SRC_DIR)/mt_lexer.c -o $@
@rm $(SRC_DIR)/mt_lexer.c
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Test Targets
test: rebuild check_test
check_test:
make -C $(CHECK_DIR) rebuild
# Example Targets
examples: libmt
make -C $(EXAMPLES_DIR)
# Clean Targets
clean: clean_build clean_test clean_examples
clean_build:
rm -f $(addprefix $(SRC_DIR)/,*.o mt_lexer.* mt_parser.*)
rm -f $(LIB_DIR)/libmt.a
clean_test:
make -C $(CHECK_DIR) clean
clean_examples:
make -C $(EXAMPLES_DIR) clean
rebuild: clean all
install: libmt
install -d $(INSTALL_PREFIX)/lib
install $(LIB_DIR)/libmt.a $(INSTALL_PREFIX)/lib/libmt.a
uninstall:
rm -f $(INSTALL_PREFIX)/lib/libmt.a
.PHONY: clean test