This assignment deals with makefiles. I strongly recommend that you read the entire assignment through once, including the Important Notes section , before starting. Create a directory...

This assignment deals with makefiles.

I strongly recommend that you read the entire assignment through once,
including the Important Notes section, before starting.




  1. Create a directory
    ~/UnixCourse/makeAsst. Within that directory, create a pair of subdirectories,
    project1
    and
    project2


    Copy the .h and .cpp files from your earlier “Compilation” assignment (should be in
    ~/UnixCourse/compileAsst) into your
    project1directory.


    Copy all files from the
    ~cs252/Assignments/cpp2html/
    directory into your
    project2
    directory.




  2. In
    project1, create a makefile that will compile
    guess.cpp
    and
    yesno.cpp
    to produce the files
    guess.o
    and
    yesno.o, and will link those two
    .o
    files to produce an executable program named
    guess.


    This should occur in 3 discrete steps (compiling
    guess.cpp, compiling
    yesno.cpp, and linking the results).


    You may produce your makefile “from scratch” or as a modification of my self-updating makefile for single-program projects.


    Verify for yourself that the
    make
    command (with no arguments) does produce the desired program. (You can do this by issuing the
    make
    command directly at the command line, or via emacs’
    M-x compile
    command.)


    Once you have successfully got
    make
    to build the project, run it again. Note that
    make
    realizes that the project is already up-to-date and does not rerun any of the compilation commands.


    One big reason that we use
    make
    is because, on large projects consisting of many, many files, we want to avoing recompiling
    everything
    after changing just one or two files.
    make
    looks at what files have changed (by checking their modification dates - the dates you see when you do a
    ls -l
    command) and figures out the minimal number of steps required to rebuild the project based upon what has actually changed.


    Now make a trivial change to either
    guess.cpp
    or
    yesno.cpp, but not both. For example, add a blank line at the beginnign or end of the file. Then run
    make
    again and verify that your makefile really does recompile only the changed file.


    You can simulate a change to a file without actually changing its contents via the
    touch
    command, which alters a file’s modification date without altering the contents of the file. For example, if you do



    touch guess.cpp


    and then run
    make
    again, it should recompile
    guess.cpp, but not
    yesno.cpp.




  3. The code in
    project2
    is for a program that formats C++ code into HTML for presentation in a webpage. For example, here is the web page produced by running the command


    ./cpp2html < ~/unixcourse/compileasst/guess.cpp=""> guess.html

    (once the program has been successfully compiled, of course).


    This program would have been a massive undertaking to write in pure C or C++, but was actually put together quite quickly using a software tool called “flex” that was originally developed for use in building compilers. Whats interesting about
    flex
    is that it actually writes out the program code for a substantial portion of a compiler (the “scanner” or “lexical analyzer”) from a (relatively speaking) simple description of what the language being processed
    looks
    like.


    The steps necessary to produce this program are:




    1. Compile
      cpp2html.c
      to produce
      cpp2html.o. (
      Important:
      the source code in this project is C, not C++, and so must be compiled and linked with
      gcc, not
      g++.)




    2. Run the command


      flex cppscanner.l

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




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




    4. Link the the
      .o
      files to produce an executable program named
      cpp2html




    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. (Note: you will probably
    not
    be able to base this makefile upon my self-updating makefile as in the earlier part of the assignment. Instead, you will probably find it necessary to write this one from scratch.




  4. Give the command:


    ~cs252/bin/makeAsst

    to complete the assignment.




May 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here