lex yacc 和 C 的简单 makefile
simple makefile for lex yacc and C
我正在尝试编译我的程序,它有一个 lex 文件和一个 yacc 文件,几个 C files.I 在 the Flex manual 中遇到了这个例子。
关于这个我有几个问题 makefile.It 没有指定编译器,例如 gcc
makefile 如何知道如何创建目标,例如 scan.o
和 parse.o
和 myprogram.o
?
# Makefile example -- scanner and parser.
# Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c"
#
LEX = flex
YACC = bison -y
YFLAGS = -d
objects = scan.o parse.o myprogram.o
myprogram: $(objects)
scan.o: scan.l parse.c
parse.o: parse.y
myprogram.o: myprogram.c
这是一个 Makefile 特性:存在一些隐式规则并记录在 https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#Catalogue-of-Rules
中
在你的情况下,相关部分是
Compiling C programs
n.o is made automatically from n.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.
[...]
Yacc for C programs
n.c is made automatically from n.y by running Yacc with the recipe ‘$(YACC) $(YFLAGS)’.
Lex for C programs
n.c is made automatically from n.l by running Lex. The actual recipe is ‘$(LEX) $(LFLAGS)’.
根据https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_12.html,有些规则不可移植...
我正在尝试编译我的程序,它有一个 lex 文件和一个 yacc 文件,几个 C files.I 在 the Flex manual 中遇到了这个例子。
关于这个我有几个问题 makefile.It 没有指定编译器,例如 gcc
makefile 如何知道如何创建目标,例如 scan.o
和 parse.o
和 myprogram.o
?
# Makefile example -- scanner and parser.
# Creates "myprogram" from "scan.l", "parse.y", and "myprogram.c"
#
LEX = flex
YACC = bison -y
YFLAGS = -d
objects = scan.o parse.o myprogram.o
myprogram: $(objects)
scan.o: scan.l parse.c
parse.o: parse.y
myprogram.o: myprogram.c
这是一个 Makefile 特性:存在一些隐式规则并记录在 https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#Catalogue-of-Rules
中在你的情况下,相关部分是
Compiling C programs
n.o is made automatically from n.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.
[...]
Yacc for C programs
n.c is made automatically from n.y by running Yacc with the recipe ‘$(YACC) $(YFLAGS)’.
Lex for C programs
n.c is made automatically from n.l by running Lex. The actual recipe is ‘$(LEX) $(LFLAGS)’.
根据https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_12.html,有些规则不可移植...