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 useall
for the main task. To run this task, you can just simply callmake
, it will automatically pick up taskall
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 make
to 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:
-Wall
will enable compiler warning messages-g
will generate dbug file to use with GDB (GNU Project Debugger) or LLDB (Low Level Debugger)