-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
97 lines (76 loc) · 2.04 KB
/
Makefile
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
### Directory definitions ###
SRCDIR=src
OUTDIR=out
INCDIR=include
### Compiler definition ###
CC := gcc
override CFLAGS += \
-std=c99 \
-D _GNU_SOURCE \
-Werror \
-Wall \
-Wextra \
-Wno-incompatible-pointer-types \
-Wno-multichar \
-Wno-unused-variable \
-Wno-unused-parameter \
-Wno-missing-field-initializers \
-I./$(INCDIR)
### Linker definition ###
LD := gcc
override LDFLAGS += # Nothing
### On macOS, include <argp.h> from Homebrew package `argp-standalone`
ifneq ($(OS),Windows_NT)
ifeq ($(shell uname -s),Darwin)
override CFLAGS += -I/usr/local/Cellar/argp-standalone/1.3/include/
override LDFLAGS += -L/usr/local/Cellar/argp-standalone/1.3/lib/ -largp
endif
endif
### Source paths ###
HEADERS := $(shell find $(SRCDIR) $(INCDIR) -name '*.h')
SOURCES := $(shell find $(SRCDIR) $(INCDIR) -name '*.c')
CMD_SRCS := $(wildcard $(SRCDIR)/commands/*.c)
BIN_SRCS := $(wildcard $(SRCDIR)/*.c)
### Target paths ###
GCHS := $(HEADERS:%.h=$(OUTDIR)/%.gch)
OBJECTS := $(SOURCES:%.c=$(OUTDIR)/%.o)
COMMANDS := $(CMD_SRCS:$(SRCDIR)/commands/%.c=%)
BINARIES := $(BIN_SRCS:$(SRCDIR)/%.c=%)
### Targets ###
.DEFAULT_GOAL := all
$(GCHS): $(OUTDIR)/%.gch: %.h
@echo "GCHS +++ $< +++ $@"
@[ -d $(@D) ] || (mkdir -p $(@D) && echo "Created directory \`$(@D)\`.")
$(CC) $(CFLAGS) -c "$<" -o "$@"
@echo
$(OBJECTS): $(OUTDIR)/%.o: %.c $(HEADERS)
@echo "OBJECTS +++ $< +++ $@"
@[ -d $(@D) ] || (mkdir -p $(@D) && echo "Created directory \`$(@D)\`.")
$(CC) $(CFLAGS) -c "$<" -o "$@"
@echo
# Make `<command_name>` an alias of `out/commands/<command_name>.o`
.PHONY: $(COMMANDS)
$(COMMANDS): %: $(OUTDIR)/$(SRCDIR)/commands/%.o
$(BINARIES): %: $(OUTDIR)/$(SRCDIR)/%.o $(OBJECTS)
@echo "BINARIES +++ $< +++ $@"
$(LD) $^ $(LDFLAGS) -o $@
@echo
### Meta-targets ###
.PHONY: headers
headers: $(GCHS)
.PHONY: commands
commands: $(COMMANDS)
.PHONY: binaries
binaries: $(BINARIES)
.PHONY: clean
clean:
rm -rf $(BINARIES) $(OUTDIR)
.PHONY: all
all: headers commands binaries
##
.PHONY: docs
docs:
(cd docs && make html)
.PHONY: clean-docs
clean-docs:
(cd docs && make clean)