This lab should be completed by editing and submitting this HTML file and by submitting scripts and output files.
Submit via all materials by D2L by the end of the lab session.
The following shell script creates a directory and initial files for a COMP 1710 assignment.
#!/bin/bash
if [[ $# != 2 ]]; then
echo "usage: setup-1710.sh dir java_file"
exit 1
fi
dir=$1
java_file=$2
if [[ ! -e $dir ]] ; then
mkdir -p $dir
fi
java_pathname=$dir/$java_file
if [[ ! -e $java_pathname ]] ; then
echo -e "public class $java_file {n}" > $java_pathname
fi
if [[ ! -e $dir/README ]] ; then
echo "$java_file is the java file" > $dir/README
fi
This script could be called as follows:
$ ./setup-1710.make assign1 Main.java
makefile
, called
fixed_args.make
, that has four targets, one for
creating the directory, one for creating the
README
, and one for creating the main class, and
an all
target to create everything. Your makefile
should perform the same as the above bash script. Define two
variables at the beginning, the first called DIR
to store assign1
as the directory, the second
called JAVA_FILE
to store Main.java
as the Java file to create.Submit fixed_args.make
.
fixed_args.make
to
cmdline_args.make
. Now remove the lines where
DIR
and JAVA_FILE
are defined. You
can now call this makefile from the command line with
DIR
and JAVA_FILE
specified as
follows:
make -f cmdline_args.make DIR=assign1 JAVA_FILE=Main.java
Test that this works (there is nothing to submit for this step).
cmdline_args.make
8 times to generate directories
and files for assignments 1 - 8. Main.java
can be
used for all of the Java files. The directories should be
assign1
, assign2
, ... up to
assign8
.setup-1710-all.sh
.The directory arith contains four
files: arith.h
, gcd.s
,
lcm.c
, and main.c
. These files can be
used to created an executable program, called
arith_pgm
. that prints out the Least Common Multiple
and Greatest Common Divisors for several pairs of numbers.
Give below the individual commands, which can be used to
transform the C files into object .o
files?
Change this with your answer
The source code for the gcd
module is not
provided. Instead you have gcd.s
which is the
assembly code produced from compiling the missing
gcd
module. You can create an object file from
this code by executing as -o gcd.o gcd.s
.
Execute this command. There is no other action to take here
but you should take a look at gcd.s
.
What command is used to combine all of the .o
files into the arith_pgm
executable?
Change this with your answer
What is the output of the arith_pgm
program?
Change this with your answer
arith
Create a Makefile
that creates the
arith_pgm
executable from the files in the
arith
directory. Your Makefile
should
contain rules, that create lcm.o
,
main.o
, gcd.o
, and
arith_pgm
. Provide a clean
target to
remove all the object files and the executable. Place your
makefile
in the arith
directory, and
call it Makefile
.
Submit your Makefile
.
What is the output from executing make
?
Change this with your answer
What is the output from executing make
clean
?
Change this with your answer
Execute make
again to rebuild the executable.
Then remove the file lcm.o
and execute
make
.
Change this with your answer
Explain what happened in the previous step. Why does the output from part 4 differ from the output of part 2?
Change this with your answer