-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
69 lines (51 loc) · 1.2 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
# Name of the project
PROJ_NAME=cminus
# .c files
C_SOURCE=$(wildcard *.c)
# .h files
H_SOURCE=$(wildcard *.h)
# Object files
OBJ=$(C_SOURCE:.c=.o)
# Compiler
CC=gcc
# Flags for compiler
CC_FLAGS=-c \
-W \
-ansi
# compilation and linking
all: $(PROJ_NAME)
$(PROJ_NAME): cminus.tab.o lex.yy.o ast.o main.o
@ echo 'Building binary using GCC linker: $@'
$(CC) -o $@ $^
@ echo 'Finished building binary: $@'
@ echo ' '
cminus.tab.o: cminus.tab.c
@ echo 'Building target using GCC compiler: $<'
$(CC) $< $(CC_FLAGS)
@ echo ' '
lex.yy.o: lex.yy.c token.h
@ echo 'Building target using GCC compiler: $<'
$(CC) $< $(CC_FLAGS)
@ echo ' '
ast.o: src/ast.c
@ echo 'Building target using GCC compiler: $<'
$(CC) $< $(CC_FLAGS)
@ echo ' '
main.o: src/main.c
@ echo 'Building target using GCC compiler: $<'
$(CC) $< $(CC_FLAGS)
@ echo ' '
# flex and bison
lex.yy.c: src/cminus.l
@ echo 'Generating $@'
flex src/cminus.l
@ echo ' '
cminus.tab.c: src/cminus.y
@ echo 'Generating $@'
bison --defines=token.h src/cminus.y
cp token.h src/
cp src/ast.h ast.h
@ echo ' '
clean:
rm -rf *.o *~ lex.yy.c cminus.tab.* ast.h token.h src/token.h $(PROJ_NAME)
.PHONY: all clean