Homework 5

If you need more information about the GNU make system, you can find its manual at http://www.gnu.org/software/make/manual/make.html. For instance, you may find the section entitled An Introduction to Makefiles helpful.

  1. What are the three parts of a make rule? (1 pt.)
  2. Describe one way in which a makefile is different from a shell script. (1~pt.)
  3. Write a rule to compile file.cc into file.o with the command g++ -c file.cc such that the compilation happens only if file.cc is newer than file.o. (1~pt.)
  4. What does it mean for a target to be phony? (1~pt.)
  5. Listed below is a makefile for an imaginary programming language. Draw the dependency graph of that makefile. Hint, clean is a target, and should have a node in the graph. Does clean have any dependencies? Is anything dependent on it? (2~pt.)

    executable: file1.x file2.x common.s
        compile file1.x file2.x -s common.s
    file1.x: file1.p file1.s
        compile file1.p -s file1.s
    file2.x: file2.p common.s
        compile file2.p -s common.s
    clean:
        rm executable file1.x file2.x
  6. Listed below are the files being built by this makefile with their time stamps. The larger a number, the newer a file. I am about to run make on the above makefile. For each rule, tell me whether its action will be run. (1~pt.ea.)

    Time Stamp File Name
    3 executable
    7 file1.x
    6 file2.x
    5 file1.p
    2 file2.p
    4 file1.s
    8 common.s

Submission

Please create a text file (not MS Word, not PDF, just plain text) for your answers and a PDF file for your drawing for question 5. Place both files in an archive and upload the archive to the moodle.