Makefile

Can be used to indicate how Make should run.

For example:

CFLAGS=-Wall -g

all: compile run clean

compile:
	@cc main.c -o main $(CFLAGS)

clean:
	@rm -rf main main.dSYM

run:
	@./main

Syntax:

[task name]: [dependency task name] [dependency task name 2] ...
    bash command to run task

For example, in here all will be dependent on compile, run, and clean task in order.

By default, Make will just run the first task (in this case all).

[!note]
By convention, people use all for the main task. To run this task, you can just simply call make, it will automatically pick up task all

If you want to use a specific task (for example clean) you can do so by running make clean.

In the task body, we need to use tab (not spaces). In here we just put normal bash script that needed for make to run.

We use @ for maketo not print out the command that it's running.

The CFLAGS will be automatically included if we use make main (main is the file name, assuming we have a file main.c).

Or we can just include it manually in compile task as $(CFLAGS)

Note: