]> git.lizzy.rs Git - rust.git/blob - mk/grammar.mk
doc: "mut" not needed for the examples
[rust.git] / mk / grammar.mk
1 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 BG = $(CFG_BUILD_DIR)/grammar/
12 SG = $(S)src/grammar/
13 B = $(CFG_BUILD_DIR)/$(CFG_BUILD)/stage2/
14 L = $(B)lib/rustlib/$(CFG_BUILD)/lib
15 LD = $(CFG_BUILD)/stage2/lib/rustlib/$(CFG_BUILD)/lib/
16 RUSTC = $(STAGE2_T_$(CFG_BUILD)_H_$(CFG_BUILD))
17 ifeq ($(CFG_OSTYPE),apple-darwin)
18         FLEX_LDFLAGS=-ll
19 else
20         FLEX_LDFLAGS=-lfl
21 endif
22
23 # Run the reference lexer against libsyntax and compare the tokens and spans.
24 # If "// ignore-lexer-test" is present in the file, it will be ignored.
25 #
26 # $(1) is the file to test.
27 define LEXER_TEST
28 grep "// ignore-lexer-test" $(1) ; \
29   if [ $$? -eq 1 ]; then \
30    CLASSPATH=$(B)grammar $(CFG_GRUN) RustLexer tokens -tokens < $(1) \
31    | $(B)grammar/verify $(1) ; \
32   fi
33 endef
34
35 $(BG):
36         $(Q)mkdir -p $(BG)
37
38 $(BG)RustLexer.class: $(BG) $(SG)RustLexer.g4
39         $(Q)$(CFG_ANTLR4) -o $(BG) $(SG)RustLexer.g4
40         $(Q)$(CFG_JAVAC) -d $(BG) $(BG)RustLexer.java
41
42 check-build-lexer-verifier: $(BG)verify
43
44 ifeq ($(NO_REBUILD),)
45 VERIFY_DEPS :=  rustc-stage2-H-$(CFG_BUILD) $(LD)stamp.rustc
46 else
47 VERIFY_DEPS :=
48 endif
49
50 $(BG)verify: $(BG) $(SG)verify.rs $(VERIFY_DEPS)
51         $(Q)$(RUSTC) --out-dir $(BG) -L $(L) $(SG)verify.rs
52
53 ifdef CFG_JAVAC
54 ifdef CFG_ANTLR4
55 ifdef CFG_GRUN
56 check-lexer: $(BG) $(BG)RustLexer.class check-build-lexer-verifier
57         $(info Verifying libsyntax against the reference lexer ...)
58         $(Q)$(SG)check.sh $(S) "$(BG)" \
59                 "$(CFG_GRUN)" "$(BG)verify" "$(BG)RustLexer.tokens"
60 else
61 $(info cfg: lexer tooling not available, skipping lexer test...)
62 check-lexer:
63
64 endif
65 else
66 $(info cfg: lexer tooling not available, skipping lexer test...)
67 check-lexer:
68
69 endif
70 else
71 $(info cfg: lexer tooling not available, skipping lexer test...)
72 check-lexer:
73
74 endif
75
76 $(BG)lex.yy.c: $(SG)lexer.l $(BG)
77         @$(call E, flex: $@)
78         $(Q)$(CFG_FLEX) -o $@ $<
79
80 $(BG)lexer-lalr.o: $(BG)lex.yy.c $(BG)parser-lalr.tab.h
81         @$(call E, cc: $@)
82         $(Q)$(CFG_CC) -include $(BG)parser-lalr.tab.h -c -o $@ $<
83
84 $(BG)parser-lalr.tab.c $(BG)parser-lalr.tab.h: $(SG)parser-lalr.y
85         @$(call E, bison: $@)
86         $(Q)$(CFG_BISON) $< --output=$(BG)parser-lalr.tab.c --defines=$(BG)parser-lalr.tab.h \
87                 --name-prefix=rs --warnings=error=all
88
89 $(BG)parser-lalr.o: $(BG)parser-lalr.tab.c
90         @$(call E, cc: $@)
91         $(Q)$(CFG_CC) -c -o $@ $<
92
93 $(BG)parser-lalr-main.o: $(SG)parser-lalr-main.c
94         @$(call E, cc: $@)
95         $(Q)$(CFG_CC) -std=c99 -c -o $@ $<
96
97 $(BG)parser-lalr: $(BG)parser-lalr.o $(BG)parser-lalr-main.o $(BG)lexer-lalr.o
98         @$(call E, cc: $@)
99         $(Q)$(CFG_CC) -o $@ $^ $(FLEX_LDFLAGS)
100
101
102 ifdef CFG_FLEX
103 ifdef CFG_BISON
104 check-grammar: $(BG) $(BG)parser-lalr
105         $(info Verifying grammar ...)
106         $(SG)testparser.py -p $(BG)parser-lalr -s $(S)src
107
108 else
109 $(info cfg: bison not available, skipping parser test...)
110 check-grammar:
111
112 endif
113 else
114 $(info cfg: flex not available, skipping parser test...)
115 check-grammar:
116
117 endif