make hello
Makefile
-
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 havehello.cppin your current directory)which will be equivalent to
g++ hello.cpp -o hello
If you execute
make hello
again (without changing
hello.cpp),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 createMakefiles that specify the relationship between the source files necessary to build a program so thatmakewill execute the correct commands for us. After creating aMakefilein the directory with our source files, we can executemakewith different targets to build our program in different ways.
Contents of a Makefile
-
We can divide the contents of a Makefile in four categories:
- Comments
-
Any line that starts with a
#in the first column is a comment and is ignored bymake. - Variables
-
Define variables (macros) like this.
VARIABLE_NAME = valueThe 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
$(VARIABLE_NAME)operator.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 letmakeknow that it needs to have (ormake) 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
.ofiles from.cppfiles using the g++ compiler in the same manner as before, you could write:.c.o: g++ -o $@ $?
EECS 281 Makefile
-
EECS 281 provides a sample
Makefilein Project 0. You are very much encouraged to use thisMakefile, since you will need to include one in your submission. The sampleMakefilewill 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) forTODOs that will indicate where you need to modify the sampleMakefile. Specifically, you will most likely need to make two changes.-
Set
EXECUTABLEtoshipfor Project 1. -
Set
PROJECTFILEto the.cppfile that has themainfunction.
That’s it! You can use this
Makefilefor Project 1 (and for the other projects, so long as you remember to change the value ofEXECUTABLE). -
-
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
make help
to get information on exactly what each of the commands does.
-
To submit, execute
make fullsubmitfor submission of project without test files. Executemake 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.)