Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:28:40+00:00 2026-06-15T09:28:40+00:00

So I have to create a makefile that would generate the application described below

  • 0

So I have to create a makefile that would generate the application described below and make sure each generated file has its own rule.

For the makefile:
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:

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

i am not sure where to start with this problem

edit: what i have so far

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:28:41+00:00Added an answer on June 15, 2026 at 9:28 am

    You have to tell the make about the dependencies. For example, lex.yy.c depends on spec.l:

    lex.yy.c: spec.l
        flex spec.l
    

    The first line say lex.yy.c depends on spec.l. The second tells how to generate an updated version of lex.yy.c when spec.l is newer. We pretty much repeat that pattern with the other files. In the case of calledspec.y, we have two results that are produced from the same input/command. At least with GNU make, you can specify that like this:

    spec.tab.c spec.tab.h: calledspec.y
        bison -vd calledspec.y
    

    Then you pretty much repeat the process for dependencies of .o (or .obj, etc.) files on headers and C files:

    lex.yy.o: lex.yy.c spec.tab.h
       $(cc) -c lex.yy.c
    

    One final note: unless you specify otherwise, make will build the first target specified in the makefile, so you normally want to arrange it with the final executable first, and other targets after that:

    parser: lex.yy.o y.tab.o
        $(cc) -o parser lex.yy.o y.tab.o
    
    lex.yy.o: lex.yy.c spec.tab.h
        $(cc) -c lex.yy.c
    

    And so on. This only applies to targets though, not to macros, so you’ll typically see a few things like:

    cflags = -O2
    

    …at the beginning of a make file. Then the lines the invoke the compiler will use that, something like:

    lex.yy.o: lex.yy.c spec.tab.h
        $(cc) $(cflags) -c lex.yy.c
    

    And when this is executed, the cflags macro will be expanded, so the command that gets executed is gcc -O2 -c lex.yy.c (and it predefines cc to the name of the compiler it normally expects to use, so Microsoft’s make sets it to cl, GNU to gcc, etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have some C++ code that we need to create a make file in.
i have created a Makefile which i would change so, that it will generate
I have create a vcf file that contains contacts by using this code ContentResolver
I have a following directory structure, I also have this make file that works
I have some limited knowledge of GNU makefile that has failed me at the
I have a C project that has the following structure Main/ Makefile.am bin/ src/
I have a number of less file that I would like to compile using
I would like to have a makefile like this: cudaLib : # Create shared
Assume I have a make rule: .PHONY:gen gen: auto.template generate-sources auto.template that creates a
I have create a Java class extending LinearLayout as shown below public class CustomLinear

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.