-
Notifications
You must be signed in to change notification settings - Fork 0
/
c.make
55 lines (45 loc) · 1.5 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
45
46
47
48
49
50
51
52
53
54
55
# 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.
CC = gcc
ifeq ($(CPP),true)
# Ideally, we'd add -pedantic-errors, but the use of designated initializers
# means julipp relies on some GCC/Clang extensions to compile as C++.
CFLAGS := -std=c++11
C_LANG := -x c++
else
CFLAGS := -std=c99
endif
CFLAGS += -Wall -Wextra -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 $(C_LANG) $(CFLAGS) -o $@ $<
.PHONY: default