Calling flex from a makefile

前端 未结 4 1279
醉酒成梦
醉酒成梦 2021-01-28 10:39

I would like to call flex to build a .l file, then call gcc to build everything.

I tryed:

comp:
    lex scanner.l   \\
    gcc -o a.out main.c hash.c -I.         


        
4条回答
  •  遥遥无期
    2021-01-28 11:22

    Try this:

    lex.yy.c: scanner.l
        lex scanner.l
    
    comp: main.c hash.c
        gcc -o a.out main.c hash.c -I.
    
    main.c: lex.yy.c
    

    The first rule set tells make that lex.yy.c needs to be rebuilt any time scanner.l changes and provides the command to recreate lex.yy.c. The second rule set tells make that the fake target comp depends on main.c and hash.c. If either file changes, then invoking make comp will cause a recompile. The last line is a stand-alone dependency that tells make to consider main.c as dirty any time that lex.yy.c changes. It will also force an invocation of make comp to create lex.yy.c if it does not exist.

提交回复
热议问题