A Quick Guide To Understanding Makefiles.
A Quick Guide To Understanding Makefiles.
target: dependencies
command
Example Makefile
hello: hello.o
gcc -o hello hello.o
hello.o: hello.c
gcc -c hello.c
clean:
rm -f hello hello.o
Variables in Makefiles
CC = gcc
CFLAGS = -Wall
hello: hello.o
$(CC) -o hello hello.o $(CFLAGS)
Phony Targets
.PHONY: clean
clean:
rm -f *.o hello
Automatic Variables
$@ - target name
$< - first dependency
$^ - all dependencies
Example:
%.o: %.c
$(CC) -c $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
include common.mk