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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# Copyright © Tavian Barnes <tavianator@tavianator.com>
# SPDX-License-Identifier: 0BSD
# Common makefile utilities. Compatible with both GNU make and most BSD makes.
# BSD make will chdir into ${.OBJDIR} by default, unless we tell it not to
.OBJDIR: .
# We don't use any suffix rules
.SUFFIXES:
# GNU make has $^ for the full list of targets, while BSD make has $> and the
# long-form ${.ALLSRC}. We could write $^ $> to get them both, but that would
# break if one of them implemented support for the other. So instead, bring
# BSD's ${.ALLSRC} to GNU.
.ALLSRC ?= $^
# Installation paths
DESTDIR ?=
PREFIX ?= /usr
MANDIR ?= ${PREFIX}/share/man
# Configurable executables
CC ?= cc
INSTALL ?= install
MKDIR ?= mkdir -p
PKG_CONFIG ?= pkg-config
RM ?= rm -f
# GNU and BSD make have incompatible syntax for conditionals, but we can do a
# lot with just nested variable expansion. We use "y" as the canonical
# truthy value, and "" (the empty string) as the canonical falsey value.
#
# To normalize a boolean, use ${TRUTHY,${VAR}}, which expands like this:
#
# VAR=y ${TRUTHY,${VAR}} => ${TRUTHY,y} => y
# VAR=1 ${TRUTHY,${VAR}} => ${TRUTHY,1} => y
# VAR=n ${TRUTHY,${VAR}} => ${TRUTHY,n} => [empty]
# VAR=other ${TRUTHY,${VAR}} => ${TRUTHY,other} => [empty]
# VAR= ${TRUTHY,${VAR}} => ${TRUTHY,} => [emtpy]
#
# Inspired by https://github.com/wahern/autoguess
TRUTHY,y := y
TRUTHY,1 := y
# Boolean operators are also implemented with nested expansion
NOT, := y
# Normalize ${V} to either "y" or ""
IS_V := ${TRUTHY,${V}}
# Suppress output unless V=1
Q, := @
Q := ${Q,${IS_V}}
# Show full commands with `make V=1`, otherwise short summaries
MSG = @msg() { \
MSG="$$1"; \
shift; \
test "${IS_V}" || printf '%s\n' "$$MSG"; \
test "$${1:-}" || return 0; \
test "${IS_V}" && printf '%s\n' "$$*"; \
"$$@"; \
}; \
msg
# Maximum width of a short message, to align the ✔/✘
MSG_WIDTH := 30
# cat a file if V=1
VCAT,y := @cat
VCAT, := @:
VCAT := ${VCAT,${IS_V}}
# All external dependencies
ALL_PKGS := \
libacl \
libcap \
libselinux \
liburing \
oniguruma
# List all object files here, as they're needed by both `./configure` and `make`
# All object files except the entry point
LIBBFS := \
obj/src/alloc.o \
obj/src/bar.o \
obj/src/bfstd.o \
obj/src/bftw.o \
obj/src/color.o \
obj/src/ctx.o \
obj/src/diag.o \
obj/src/dir.o \
obj/src/dstring.o \
obj/src/eval.o \
obj/src/exec.o \
obj/src/expr.o \
obj/src/fsade.o \
obj/src/ioq.o \
obj/src/mtab.o \
obj/src/opt.o \
obj/src/parse.o \
obj/src/printf.o \
obj/src/pwcache.o \
obj/src/stat.o \
obj/src/thread.o \
obj/src/trie.o \
obj/src/typo.o \
obj/src/xregex.o \
obj/src/xspawn.o \
obj/src/xtime.o \
obj/gen/version.o
# Unit test objects
UNIT_OBJS := \
obj/tests/alloc.o \
obj/tests/bfstd.o \
obj/tests/bit.o \
obj/tests/ioq.o \
obj/tests/main.o \
obj/tests/trie.o \
obj/tests/xspawn.o \
obj/tests/xtime.o
# All object files
OBJS := \
obj/src/main.o \
obj/tests/mksock.o \
obj/tests/xspawnee.o \
obj/tests/xtouch.o \
${LIBBFS} \
${UNIT_OBJS}
|