Utilizing the Make Command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

[list]
]Compile cpp2html.c to produce cpp2html.o.
( Important: the source code in these files is C, not C++, and so must be compiled and linked with gcc, not g++.)

[list]
Run the command

flex cppscanner.l

to produce the file lex.yy.c from the language description in cppscanner.l.

[list]
Compile lex.yy.c to produce lex.yy.o. (This often produces a warning message about extra tokens. Ignore it.)

[list]
Link the the .o files to produce an executable program named cpp2html

[list]
Write a makefile that will carry out these steps. Your makefile should result in only the minimum required amount of steps when any input file to this process is changed.

  1. Relevant commands, code, scripts, algorithms:
    just unix commands

  2. The attempts at a solution (include all code and scripts):

my makefile

cpp2html.o: cpp2html.c
                gcc -g -DDEBUG -c cpp2html.c
lex.yy.o: lex.yy.c 
            gcc -g -DDEBUG -c lex.yy.c
cpp2html: cpp2html.o lex.yy.o
             gcc -g -DDEBUG -o cpp2html.o lex.yy.o
             mv a.out cpp2html
The error given is your makefile does not build 'cpp2htm' when invoked:
gcc -g -DDEBUG -c cpp2html.c

Ive tried calling the flex command in the 'make' command line, is that the right process?
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Old Dominion University,Norfolk(VA), USA, Mr. Zeil, CS 252

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

If you don't tell it the target you want, make considers the first rule given to be the product you want. That's why it was making cpp2html.o, just because it was at the top of the file. Try telling it 'make cpp2html' and it would do it if your makefile was correct.

Your makefile is a little overspecified -- you don't need to tell it how to make .o files.

Your compile line is wrong too, -c makes .o files, and you don't want gcc making an .o file in the linking step. And you don't have to do a mv after if you tell gcc what file to make in the first place.

I would simplify it down to this:

CFLAGS=-g -DDEBUG

cpp2html: cpp2html.o lex.yy.o
             gcc cpp2html.o lex.yy.o -o $@

Also, no, it is not right to give it the flex command in the commandline. It should be in your makefile. Show me what you run to generate lex.yy.o and I'll show how to incorporate it into your makefile.