I am trying to compile my program which has a lex file and a yacc file and a couple of C files.I came across this example in the Flex manual.
I have a couple of questions regarding this makefile.It doesn't specify a compiler such as gcc
how does the makefile know how to create the targets such as scan.o
and parse.o
and 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
答案 0 :(得分:4)
这是一个Makefile功能:存在一些隐式规则,并记录在https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#Catalogue-of-Rules
中在您的情况下,相关部分是
编译C程序
n.o是从n.c自动生成的,其形式为'$(CC)$(CPPFLAGS)$(CFLAGS)-c'。
[...]
Yacc for C program
通过使用配方'$(YACC)$(YFLAGS)'运行Yacc,从n.y自动生成。
Lex for C program
n.c是通过运行Lex从n.l自动生成的。实际配方是'$(LEX)$(LFLAGS)'。
根据https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_12.html,一些规则不可移植......