Lab 2: More Makefiles and Unix
Due: Sunday, Sept. 7, 2014 @ 5 p.m.
Description:
The
purpose of this assignment is to give you practice using the vi editor,
learning about and editing Makefiles and working in a Unix environment. All of the
work for this lab must be performed on mason. You must use Secure Shell to remotely log into your mason
account. Once you are logged in, you will start a script that will record all the commands and work that you do for the lab.
Background Preparation:
Review how to login to mason using ssh and how to move files to mason
using sftp or scp. Review Unix commands (man, cp, mkdir, mv, rm, cat,
ls,
etc.) and vi/vim commands introduced in class and/or lesson 1 of
vimtutor (moving around within the file (hjkl), editing text,
saving the file and exiting, etc.). It is also suggested that you
complete vimtutor
lesson 2.
Step by Step Instructions:
- Log into your mason account using ssh.
- Create in your home directory (if you haven't already) a directory named CS262
- Change to this directory.
- Create a directory named Lab2
- Change to this new directory (Lab2)
- Using
sftp or scp, copy the files found on Blackboard for the Lab2 assignment to
this new directory (you don't need to copy this html instruction page).
- Start a typescript with the following command: "script YourName.txt" (e.g. SarahBellum.txt)
- Use the Unix command that shows your current working directory
- Use the Unix command that shows the files contained in your current working directory
- Type the command to use the Makefile to compile the files in the directory
- Use
the command that shows the files in your current working directory
(there should be more files now). Note that the Makefile compiled only
one of the source (*.c) files. Note also that the Makefile created a
Dependencies file.
- Copy the Makefile to a file named Makefile.orig (You will be editing Makefile and at the end, comparing it to Makefile.orig)
- Use vi or vim to edit the Makefile:
- Add these comments at the top of the Makefile
- # YourName and Lab Section
- # CS262 Lab 2 Makefile
- Modify the Makefile so that the other source files that are part of Lab2 will also be compiled when using the make command:
- Currently, there is one executable that is created. It is created using the following lines in the Makefile:
- $(TARGET): objs
${CC} ${CFLAGS} -o $@ $(OBJS) $(LIB)
- These
lines show how the "variables" which are set higher in the makefile are
used. You will create similar lines to compile the other executables
- In
the Makefile, comment out the two lines shown above. Make sure the
comment character (#) is in the first column for both lines.
- Copy and paste three times these same two lines:
- Make sure you are in command mode in vi and put the cursor anywhere on the first line of the two
- type "3yy" (this "yanks" or copies three lines)
- type "PPP" (capital P "puts" one set of the yanked lines above the line where the cursor is)
- Move your cursor to the top set of the two lines. Uncomment them.
- In the first line, change the $(TARGET) to "word-count" (without quotes)
- In the second line, change the $(OBJS) to "word-count.o"
- Repeat the preceding three steps replacing "digit-count" and "gmu_pi" for "word-count."
- Add the following executable names to the TARGET variable definition: digit-count gmu_pi (use whitespace to separate the names).
- Add
the following source file names to the SRCS variable definition:
digit-count.c gmu_pi.c (use whitespace to separate the names).
- Create
a new target named "cleanall." This target will remove all *.o,
dependency and executable files. Base this new target off of the
current "clean" target.
- Save your changes and exit the vi editor
- Compile
all the executables using the Makefile. If there are any errors, return
to the previous step and make corrections until all executables are
compiled correctly
- Use the Unix command that shows the files contained in your current working directory (including all the new executable files)
- Use the Unix command print the text contained in Dependencies to the screen
- Run all the executables in this order: word, gmu_pi, digit
- List the files in your directory
- Type "make" again. Notice that the files are up to date and no action is made.
- Edit gmu_pi.c using vi/vim by adding a comment at the top that contains your name and lab section. Save and exit.
- Check
the timestamps of gmu_pi.c and gmu_pi by typing the following command
"ls -l gmu_pi.c gmu_pi" (without quotes). Notice that gmu_pi.c is more
recent than the executable gmu_pi.
- Type "make" again. Notice that since gmu_pi.c is more recent than gmu_pi, the executable is recreated.
- Type the command "make clean"
- List the files in your directory
- Use the Unix command print the text contained in your modified Makefile to the screen
- Use the "diff" command to compare the differences between your new Makefile and the original makefile you saved.
- Type the command "make cleanall"
- List the files in your directory
- Exit the script
Submission: Verify that your script file was created correctly by using the more (or less)
command (your choice) to see the contents of the file. Informatin on
these commands can be obtained by using the manual pages ("man
more" or "man less"). Once you are sure the file is correct, copy
the script file and Makefile back to your local computer and submit
both of them to Blackboard as Lab 2.
**
Note: This
lab is required to be performed completely on Mason. Please be
prepared to continue to do this whenever required. In future,
however, we
may allow you to use other C environments with which to
develop your
code. For information on the various C compiler options available
and
how to access them, please see the posted slides and accompanying
reference guides. Even for programs where you are permitted to
develop
the code in another environment, you still must be sure it compiles
properly on the Mason cluster. Therefore, if you decide to use a
different development environment, you must be familiar with using sftp
to transport your files to and from the Mason system.