-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
62 lines (47 loc) · 1.45 KB
/
Copy pathMakefile
File metadata and controls
62 lines (47 loc) · 1.45 KB
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
56
57
58
59
60
61
62
# cshell - a small POSIX shell
#
# Usage:
# make build the release binary (./cshell)
# make debug build with -O0 -g3 and assertions enabled
# make release same as the default target
# make test build, then run the end-to-end test suite
# make clean remove build output
CC ?= cc
BIN := cshell
BUILD ?= release
WARNINGS := -Wall -Wextra -Wpedantic -Wshadow -Wstrict-prototypes
STD := -std=c11
# POSIX 2008 for sigaction, setenv, strdup and friends; the Darwin macro keeps
# the same declarations visible on macOS, where strict POSIX hides some of them.
DEFINES := -D_POSIX_C_SOURCE=200809L -D_DARWIN_C_SOURCE
ifeq ($(BUILD),debug)
OPTFLAGS := -O0 -g3
else ifeq ($(BUILD),release)
OPTFLAGS := -O2 -DNDEBUG
else
$(error unknown BUILD "$(BUILD)", expected "debug" or "release")
endif
CFLAGS := $(STD) $(WARNINGS) $(DEFINES) $(OPTFLAGS) -MMD -MP
LDFLAGS ?=
SRCDIR := src
OBJDIR := build/$(BUILD)
SRCS := $(wildcard $(SRCDIR)/*.c)
OBJS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SRCS))
DEPS := $(OBJS:.o=.d)
.PHONY: all release debug test clean
all: $(BIN)
release:
@$(MAKE) --no-print-directory BUILD=release all
debug:
@$(MAKE) --no-print-directory BUILD=debug all
$(BIN): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR):
mkdir -p $(OBJDIR)
test: $(BIN)
tests/run_tests.sh ./$(BIN)
clean:
rm -rf build $(BIN)
-include $(DEPS)