Dana Vrajitoru
C151 Multi-User Operating Systems
C151 Homework 6
Due date: Monday, March 8, 2021.
Ex. 1. Writing a Makefile
In this homework you will write a Makefile for a Java
project composed of several files.
Go to the folder week5 that you created for Lab 5 and
Homework 5, and to the folder planets inside it. You have
compiled these files manually for Homework 5. Now you'll write a
Makefile for them.
Write a Makefile with the following features:
- Have a separate target for each class file. The list of
dependencies should contain the source file that is being compiled and
all the other source files for the classes used in that source file.
Note that
- The Earth class references the Sun class.
- The Moon class references the Earth class.
- The Main class references the Moon class.
The compilation command for each object should be listed starting
with a tab under that target.
For example, to create a target for a compiled file
called Earth.class based on compiling the source
file earth.java, you have to look at the
file Earth.java and see that it calls a method from the
class Sun. Thus, the target will be listing both of them as
dependencies:
Earth.class: Earth.java Sun.java
javac Earth.java
Note: You'll have to manually replace the spaces at the
beginning of the compilation command above with a tab.
Proceed the same way for all of the others.
- Declare a variable called classes that contains the list
of all the .class files. You can place it before all the targets. You
will use it in the compilation command that creates the jar file and
in the dependency list for it. For example, you can start with
objects = Earth.class ...
and replace the dots with the remaining objects, including
the Main.
- Add a target for the jar file called planet.jar having all
the class files as dependencies. Use the value of
variable $(classes) in place of this list of classes. Write
the appropriate compilation command below the target, using the
variable again.
- Add a target called clean with no dependencies, having a
command deleting all the .class files and the jar file.
- Add a default target at the top that redirects to the
target planet.jar.
- Add a comment with your name at the top of the file.
Compile and execute the program using your Makefile. Then
modify the file Main.java using any editor you want to print
out an explanation message about what the program is doing. Place it
before the one function call you'll find in the main. After
that, recompile the program with the command make and run it
again. Copy these commands and their outcome in a file
called hw6.txt.
Canvas Submission
Upload to Canvas, Assignments, Homework 6:
- the file hw6.txt and
- the Makefile that you created for the homework (make sure
it's not the one from the lab).