generate a.out from lex file using makefile

2019-07-18 08:23发布

问题:

I have auto.lex and I want to generate a.out of this file .

I tried -

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

lex.yy.c: auto.lex
    flex -c auto.lex

but it not worked .

EDIT:

changed to -

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

and fixed .

回答1:

The recommend suffix for lex files is .l. GNU make has a builtin rule .l.c that creates C code from a lex source. Thus, if you want to create an executable auto from auto.l, you don't need a makefile at all. Just type 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