Exercise Hello-World

Objective: Learn to work with makefiles and make utility by making a "Hello, world" program.

Make the directory for the hello-excercise

mkdir --parents ~/public_html/numeric/hello
and do the exercise in this directory.
  1. (6 points)

    Create a project with the corresponding makefile with the following targets:

    1. The (default) target "A" which creates a text file, say "out.A.txt" with the text "Hello, your_username". The text-file should be created by building a helloworld program—a program which prints "hello your_username" on the standard output—and then running it, redirecting the output to the "out.A.txt" file.
    2. Target "cleanA" that removes all generated files leaving only the essential files.
    3. Make sure commands make A and make cleanA work as intended.

    Comment an arbitrary line in the makefile explaining its purpose.

    Hint: the commands in the makefile must start with the tabulator-sign which might not be visible in the nano editor. To make them visible, create a ~/.nanorc file with the content

    syntax "makefile" "[Mm]akefile"
    color white,magenta "	"
    
    (or whatever colors you prefer) where there is the tabulator sign (obtained by pressing the tabulator-key on the keyboard) between the quotes in the second line.
  2. (3 points)

    Extend your makefile: now there must be a default target "all" (remember that default target is the first one) which depends on targets "A" and "B". The target "B" must compile three functions in three separate files,

    1. function hello that prints "hello, " to the stdout,
    2. function world that prints "you_username\n" to the stdout,
    3. function main that calls the two previous functions,

    then link the object files into a program called main and then run the program redirecting the output into the "out.B.txt" file.

    The clean target has to be updated as well.

  3. (2 points) Create a "checkA" and "checkB" targets that check whether the "A" and "B" targets have been built correctly. For example,

    checkA: out.A.txt
       @echo "checking A ..."
       @echo "hello, fedorov" > correct.txt
       @diff --brief correct.txt out.A.txt
       @echo "Target A seems to be ok ..."
       @rm -f correct.txt
    
  4. (0 points) Create a "backup" target that builds an archive of the exercise and backs it up somehow, e.g. by mailing the archive to your NFIT mail account (or any other mail address suitable for backing up):

    
    backup: hello.tgz
       ssh $(shell whoami)@lifa.phys.au.dk \
       'base64 $(shell pwd)/hello.tgz \
       | mailx -s "hello backup" $(shell whoami)@phys.au.dk'
    hello.tgz: makefile $(shell ls *.cc)
       tar --create --gzip --file=hello.tgz makefile *.cc
       tar --list --file=hello.tgz
    
    You need to run mailx on lifa because all other servers are behind the firewall.

    The utility base64 performs encoding (and decoding) suitable for sending files as emails.