Creating a Makefile, help

This is a discussion on Creating a Makefile, help within the Tech Board forums, part of the Community Boards category; Give a makefile (doesn't have to be a separate file - just what the contents would be) that would generate ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    50

    Creating a Makefile, help

    Give a makefile (doesn't have to be a separate file - just what the contents would be) that would generate the application described below. Be sure each generated file has its own rule.

    The first tool is flex, which takes a file called spec.l and generates a file called lex.yy.c. Another tool called bison expects a file calledspec.y and will generate the file spec.tab.c. If bison is called using the directives -vd, it will also generate a file called spec.tab.h (which is needed when compiling lex.yy.c). The two C files can be compiled into object files and then linked together with the yacc (-ly) and lex (-ll) libraries to generate the compiler (a.out.
    The makefile you describe must generate the following commands if you were starting just with spec.l and spec.y:

    Code:
    flex spec.l
    bison -vd spec.y
    gcc -c lex.yy.c
    gcc -c spec.tab.c
    gcc spec.tab.o lex.yy.o -ly -ll

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    A makefile entry looks like this
    Code:
    target : dependency
            rule
    Note that it is a TAB which indents rule, not spaces.

    So for example
    Code:
    lex.yy.c : spec.l
            flex spec.l
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    can u tell me if this is correct?

    compiler: spec.tab.o lex.yy.o
    gcc spec.tab.o lex.yy.o -ly –ll
    lex.yy.c: spec.l
    flex spec.l
    spec.tab.c: spec.y
    bison -vd spec.y
    spec.tab.o: spec.tab.c
    gcc -c spec.tab.c
    lex.yy.o: lex.yy.c spec.tab.h
    gcc –c lex.yy.c
    clean:
    rm –f *.c *.o a.out

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > can u tell me if this is correct?
    Hey, they're your files on your system, why don't you try it for yourself.

    If you type in say
    touch spec.y
    that will update the modification date of the file, to make it seem like you edited the file.

    Then you type
    make
    If you see all the expected things happening (bison + two gcc), then I'd say it's working.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile help
    By hansel13 in forum C Programming
    Replies: 4
    Last Post: 05-28-2010, 09:32 PM
  2. Creating a Makefile
    By Tom_Arch in forum C Programming
    Replies: 1
    Last Post: 04-26-2009, 05:51 AM
  3. creating two binary from 1 makefile
    By -EquinoX- in forum C Programming
    Replies: 1
    Last Post: 03-21-2009, 11:40 AM
  4. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM
  5. makefile
    By rahulsk1947 in forum C Programming
    Replies: 2
    Last Post: 04-27-2006, 09:12 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21