Homework 1b: Building a Project

Due 01/16/05

Educational Objectives: Experience building programs using command line statements and the make utility.

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 hw1b.txt through emacs.

Deliverables: Five (5) files: hw1a.txt, hw1b.txt, makefile, makefile2, square1.cpp

Procedural Requirements

  1. Create two logins to your CS account, one on shell and one on program. (These will be two separate text windows.) In each login window, change to the directory cop4530/hw1 that you already created as part of Homework 1a. Complete the rest of this assignment inside this subdirectory.

  2. Use the shell login and Emacs to create a text file named hw1b.txt. Type the following information at the top of this file:

    COP 4530 Spring 2005
    Homework Assignment 1b
    (Your Name)
    CS  Username: (Your CS Username   - used for login to CS account)
    FSU Username: (Your ACNS Username - used for login to Blackboard)
    

  3. Use the program login to copy the file tests/ftvector.cpp into the hw1 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.

  4. 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.

  5. Copy the following files into your assignment directory:

    hw1/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.

  6. 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++ -W -Wall -c -I. -I/home/courses/cop4530p/spring05/tcpp square1.cpp
    g++ -W -Wall -c -I. -I/home/courses/cop4530p/spring05/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.

  7. Now remove the files integer.h and integer.cpp from your directory and issue the commands:

    g++ -W -Wall -c -I. -I/home/courses/cop4530p/spring05/cpp -I/home/courses/cop4530p/spring05/tcpp square1.cpp
    g++ -W -Wall -c -I. -I/home/courses/cop4530p/spring05/cpp -I/home/courses/cop4530p/spring05/tcpp /home/courses/cop4530p/spring05/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 hw1b.txt.)

  8. Now remove the object and executable files (using clean .) and issue these commands:

    co4530 square1
    co4530 /home/courses/cop4530p/spring05/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?

  9. Now we are ready to create a "simple" makefile named makefile. Start by copying the file ~cop4530p/spring05hw1/makefile.partial to ~/cop4530/hw1/makefile. Edit this file, following the hints provided by the documentation. The idea is to accomplish two things:

    1. Capture the file dependencies implied by #include<> statements; and
    2. Capture the compile commands explored above.
    The file dependencies will guide the compilations required to build (and re-build) a project. The compile commands will be issued in an appropriate order for the project build.
    Note 1: Dependencies begin in column 1, while compile commands begin with a TAB.
    Note 2: Acknowledge dependencies only from your code files to each other and to the library. Don't acknowledge dependencies created by the library itself.
    Note 3: You need to remove all object and executable files before attempting to build, otherwise the test may not be adequate. This is easily accomplished using the command

    clean .

    created in Homework 1. 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.

  10. 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 hw1/makefile2.partial to hw1/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.)

  11. Here are some experiments to illustrate some of the benefits of using makefiles.

    1. Build twice in a row, without cleaning up in between. You should get the message "'game.x' is up to date.".
    2. Build, then make a small change in square1.cpp and build again without cleaning up in between. You should see only the appropriate files updated.

  12. Submit the files hw1a.txt, hw1b.txt, makefile, makefile2, square1.cpp using the project submit system:

    1. Copy the file ~cop4530p/spring05/submitscripts/hw1submit.sh into hw1
    2. Change permissions of this file to 700 (executable).
    3. From the shell login, enter the command hw1submit.sh
    4. You should see something on screen as follows:

      yourname@shell:~/cop4530/hw1>hw1submit.sh
      Changing directory to ....
      Archiving...
      a makefile 1K
      a makefile2 1K
      a square1.cpp 3K
      a hw1a.txt 2K
      a hw1b.txt 2K
      Sending mail...
      Cleaning up...
      yourname@shell:~/cop4530/hw1>
      
    5. Check your CS email (from shell) to verify that you receive two automatic responses to the submit:
      1. An email acknowledging receipt of the submission.
      2. An email containing the contents of what was received.
      Be sure that these agree with what you thought was submitted, and correct if necessary. Items may be re-submitted as many times as you like. The new submission is just copied over the old one.

  13. 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 hw1submit.sh.

Technical Requirements and Specifications

  1. Performance of each procedural step above should be documented in your file hw1b.txt. Documentation should either be a snippet of screen output or, where questions are asked, the answer to the question.

  2. Each makefile should correctly produce two object code files square1.o and integer.o and one executable game.x.

  3. 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., ".").

  4. 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).