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:

  1. Log into your mason account using ssh.
  2. Create in your home directory (if you haven't already) a directory named CS262
  3. Change to this directory.
  4. Create a directory named Lab2
  5. Change to this new directory (Lab2)
  6. 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).
  7. Start a typescript with the following command: "script YourName.txt" (e.g. SarahBellum.txt)
  8. Use the Unix command that shows your current working directory
  9. Use the Unix command that shows the files contained in your current working directory
  10. Type the command to use the Makefile to compile the files in the directory
  11. 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.
  12. Copy the Makefile to a file named Makefile.orig (You will be editing Makefile and at the end, comparing it to Makefile.orig)
  13. Use vi or vim to edit the Makefile:
    1. Add these comments at the top of the Makefile
    2. Modify the Makefile so that the other source files that are part of Lab2 will also be compiled when using the make command:
    3. Save your changes and exit the vi editor
  14. 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
  15. Use the Unix command that shows the files contained in your current working directory (including all the new executable files)
  16. Use the Unix command print the text contained in Dependencies to the screen
  17. Run all the executables in this order: word, gmu_pi, digit
  18. List the files in your directory
  19. Type "make" again. Notice that the files are up to date and no action is made.
  20. Edit gmu_pi.c using vi/vim by adding a comment at the top that contains your name and lab section. Save and exit.
  21. 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.
  22. Type "make" again. Notice that since gmu_pi.c is more recent than gmu_pi, the executable is recreated.
  23. Type the command "make clean"
  24. List the files in your directory
  25. Use the Unix command print the text contained in your modified Makefile to the screen
  26. Use the "diff" command to compare the differences between your new Makefile and the original makefile you saved.
  27. Type the command "make cleanall"
  28. List the files in your directory
  29. 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.