-
Notifications
You must be signed in to change notification settings - Fork 0
/
OldMakefile
51 lines (40 loc) · 1.31 KB
/
OldMakefile
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
# 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 -Werror -Wno-unused-parameter
BIN_INSTALL := /usr/local/bin/
# 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 ---------------------------------------------------------------------
default: build/$(NAME)
# Install the executable in the bin folder
install: build/$(NAME)
install build/$(NAME) $(BIN_INSTALL)$(NAME)
# 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 clean
clean:
rm -rf build/
uninstall:
rm -rf $(BIN_INSTALL)$(NAME)