makeis a program (and a programming language) intended to help the development of programs that are constructed from one or more source files. For instance, you can execute this command in CAEN environment (if you have
hello.cppin your current directory)
which will be equivalent to
g++ hello.cpp -o hello
If you execute
again (without changing
makewill inform you that
`hello' is up to date.
As you can see,
makeprovides an easy way to build a program.
We can use
maketo our advantage and make the build process more complex. We can create
Makefiles that specify the relationship between the source files necessary to build a program so that
makewill execute the correct commands for us. After creating a
Makefilein the directory with our source files, we can execute
makewith different targets to build our program in different ways.
Contents of a Makefile
We can divide the contents of a Makefile in four categories:
Any line that starts with a
#in the first column is a comment and is ignored by
Define variables (macros) like this.
VARIABLE_NAME = value
The above line defines a variable called
VARIABLE_NAMEwhose value is the entire contents of the line after the
=, except surrounding whitespace.
Once a variable is defined, it can be extracted with the
You can use of variables in a
Makefileto enable version 4.8.2 of gcc and C++11 on CAEN.
# enables c++11 on CAEN PATH := /usr/um/gcc-4.8.2/bin:$(PATH) LD_LIBRARY_PATH := /usr/um/gcc-4.8.2/lib64 LD_RUN_PATH := /usr/um/gcc-4.8.2/lib64
- Dependency rules
Dependency rules are the heart of
make. Their purpose is to define the dependency of some target on some sources, to let
makeknow that it needs to have (or
make) all the sources before it can make the target. They also let make know that it will need to recreate the target if any of the objects that the target depends upon are more recent than the target.
A dependency rules must start in this form.
target: dependencies action
- Derivation rules
Derivation rules tell make how to “automatically” make a file with a particular suffix out of a file with another suffix, you can set up rules that look similar to dependency rules, but do not contain the names of specific files. For example, to tell make to make
.cppfiles using the g++ compiler in the same manner as before, you could write:
.c.o: g++ -o [email protected] $?
EECS 281 Makefile
EECS 281 provides a sample
Makefilein Project 0. You are very much encouraged to use this
Makefile, since you will need to include one in your submission. The sample
Makefilewill also facilitate compressing your files into at
.tar.gzarchive before you submit.
To use EECS 281
Makefilefor Project 1, first download the Makefile from the Project 0 example. Take a look at it and read the comments. Next, search (with Command-F or Control-F) for
TODOs that will indicate where you need to modify the sample
Makefile. Specifically, you will most likely need to make two changes.
shipfor Project 1.
.cppfile that has the
That’s it! You can use this
Makefilefor Project 1 (and for the other projects, so long as you remember to change the value of
Once you transfer your project files (including your
Makefile) to a directory on CAEN, you’ll be able to execute these commands.
make release make all make debug make profile make clean make test_class make alltests make partialsubmit make fullsubmit
In addition, you’ll be able to execute
to get information on exactly what each of the commands does.
To submit, execute
make fullsubmitfor submission of project without test files. Execute
make partialsubmitfor submission of project without test files. You might want to create partial submission when you are just starting working on your project and do not want to risk losing a submission if your code does not compile. (If your code does not compile and you submit test cases, you will use one submission. If you code does not compile and you do not submit test cases, you will not use one submission.)