forked from jivanpal/drat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
109 lines (88 loc) · 2.34 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
98
99
100
101
102
103
104
105
106
107
108
109
### 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-unused-variable \
-Wno-unused-but-set-variable \
-Wno-deprecated-non-prototype \
-Wno-multichar \
-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)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),arm64)
# Apple Silicon
ARGP_PREFIX := /opt/homebrew/opt/argp-standalone
else ifeq ($(UNAME_M),x86_64)
# Intel Macs
ARGP_PREFIX := /usr/local/opt/argp-standalone
else
$(error Unsupported architecture $(UNAME_M))
endif
override CFLAGS += -I$(ARGP_PREFIX)/include/
override LDFLAGS += -L$(ARGP_PREFIX)/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)