-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
44 lines (28 loc) · 1.1 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
SRC := ./src
BUILD := ./build
INCLUDE := ./include
# Où copier l'exécutable (~/.local/bin est dans mon $PATH)
BIN_PATH := ~/.local/bin
C_FLAGS := -I $(INCLUDE) -Wall -g
C_LIBS := -lfl
# parser.c et lexer.c sont générés par bison et flex.
C_FILES := $(wildcard $(SRC)/*.c) $(SRC)/parser.c $(SRC)/lexer.c
HEADERS := $(wildcard $(INCLUDE)/*.h) $(INCLUDE)/parser.h
OBJS := $(patsubst $(SRC)/%.c, $(BUILD)/%.o, $(C_FILES))
.PHONY: clean
arc: $(OBJS)
gcc $(C_FLAGS) $^ -o $@ $(C_LIBS)
# cp arc $(BIN_PATH)
# Un fichier objet dépend de sa source mais également des headers.
# Ainsi si un header est modifié on recompile tous les objets pour être
# sûrs que les changements soient bien appliqués partout
$(BUILD)/%.o: $(SRC)/%.c $(HEADERS)
gcc $(C_FLAGS) -c $< -o $@ $(C_LIBS)
# Règles pour le parser et le lexer
$(SRC)/parser.c $(INCLUDE)/parser.h: $(CURDIR)/src/parser.y
bison -d -o $(SRC)/parser.c $< -Wcounterexamples
mv $(SRC)/parser.h $(INCLUDE)
$(SRC)/lexer.c: $(SRC)/lexer.lex $(INCLUDE)/parser.h
flex -o $@ $<
clean:
rm ./build/* arc $(SRC)/lexer.c $(SRC)/parser.c $(INCLUDE)/parser.h