* [Online make manual](https://www.gnu.org/software/make/manual/make.html)
* `man make`
Make allows you to automate some commands and simplify what you have to type to program things (though it can be used for programming anything, not just programs).
Typically, you'll be using the following pattern:
```bash
make targetname
```
where `targetname` is a specific target to execute.
Targets are just names, behind which are defined sets of commands to do something.
Let's have a look at the basic FTDI echo files:
* [hello.ftdi.44.echo.c](http://academy.cba.mit.edu/classes/embedded_programming/hello.ftdi.44.echo.c) - the c program file (i.e. the code to compile and run onto the micro-controller)
* [hello.ftdi.44.echo.c.make](http://academy.cba.mit.edu/classes/embedded_programming/hello.ftdi.44.echo.c.make) - the makefile
The `.make` file contains the following (in the terminal: `cat hello.ftdi.44.echo.c.make`):
avrdude -p t44 -P usb -c avrisp2 -U flash:w:$(PROJECT).c.hex
program-avrisp2-fuses: $(PROJECT).hex
avrdude -p t44 -P usb -c avrisp2 -U lfuse:w:0x5E:m
program-usbtiny: $(PROJECT).hex
avrdude -p t44 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex
program-usbtiny-fuses: $(PROJECT).hex
avrdude -p t44 -P usb -c usbtiny -U lfuse:w:0x5E:m
program-dragon: $(PROJECT).hex
avrdude -p t44 -P usb -c dragon_isp -U flash:w:$(PROJECT).c.hex
program-ice: $(PROJECT).hex
avrdude -p t44 -P usb -c atmelice_isp -U flash:w:$(PROJECT).c.hex
program-ice-fuses: $(PROJECT).hex
avrdude -p t44 -P usb -c atmelice_isp -U lfuse:w:0x5E:m
```
The **targets** we mentions are all the blocks starting like `targetname:`.
When calling for example
```bash
make -f hello.ftdi.44.echo.c.make program-usbtiny
```
It ...
Wait a second, what's that command?
Unfortunately, you cannot just use `make targetname` all the time.
It only works when the configuration for make (`.make` file) is actually named `Makefile` and available where you run `make`.
Most examples in the class are not named with that single same name because it would create lots of conflicts and there is nothing that associates that file.
By naming the file `myprogram.c.make`, we know that the makefile is associated with the program `myprogram.c`, but then we have to specify the `makefile` that makes uses.
Here is that argument in the manual:
<imgsrc="images/man_make_f.png"width="800">
Back to the command, `make -f hello.ftdi.44.echo.c.make program-usbtiny` ends up running the target `program-usbtiny` in the makefile.
```bash
program-usbtiny: $(PROJECT).hex
avrdude -p t44 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex
```
* `program-usbtiny` is the target name (for the argument to `make`)
* `$(PROJECT).hex` (on the right of the target, after the `:` separator) is the list of dependencies that needs to be `made` before we can run the actual script below.
* `avrdude -p t44 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex` is the actual command being run
* Beware, those lines must start with a tabulation character `\t`, which is not visible but is different from a blank space
If we look at the dependency, it's name is actually using a MACRO definition that is available at the top of the make file:
```bash
PROJECT=hello.ftdi.44.echo
```
The dependency name is either another *target* or a *file*, i.e. `hello.ftdi.44.echo.hex`.
If it's a file and the file is the last version, then it doesn't need to be computed again.
The rules are based on the existence of [the file dependencies and their relative timestamps](https://stackoverflow.com/questions/35588153/where-does-make-store-its-cache).
What about the target name? There is no explicit matching target name, but there is if we compute the MACROS (i.e. `$(PROJECT).hex:`)
And this has another dependency on the `.out` file, which is the object output from compiling the c file.
Fortunately, make outputs all the commands it runs, so you can just follow what's written on the terminal.
The first command compiled the C file with `avr-gcc`.
* `-mmcu=attiny44` because assumes an attiny44 as mcu
* `-Wall` enables all **w**arnings
* `-Os` optimizes for **s**ize
* `-DF_CPU=20000000` defines the MACRO F_CPU and sets it to `20000000` (20MHz)
* `-I./` adds the current directory to search for included files (`#include "file"`)
* `-o hello.ftdi.44.echo.out` specifies the output name
* `hello.ftdi.44.echo.c` is the input file
Then the second command creates a `hex` file from the program output.
See [.hex vs .out](https://electronics.stackexchange.com/questions/417648/whats-the-difference-between-a-generated-hex-file-and-a-binary-file-in-embedded) for the difference.
TL;DR hex files are easy to read and used for not only programming but also checking that the programming went well, whereas out files are binary codes to be transferred to the memory for execution.
The last command computes information about the size that the program is going to take.
This is important if you are creating your own program, because you need to make sure it will fit in memory.