77
88set -eu
99
10- # Save the ./configure command line for bfs --version
11- export CONFIG=" $0 $* "
10+ # Print the help message()
11+ help () {
12+ cat << EOF
13+ Usage:
1214
13- # Default to `make`
14- MAKE=" ${MAKE:- make} "
15-
16- # Pass -j$(nproc) unless MAKEFLAGS is set
17- if [ " ${MAKEFLAGS+y} " ]; then
18- j=" "
19- else
20- j=" -j$( { nproc || sysctl -n hw.ncpu || getconf _NPROCESSORS_ONLN || echo 1; } 2> /dev/null) "
21- fi
22-
23- # Convert kebab-case to UPPER_CASE
24- toupper () {
25- printf ' %s' " $1 " | tr ' a-z-' ' A-Z_'
15+ \$ $0 [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...]
16+ \$ $MAKE $j
17+
18+ Variables set in the environment or on the command line will be picked up:
19+
20+ MAKE
21+ The make implementation to use
22+ CC
23+ The C compiler to use
24+
25+ CPPFLAGS="-I... -D..."
26+ CFLAGS="-W... -f..."
27+ LDFLAGS="-L... -Wl,..."
28+ Preprocessor/compiler/linker flags
29+
30+ LDLIBS="-l... -l..."
31+ Dynamic libraries to link
32+
33+ EXTRA_{CPPFLAGS,CFLAGS,LDFLAGS,LDLIBS}
34+ Adds to the default flags, instead of replacing them
35+
36+ The default flags result in a plain debug build. Other build profiles include:
37+
38+ --enable-release
39+ Enable optimizations, disable assertions
40+ --enable-{asan,lsan,msan,tsan,ubsan}
41+ Enable sanitizers
42+ --enable-gcov
43+ Enable code coverage instrumentation
44+
45+ External dependencies are auto-detected by default, but you can build --with or
46+ --without them explicitly:
47+
48+ --with-libacl --without-libacl
49+ --with-libcap --without-libcap
50+ --with-libselinux --without-libselinux
51+ --with-liburing --without-liburing
52+ --with-oniguruma --without-oniguruma
53+
54+ Packaging:
55+
56+ --prefix=/path
57+ Set the installation prefix (default: /usr)
58+ --mandir=/path
59+ Set the man page directory (default: \$ PREFIX/share/man)
60+
61+ This script is a thin wrapper around a makefile-based configuration system.
62+ Any other arguments will be passed directly to the $MAKE invocation, e.g.
63+
64+ \$ $0 $j V=1
65+ EOF
2666}
2767
2868# Report an argument parsing error
@@ -32,7 +72,26 @@ invalid() {
3272 exit 1
3373}
3474
75+ # Get the number of cores to use
76+ nproc () {
77+ {
78+ command nproc \
79+ || sysctl -n hw.ncpu \
80+ || getconf _NPROCESSORS_ONLN \
81+ || echo 1
82+ } 2> /dev/null
83+ }
84+
85+ # Save the ./configure command line for bfs --version
86+ export CONFIG=" $0 $* "
87+
88+ # Default to `make`
89+ MAKE=" ${MAKE-make} "
90+
91+ # Parse the command-line arguments
3592for arg; do
93+ shift
94+
3695 # --[(enable|disable|with|without)-]$name[=$value]
3796 value=" ${arg#* =} "
3897 name=" ${arg%% =* } "
@@ -80,67 +139,13 @@ for arg; do
80139
81140 case " $arg " in
82141 -h|--help)
83- cat << EOF
84- Usage:
85-
86- \$ $0 [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...]
87- \$ $MAKE $j
88-
89- Variables set in the environment or on the command line will be picked up:
90-
91- MAKE
92- The make implementation to use
93- CC
94- The C compiler to use
95-
96- CPPFLAGS="-I... -D..."
97- CFLAGS="-W... -f..."
98- LDFLAGS="-L... -Wl,..."
99- Preprocessor/compiler/linker flags
100-
101- LDLIBS="-l... -l..."
102- Dynamic libraries to link
103-
104- EXTRA_{CPPFLAGS,CFLAGS,LDFLAGS,LDLIBS}
105- Adds to the default flags, instead of replacing them
106-
107- The default flags result in a plain debug build. Other build profiles include:
108-
109- --enable-release
110- Enable optimizations, disable assertions
111- --enable-{asan,lsan,msan,tsan,ubsan}
112- Enable sanitizers
113- --enable-gcov
114- Enable code coverage instrumentation
115-
116- External dependencies are auto-detected by default, but you can build --with or
117- --without them explicitly:
118-
119- --with-libacl --without-libacl
120- --with-libcap --without-libcap
121- --with-libselinux --without-libselinux
122- --with-liburing --without-liburing
123- --with-oniguruma --without-oniguruma
124-
125- Packaging:
126-
127- --prefix=/path
128- Set the installation prefix (default: /usr)
129- --mandir=/path
130- Set the man page directory (default: \$ PREFIX/share/man)
131-
132- This script is a thin wrapper around a makefile-based configuration system.
133- Any other arguments will be passed directly to the $MAKE invocation, e.g.
134-
135- \$ $0 $j V=1
136- EOF
142+ help
137143 exit 0
138144 ;;
139145
140146 --enable-* |--disable-* )
141147 case " $name " in
142148 release|asan|lsan|msan|tsan|ubsan|lint|gcov)
143- shift
144149 set -- " $@ " " $NAME =$yn "
145150 ;;
146151 * )
152157 --with-* |--without-* )
153158 case " $name " in
154159 libacl|libcap|libselinux|liburing|oniguruma)
155- shift
156160 set -- " $@ " " WITH_$NAME =$yn "
157161 ;;
158162 * )
@@ -162,23 +166,20 @@ EOF
162166 ;;
163167
164168 --prefix=* |--mandir=* )
165- shift
166169 set -- " $@ " " $NAME =$value "
167170 ;;
168171
169172 --infodir=* |--build=* |--host=* |--target=* )
170- shift
171173 printf ' warning: Ignoring option "%s"\n' " $arg " >&2
172174 ;;
173175
174176 MAKE=* )
175- shift
176177 MAKE=" $value "
177178 ;;
178179
179180 # make flag (-j2) or variable (CC=clang)
180181 -* |* =* )
181- continue
182+ set -- " $@ " " $arg "
182183 ;;
183184
184185 * )
@@ -196,6 +197,6 @@ for f in Makefile build completions docs src tests; do
196197done
197198
198199# Set MAKEFLAGS to -j$(nproc) if it's unset
199- export MAKEFLAGS=" ${MAKEFLAGS-$j } "
200+ export MAKEFLAGS=" ${MAKEFLAGS--j$(nproc) } "
200201
201202$MAKE -rf build/config.mk " $@ "
0 commit comments