Building Software and Documentation with GNU Make

Paul Waring (paul@xk7.net)

February 25, 2017

What is GNU Make?

What does Make do?

Makefile components

Makefile components

Make will build a target when...

Make will not build a target when...

Make without a Makefile

Example: slides

Slides Makefile

slides.html: slides.md Makefile
    filepp slides.md | pandoc -t s5 -V s5-url=../s5/default -s -o slides.html

clean:
    rm -f *.html

.PHONY: clean

Phony targets and clean

Make variables

Make variables

Special variables

C example with explicit rules

CC = clang
CFLAGS = -Weverything -Werror
SOURCES = hello.c
OBJECTS = $(subst .c,.o,$(SOURCES))
EXECUTABLE = hello

$(EXECUTABLE): $(OBJECTS)
    $(CC) $(OBJECTS) -o $(EXECUTABLE)

%.o: %.c
    $(CC) $(CFLAGS) -c $< -o $@

clean:
    -rm -f $(OBJECTS) $(EXECUTABLE)

.PHONY: clean

Example: Configuration management workshop

Debugging

Parallel builds

Recursive Make

Autotools

Automake

Gotchas

Resources