Makefile

  • make is 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.cpp in your current directory)

    make hello

    which will be equivalent to

    g++     hello.cpp    -o hello

    If you execute

    make hello

    again (without changing hello.cpp), make will inform you that `hello' is up to date.

  • As you can see, make provides an easy way to build a program.

  • We can use make to 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 make will execute the correct commands for us. After creating a Makefile in the directory with our source files, we can execute make with 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 by make.

    Variables

    Define variables (macros) like this.

    VARIABLE_NAME = value

    The above line defines a variable called VARIABLE_NAME whose 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 Makefile to 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 make know 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 .o files from .cpp files 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 Makefile in Project 0. You are very much encouraged to use this Makefile, since you will need to include one in your submission. The sample Makefile will also facilitate compressing your files into at .tar.gz archive before you submit.

  • To use EECS 281 Makefile for 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.

    • Set EXECUTABLE to ship for Project 1.

    • Set PROJECTFILE to the .cpp file that has the main function.

    That’s it! You can use this Makefile for Project 1 (and for the other projects, so long as you remember to change the value of EXECUTABLE).

  • 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 fullsubmit for submission of project without test files. Execute make partialsubmit for 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.)

results matching ""

    No results matching ""