-
Notifications
You must be signed in to change notification settings - Fork 0
/
c.make
44 lines (36 loc) · 1.26 KB
/
c.make
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Makefile for building a single configuration of the C interpreter. It expects
# variables to be passed in for:
#
# MODE "debug" or "release".
# NAME Name of the output executable (and object file directory).
# SOURCE_DIR Directory where source files and headers are found.
CFLAGS := -std=c99 -Wall -Wextra -Werror -Wno-unused-parameter
# If we're building at a point in the middle of a chapter, don't fail if there
# are functions that aren't used yet.
ifeq ($(SNIPPET),true)
CFLAGS += -Wno-unused-function
endif
# Mode configuration.
ifeq ($(MODE),debug)
CFLAGS += -O0 -DDEBUG -g
BUILD_DIR := build/debug
else
CFLAGS += -O3 -flto
BUILD_DIR := build/release
endif
# Files.
HEADERS := $(wildcard $(SOURCE_DIR)/*.h)
SOURCES := $(wildcard $(SOURCE_DIR)/*.c)
OBJECTS := $(addprefix $(BUILD_DIR)/$(NAME)/, $(notdir $(SOURCES:.c=.o)))
# Targets ---------------------------------------------------------------------
# Link the interpreter.
build/$(NAME): $(OBJECTS)
@ printf "%8s %-40s %s\n" $(CC) $@ "$(CFLAGS)"
@ mkdir -p build
@ $(CC) $(CFLAGS) $^ -o $@
# Compile object files.
$(BUILD_DIR)/$(NAME)/%.o: $(SOURCE_DIR)/%.c $(HEADERS)
@ printf "%8s %-40s %s\n" $(CC) $< "$(CFLAGS)"
@ mkdir -p $(BUILD_DIR)/$(NAME)
@ $(CC) -c $(CFLAGS) -o $@ $<
.PHONY: default