This lab is designed to help you feel comfortable using GNU Make, one of the oldest and still most-common build tools; as well as with many-file C projects.
Your task:
We would recommend working with a partner, but it is also fine if you do this alone.
Download
make-lab.tar
(you can do this using the link on this page, or from a command line viawget https://www.cs.virginia.edu/~cr4bd/3130/F2024/files/make-lab.tar
)Expand it using
tar xvf make-lab.tar
Read enough of the files to get an idea what they do. Then build them with
clang *.c
and run./a.out
to verify your understanding. Ask a TA for help if you are not sure you fully understand.Add a
Makefile
in the resultingmake-lab
directory, which- has rules for the following
- building each
.c
file into a.o
file - combining
cheer.o
andgrunt.o
into a library (eitherlibsay.a
orlibsay.so
) - combining the library and
guesser.o
into programguesser
- building each
- has
CC
,CFLAGS
, andLDFLAGS
we can edit make all
createsguesser
and its dependenciesmake clean
deletes all files thatmake
can recreate
Your
Makefile
must have correct dependencies for all rules, so for example,- running
make
twice in a row without editing anything does not cause anything to rebuilt the second time - editing
say.h
and runningmake
should cause all files to be rebuilt - editing any .c file and running
make
causes its .o file to be rebuilt, along with the library and/or program if they depend on the .c file- Note: if you chose library format
libsay.a
, thenguesser
should be rebuilt iflibsay.a
changes; but if you chose library formatlibsay.so
, thenguesser
should not be rebuilt iflibsay.so
changes, only ifsay.h
orguesser.c
change.
- Note: if you chose library format
- editing
cheer.c
orgrunt.c
should cause libsay and possiblyguesser
to be rebuilt, but should not causeguesser.o
to be rebuilt
Also, your Makefile should not rely on
built-in
rules1; you can test this usingmake --no-builtin-rules ...
instead ofmake ...
.- has rules for the following
Either:
- Place a comment (line starting with
#
) at the top of your Makefile indicating who you worked with and submit your Makefile to the submission site. (If working with a partner, both must submit.) and/or - Show a TA your
Makefile
. They may ask you to show it working, or to look at its contents, or both.
- Place a comment (line starting with
Refer to the complation and libraries and makefiles reading and/or the corresponding C material for information on how to achieve these goals. We recommend you read it in full, discussing it with a partner and asking clarifying questions of TAs as you go, then return to the tasks above.
make has some default rules, for example for building .o files from .c files, intended to allow Makefiles to avoid boilerplate for common tasks. For this lab, we want to write all the needed make rules explicitly.↩︎