Successful completion of this assignment prior to submitting the first programming assignment is mandatory.
This assignment takes the student through a review of topics in Unix, Emacs, g++, and Make that represent essential skills for the course, and creates some directories, links, and Unix shell commands that will also be needed. Most of this material is a review from previous courses. The grading is pass/fail. The material will be covered on exams.
Homework 0 is divided into two parts. The first deals with basics of Unix and file editing. The second deals with compiling with g++ and project build with make.
Educational Objectives: After completing part a, the student should be able to accomplish the following:
Operational Objectives:
Deliverables: One file hw0a.txt, to be submitted after completing Part b.
If you have not obtained a CS account, do so now at http://system.cs.fsu.edu/. You will not be able to continue until you have an active CS account. You will also need a secure shell login. See the course organizer for access to SSH software.
Log in to your CS account. In your home directory, create a directory named cop4530. From within this directory, create subdirectories named as follows:
hw0 hw1 hw2 hw3 hw4 proj1 proj2 proj3
Change permissions for all of the directories to 700 by issuing the command
chmod 700 *
Read and understand aboutthis command in the on-line Unix manual pages (man chmod).
Create a symbolic link to the course home directory by issuing the following command:
ln -s /home/courses/cop4530p/spring11 cop4530p
This should create a link from "cop4530p" to the course library files. Now a long listing of your cop4530 directory should produce something like the following:
lrwxrwxrwx 1 username CS-Course 31 Dec 7 12:52 cop4530p -> /home/courses/cop4530p/spring11 drwx------ 2 username CS-Course 512 Dec 7 12:54 hw0 drwx------ 2 username CS-Course 512 Dec 7 12:54 hw1 drwx------ 2 username CS-Course 512 Dec 7 12:54 hw2 drwx------ 2 username CS-Course 512 Dec 7 12:54 hw3 drwx------ 2 username CS-Course 512 Dec 7 12:54 hw4 drwx------ 2 username CS-Course 512 Dec 7 12:54 proj1 drwx------ 2 username CS-Course 512 Dec 7 12:54 proj2 drwx------ 2 username CS-Course 512 Dec 7 12:54 proj3
The symbolic link is in effect a short cut over to the course library for use in file manipulation commands, such as cd and cp.
Get back into your home directory (issue the command cd with no argument). Unless you already have a customized setup for emacs, do the following three commands:
You may also wish to set emacs to correctly indent braces in code - see the FAQ for details on how to accomplish this.
Remaining in your home directory, issue the command
ls -al
This will show a long (-l) listing (ls) of all (-a) of the contents of the directory, including those items that are normally ignored by the ls command. Get into your directory named .bin. (Create ~/.bin if it does not already exist.) Using emacs, create a file named clean with the following contents:
#!/bin/sh rm $1/*~ rm $1/*.o rm $1/*.x
Then issue the command
chmod 700 clean
What you have just accomplished is the creation of a Unix script clean that executes from the command line. This command takes one argument (denoted by $1 in the code) intended to be a directory (or path). Execution of the command will safely remove all of the Emacs backup files (ending in "~"), object code files (ending in ".o"), and executables (which will end in ".x" by convention in this course) from the directory. This is very handy to keep from cluttering your work space.
Copy the following two files from ~/cop4530/cop4530p/examples/scripts into .bin: c4530 and co4530. (Assuming you are still in the .bin directory, these copies should be created by the following command:
cp ~cop4530p/spring11/examples/scripts/* .
Change the permissions on these files so that they are executable, as described above for your clean command. Also, look at these files using emacs. What does c4530 do? What does co4530 do? (To answer these questions, look at the manual for g++ by entering the command man g++.) Finally, issue the command hash or, if that is an unknown command, rehash, which will incorporate the three new commands into your login session. (This will happen automatically in all new login sessions.)
This is the documentation phase of the assignment, to be completed inside your subdirectory ~/cop4530/hw0.
Use Emacs to create a text file named hw0a.txt. Type the following information at the top of this file:
COP 4530 Spring 2011 Homework Assignment 0 (Your Name) CS Username: (Your CS Username - used for login to CS account) FSU Username: (Your ACNS Username - used for login to Blackboard)
Save the file and close Emacs. Issue the command
clean .
Open the file hw0a.txt with Emacs in one window, and open a second window to the same directory. In this second window, you will issue commands and copy/paste the resulting screen output into hw0a.txt. Specifically:
Copy/paste screen output into hw0a.txt that documents each of following commands:
Save and close the file, but do not submit. It will be part of the material submitted after completing part b.
Educational Objectives: After completing part b, the student should be able to accomplish the following:
Operational Objectives: This assignment consists of a sequence of steps performed with a Unix login session. To document your completion of these steps, copy/paste the screen results into a file named hw0b.txt through emacs. The result should be a makefile for managing the build of the Square1 game.
Deliverables: Five (5) files: hw0a.txt, hw0b.txt, makefile, makefile2, square1.cpp
Create two logins to your CS account, one on shell and one on linprog. (These will be two separate text windows.) In each login window, change to the directory cop4530/hw0 that you already created as part of Homework 0a. Complete the rest of this assignment inside this subdirectory.
Use the shell login and Emacs to create a text file named hw0b.txt. Type the following information at the top of this file:
COP 4530 Spring 2011 Homework Assignment 0b (Your Name) CS Username: (Your CS Username - used for login to CS account) FSU Username: (Your ACNS Username - used for login to Blackboard)
Use the linprog login to copy the file tests/ftvector.cpp into the hw0 directory. Try to compile this into an executable using g++:
g++ ftvector.cpp
What goes wrong? Try again with the command
c4530 ftvector
What file is created by the second command? Explain why the second command works and the first does not.
Clean (clean .) the directory and issue the commands
co4530 ftvector g++ -o test.x ftvector.o
What files are created? Run the executable, and try to make sense out of the interface. This is a test program for the TVector<char> container, which we will study in the next couple of weeks.
Copy the following files into your assignment directory:
hw0/square1.cpp cpp/integer.h cpp/integer.cpp tcpp/tvector.h tcpp/tvector.cpp
Issue the following commands
g++ -c -I. square1.cpp g++ -c -I. integer.cpp g++ -ogame.x square1.o integer.o
What new files are created? Try playing the game by running the executable.
Now remove the files tvector.h and tvector.cpp, and repeat the three commands. What happens? Use emacs to look inside the remaining files to arrive at an explanation. Issue the following modified commands:
g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/tcpp square1.cpp g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/tcpp integer.cpp g++ -ogame.x square1.o integer.o
What is the effect of the modified commands? Look at the on-line manual for g++ and its parent gcc (type man g++ and then man gcc) to find out about the -I, -W, and -Wall flags, and explain why these new commands work.
Now remove the files integer.h and integer.cpp from your directory and issue the commands:
g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/cpp -I/home/courses/cop4530p/spring11/tcpp square1.cpp g++ -Wall -Wextra -c -I. -I/home/courses/cop4530p/spring11/cpp -I/home/courses/cop4530p/spring11/tcpp /home/courses/cop4530p/spring11/cpp/integer.cpp g++ -ogame.x square1.o integer.o
What happens? Why? (Play the game some more, and copy/paste a bit of this play screen into hw0b.txt.)
Now remove the object and executable files (using clean .) and issue these commands:
co4530 square1 co4530 /home/courses/cop4530p/spring11/cpp/integer g++ -ogame.x square1.o integer.o
What is the effect of these commands? Which are easier, the raw g++ commands or these customized command line scripts?
Now we are ready to create a "simple" makefile named makefile. Start by copying the file ~cop4530p/spring11/hw0/makefile.partial to ~/cop4530/hw0/makefile. Edit this file, following the hints provided by the documentation. The idea is to accomplish two things:
clean .
created in Homework 0a. Now from inside your Emacs session, place your cursor where you would like the makefile to be placed and enter this Emacs command:
Ctrl-X i makefile
This will place the makefile in the document.
Finally we are ready to create the kind of makefile you will need for your programming projects. This makefile, named makefile2, will do essentially the same things as the simple one, but it will be more flexible through the use of macros. Begin by copying hw0/makefile2.partial to hw0/makefile2. Edit this file, using the completed lines as a guide, until it properly creates game.x. Be sure to use the macros to define the various paths that are hard-coded in the first makefile. Build with this makefile using the command:
make -f makefile2
Keep trying until this command builds the executable without error messages. (See note above about cleaning old object and executable files when testing.)
Here are some experiments to illustrate some of the benefits of using makefiles.
Submit the files hw0a.txt, hw0b.txt, makefile, makefile2, square1.cpp using the project submit system:
yourname@shell:~/cop4530/hw0>hw0submit.sh Changing directory to .... Archiving... a makefile 1K a makefile2 1K a square1.cpp 3K a hw0a.txt 2K a hw0b.txt 2K Sending mail... Cleaning up... yourname@shell:~/cop4530/hw0>
Submit scripts do not work on the program and linprog servers, because they do not suipport email. To see what happens if you try, try it: From your program login, enter the command hw0submit.sh.
Performance of each procedural step above should be documented in your file hw0b.txt. Documentation should either be a snippet of screen output or, where questions are asked, the answer to the question.
Each makefile should correctly produce two object code files square1.o and integer.o and one executable game.x.
The makefiles should use absolute path names for the course library (i.e., defined from the root /home/courses/...) and use relative self-reference for the assignment directory (i.e., ".").
Your documentation for playing game.x should show that you found an integer with "palindromic period" at least 25 (and not one of those listed in the documentation for square1.cpp). For example:
SQUARE1: Enter an Integer (0 to quit): 7801686 Successful on iteration 55. Found the following palindrom: 8834453324841674761484233544388
shows that the integer 7801686 yields the palindromic integer 8834453324841674761484233544388 after 55 steps (that is, it has palindromic period 55).