Homework 6
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.
Rewrite the following make rule to use an automatic variable in the command. (1~pt.)
file.o: file.cpp g++ -c file.cpp
- Rewrite the same rule as a pattern matching rule that compiles any
.cpp
file into a.o
file. (1~pt.) - Rewrite the same rule as a suffix rule that compiles any
.cpp
file into a.o
file. (1~pt.) Note: you can find information about suffix rules in make's manual. Why do pattern matching rules need automatic variables? Why can't they just use a plain filename in their command? (1~pt.)
The files in the current directory are listed below with their timestamps. A higher number means the file is newer.
Time Stamp File Name 2 file.o 1 file1.cpp 3 file2.cpp If the following make rule is run what are the values of the following variables?
file.o: file1.cpp file2.cpp echo $< echo $^ echo $?
- $< (1~pt.)
- $^ (1~pt.)
- $? (1~pt.)
- \What does the VPATH variable do? The VPATH was discussed in lecture and is also discussed in make's manual. (1~pt.)
- If the VPATH variable has multiple directories in it you may not know in what directory a particular file will be found. What is the advantage of automatic variables in this case? (1~pt.)
- What is an implicit rule? (1~pt.)
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.