使用makefile从lex文件生成a.out

我有auto.lex ,我想生成此文件的a.out

我试过了 –

 a.out: lex.yy.c gcc -c lex.yy.c lex.yy.c: auto.lex flex -c auto.lex 

但它不起作用。

编辑:

变成 –

 a.out: lex.yy.c gcc lex.yy.c lex.yy.c: auto.lex flex auto.lex 

并修复。

lex文件的推荐后缀是.l 。 GNU make有一个内置规则.lc ,它从lex源创建C代码。 因此,如果要从auto.l创建可执行文件auto ,则根本不需要makefile。 只需键入make auto

 $ make auto
 lex -t auto.l> auto.c
 cc -c -o auto.o auto.c
 cc auto.o -lfl -o auto
 rm auto.o auto.c