zsv 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +140 -2
  3. data/README.md +129 -275
  4. data/ext/zsv/ZSV_UPSTREAM +7 -0
  5. data/ext/zsv/common.h +0 -12
  6. data/ext/zsv/extconf.rb +70 -122
  7. data/ext/zsv/options.c +63 -62
  8. data/ext/zsv/options.h +8 -11
  9. data/ext/zsv/parser.c +390 -201
  10. data/ext/zsv/parser.h +35 -22
  11. data/ext/zsv/row.c +75 -28
  12. data/ext/zsv/row.h +15 -9
  13. data/ext/zsv/upstream.rb +55 -0
  14. data/ext/zsv/vendor/zsv/LICENSE +21 -0
  15. data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
  16. data/ext/zsv/vendor/zsv/configure +1212 -0
  17. data/ext/zsv/vendor/zsv/include/zsv/api.h +375 -0
  18. data/ext/zsv/vendor/zsv/include/zsv/common.h +397 -0
  19. data/ext/zsv/vendor/zsv/include/zsv/ext/implementation.h +62 -0
  20. data/ext/zsv/vendor/zsv/include/zsv/ext/implementation_private.h +113 -0
  21. data/ext/zsv/vendor/zsv/include/zsv/ext/sheet.h +80 -0
  22. data/ext/zsv/vendor/zsv/include/zsv/ext.h +333 -0
  23. data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
  24. data/ext/zsv/vendor/zsv/include/zsv/utils/arg.h +139 -0
  25. data/ext/zsv/vendor/zsv/include/zsv/utils/cache.h +49 -0
  26. data/ext/zsv/vendor/zsv/include/zsv/utils/clock.h +36 -0
  27. data/ext/zsv/vendor/zsv/include/zsv/utils/compiler.h +69 -0
  28. data/ext/zsv/vendor/zsv/include/zsv/utils/db.h +19 -0
  29. data/ext/zsv/vendor/zsv/include/zsv/utils/dirs.h +149 -0
  30. data/ext/zsv/vendor/zsv/include/zsv/utils/dl.h +22 -0
  31. data/ext/zsv/vendor/zsv/include/zsv/utils/emcc/fs_api.h +28 -0
  32. data/ext/zsv/vendor/zsv/include/zsv/utils/err.h +22 -0
  33. data/ext/zsv/vendor/zsv/include/zsv/utils/file-mem.h +18 -0
  34. data/ext/zsv/vendor/zsv/include/zsv/utils/file.h +125 -0
  35. data/ext/zsv/vendor/zsv/include/zsv/utils/jq.h +65 -0
  36. data/ext/zsv/vendor/zsv/include/zsv/utils/json.h +19 -0
  37. data/ext/zsv/vendor/zsv/include/zsv/utils/mem.h +19 -0
  38. data/ext/zsv/vendor/zsv/include/zsv/utils/memmem.h +13 -0
  39. data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
  40. data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
  41. data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite.h +71 -0
  42. data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite_writer.h +53 -0
  43. data/ext/zsv/vendor/zsv/include/zsv/utils/prop.h +119 -0
  44. data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
  45. data/ext/zsv/vendor/zsv/include/zsv/utils/signal.h +25 -0
  46. data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
  47. data/ext/zsv/vendor/zsv/include/zsv/utils/string.h +173 -0
  48. data/ext/zsv/vendor/zsv/include/zsv/utils/utf8.h +41 -0
  49. data/ext/zsv/vendor/zsv/include/zsv/utils/win/dl.h +25 -0
  50. data/ext/zsv/vendor/zsv/include/zsv/utils/writer.h +109 -0
  51. data/ext/zsv/vendor/zsv/include/zsv/zsv_export.h +33 -0
  52. data/ext/zsv/vendor/zsv/include/zsv.h.in +18 -0
  53. data/ext/zsv/vendor/zsv/src/Makefile +238 -0
  54. data/ext/zsv/vendor/zsv/src/vector_delim.c +60 -0
  55. data/ext/zsv/vendor/zsv/src/zsv.c +622 -0
  56. data/ext/zsv/vendor/zsv/src/zsv_internal.c +789 -0
  57. data/ext/zsv/vendor/zsv/src/zsv_scan_delim.c +285 -0
  58. data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
  59. data/ext/zsv/vendor/zsv/src/zsv_scan_fixed.c +88 -0
  60. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
  61. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
  62. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
  63. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
  64. data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
  65. data/ext/zsv/zsv_ext.c +176 -105
  66. data/lib/zsv/errors.rb +32 -0
  67. data/lib/zsv/input.rb +88 -0
  68. data/lib/zsv/options.rb +132 -0
  69. data/lib/zsv/strict_validator.rb +124 -0
  70. data/lib/zsv/version.rb +1 -1
  71. data/lib/zsv.rb +137 -35
  72. metadata +82 -11
@@ -0,0 +1,1212 @@
1
+ #!/bin/sh
2
+ # Based on the configure script from musl libc, MIT licensed; vis, ISC licensed
3
+
4
+ usage () {
5
+ cat <<EOF
6
+ Usage: $0 [OPTION]... [VAR=VALUE]...
7
+
8
+ To assign environment variables (e.g., CC, CFLAGS...), specify them as
9
+ VAR=VALUE. See below for descriptions of some of the useful variables.
10
+
11
+ Defaults for the options are specified in brackets.
12
+
13
+ Configuration:
14
+ --config-file=FILE save config to FILE [config.mk]
15
+
16
+ Optional configuration:
17
+ --minimal=yes do not include extra features (default=no)
18
+ --arch=ARCH use -march=ARCH. Set to 'none' for none, else defaults to 'native'
19
+ --jq-prefix=JQ_PREFIX specify directory containing lib/libjq and include/jq.h
20
+ defaults to PREFIX if not specified and PREFIX/include/jq.h exists
21
+ --pcre2-8-prefix=PCRE2_8_PREFIX
22
+ no=do not use pcre2
23
+ builtin=build from included source (pcre2-10.47)
24
+ otherwise, specify dir with lib/libpcre2-8 and include/pcre2-8.h
25
+ defaults to 'builtin' if not specified
26
+ --no-parallel disable parallelization in the CLI 'select' command
27
+
28
+ Installation directories:
29
+ --prefix=PREFIX main installation prefix [\$PREFIX or /usr/local]
30
+ --exec-prefix=EPREFIX installation prefix for bin, lib, include [PREFIX]
31
+
32
+ Fine tuning of the installation directories:
33
+ --libdir=DIR static and/or shared libraries [PREFIX/lib]
34
+ --sharedir=DIR share directories [PREFIX/share]
35
+ --docdir=DIR misc. documentation [PREFIX/share/doc]
36
+ --mandir=DIR man pages [PREFIX/share/man]
37
+
38
+ Optional features:
39
+ --try-avx512 use avx512 instructions, if available [no]
40
+ --force-avx2 force compile with (no CPU check) or without -mavx2 [auto]
41
+ --force-avx force compile with (no CPU check) or without -mavx [auto]
42
+ --force-sse2 force compile with (no CPU check) or without -msse2 [auto]
43
+ --enable-sheet compile with 'sheet' feature (requires ncurses) [yes]
44
+ --without-pdcurses on Windows/MinGW, use ncurses instead of PDCurses;
45
+ PDCurses is the default there and is bootstrapped into
46
+ the build dir if not already installed
47
+ --enable-shared build/install zsv shared library
48
+ --ncurses-dynamic compile without NCURSES_STATIC
49
+ --enable-lto compile with LTO (works with some but not all platforms/compilers) [no]
50
+ --enable-whole-program compile without -fwhole-program even if no -flto [yes]
51
+ --enable-pie build with position independent executables [auto]
52
+ --enable-pic build with position independent shared libraries [auto]
53
+ --enable-termcap build with ncurses / termcap (used by \`pretty\` to get console width) [auto]
54
+ --disable-stdin disable stdin from CLI commands
55
+ --enable-simdutf use simdutf for 'check --utf8'. Faster, but adds ~300k to binary
56
+ --disable-only-crlf disable the --only-crlf parsing option
57
+ --disable-toon build without any TOON features (no 2toon command,
58
+ no compare --toon, no 2json --from-toon / 2toon --from-json)
59
+ --disable-tab-auto-recognize
60
+ do not auto-select tab delimiter for .tab input files
61
+ (.tsv is always recognized) [enabled]
62
+ --default-parser=fast|compat
63
+ set the default parsing engine when --parser is
64
+ not specified on the command line [compat]
65
+ --parallel-tempfile use temp files + sendfile for parallel select
66
+ output merge instead of in-memory buffers.
67
+ May be faster on systems with fast local storage [no]
68
+
69
+ Some influential environment variables:
70
+ CC C compiler command [detected]
71
+ AWK AWK tool command [detected]
72
+ MAKE gmake tool command [detected]
73
+ AR archive command [detected]
74
+ RANLIB ranlib archive indexer command [detected]
75
+ WINDRES Windows resource compiler, for mingw hosts [detected]
76
+ CFLAGS C compiler flags [-Os -pipe ...]
77
+ LDFLAGS Linker flags
78
+
79
+ CROSS_COMPILING=no Set to yes to disable auto-detect compilation flags
80
+ NO_THREADING=0 Set to 1 to disable threading
81
+
82
+ Use these variables to override the choices made by configure.
83
+
84
+ EOF
85
+ exit 0
86
+ }
87
+
88
+ # Helper functions
89
+
90
+ quote () {
91
+ tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
92
+ $1
93
+ EOF
94
+ printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
95
+ }
96
+ echo () { printf "%s\n" "$*" ; }
97
+ fail () { echo "$*" ; exit 1 ; }
98
+ # shellcheck disable=SC2329
99
+ fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
100
+ cmdexists () { type "$1" >/dev/null 2>&1 ; }
101
+ trycc1 () { test -z "$CC" && cmdexists "$1" && ( "$1" --version | grep -i gcc ) >/dev/null 2>/dev/null && CC=$1 ; }
102
+ trycc2 () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
103
+ tryar () { test -z "$AR" && cmdexists "$1" && AR=$1 ; }
104
+ tryranlib () { test -z "$RANLIB" && cmdexists "$1" && RANLIB=$1 ; }
105
+ trywindres () { test -z "$WINDRES" && cmdexists "$1" && WINDRES=$1 ; }
106
+ tryawk () { test -z "$AWK" && "$1" 'function works () {return 0} BEGIN{exit works()}' && AWK=$1 ; }
107
+ trymake() {
108
+ if test -z "$MAKE" && cmdexists "$1" ; then
109
+ v=$($1 --version | grep 'GNU Make' | sed -e 's/.*Make //')
110
+ if [ "$v" = "" ] ; then
111
+ printf "Found but not using non-GNU make (%s)..." "$1"
112
+ else
113
+ MAKE="$1"
114
+ maj=$(echo "$v" | cut -d. -f 1)
115
+ min=$(echo "$v" | cut -d. -f 2)
116
+ if ! test "$maj" -gt 3 -o '(' "$maj" -eq 3 -a "$min" -ge 81 ')'; then
117
+ printf "WARNING: using make, but version %s < 3.81 has not been tested. " "$v"
118
+ fi
119
+ fi
120
+ fi
121
+ }
122
+
123
+ stripdir () {
124
+ while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
125
+ }
126
+
127
+ NO_HAVE=
128
+ trycchdr () {
129
+ printf "checking whether there is a header called %s... " "$2"
130
+ dn=$(dirname "$2")
131
+ if [ "$dn" != "" ]; then
132
+ dn="/$dn"
133
+ bn=$(basename "$2")
134
+ for x in $CCSEARCHPATH ; do
135
+ fnd=$fnd"$x$dn "
136
+ done
137
+ else
138
+ bn="$2"
139
+ fnd=$CCSEARCHPATH
140
+ fi
141
+ upper2=$(echo "$2" | tr '[:lower:]' '[:upper:]' | tr . _ | tr / _)
142
+ if find "$fnd" -name "$bn" 2>/dev/null | grep "/$2$" >/dev/null 2>&1 ; then
143
+ eval "$1=\"\${$1} -DHAVE_\${upper2}\""
144
+ eval "$1=\${$1# }"
145
+ printf "yes\n"
146
+ return 0
147
+ else
148
+ printf "no\n"
149
+ NO_HAVE="$NO_HAVE
150
+ NO_$upper2 = 1"
151
+ return 1
152
+ fi
153
+ }
154
+
155
+ trycpusupport() {
156
+ rm -f "$tmpc"
157
+ printf "checking whether CPU accepts %s... " "$1"
158
+ cat >> "$tmpc" <<EOF
159
+ int main() {
160
+ if(__builtin_cpu_supports("$1"))
161
+ return 0;
162
+ return 1;
163
+ }
164
+ EOF
165
+ $CC -o "$tmpe" "$tmpc" >/dev/null 2>&1 && "$tmpe" && echo "yes" && return 0;
166
+ echo "no"
167
+ return 1;
168
+ }
169
+
170
+ tryccfn () {
171
+ rm -f "$tmpc"
172
+ if [ "$5" != "" ] ; then
173
+ printf "checking whether compiler accepts %s from %s with %s... " "$2" "$3" "$5"
174
+ echo "$5" >> "$tmpc"
175
+ else
176
+ printf "checking whether compiler accepts %s from %s..." "$2" "$3"
177
+ fi
178
+ if [ "$3" != "" ]; then
179
+ printf "%s\n" "$3" | sed 's/\(.*\)/#include <\1>/' >> "$tmpc"
180
+ fi
181
+ cat >> "$tmpc" <<EOF
182
+ int main() {$2;}
183
+ EOF
184
+ flag=$(echo "$2" | cut -d'(' -f1 | tr '[:lower:]' '[:upper:]')
185
+ if $CC -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
186
+ if [ "$4" != "" ] ; then
187
+ lib=$(echo "$4" | tr '[:lower:]' '[:upper:]' | tr . _)
188
+ USE_LIBS="$USE_LIBS
189
+ USE_LIB_$lib = 1"
190
+ fi
191
+
192
+ eval "vars=\$$1"
193
+ # shellcheck disable=SC2154
194
+ if ! printf "%s\n" "${vars}" | grep "\-DHAVE_${flag}\$" >/dev/null 2>&1; then
195
+ flag="-DHAVE_${flag}"
196
+ eval "$1=\"\${vars} \${flag}\""
197
+ eval "$1=\${$1# }"
198
+ fi
199
+ printf "yes\n"
200
+ return 0
201
+ else
202
+ printf "no\n"
203
+ NO_HAVE="$NO_HAVE
204
+ NO_$flag = 1"
205
+ {
206
+ echo "------"
207
+ echo "Failed: $CC -o $tmpo tmp.c"
208
+ cat "$tmpc"
209
+ echo "------"
210
+ } >>"$CONFIGFILE".log
211
+ return 1
212
+ fi
213
+ }
214
+
215
+ tryccfn1 () {
216
+ rm -f "$tmpc"
217
+ printf "checking whether compiler accepts %s(%s)..." "$2" "$3"
218
+ cat >> "$tmpc" <<EOF
219
+ int main() {$2($3);}
220
+ EOF
221
+ flag=$(echo "$2" | cut -d'(' -f1 | tr '[:lower:]' '[:upper:]')
222
+ if $CC -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
223
+ flag="-DHAVE_${flag}"
224
+ have=1
225
+ else
226
+ flag="-DNO_${flag}"
227
+ have=0
228
+ fi
229
+ eval "vars=\$$1"
230
+ if ! printf "%s\n" "${vars}" | grep "\-D${flag}\$" >/dev/null 2>&1; then
231
+ eval "$1=\"\${vars} \${flag}\""
232
+ eval "$1=\${$1# }"
233
+ fi
234
+ if [ "$have" = "1" ]; then
235
+ printf "yes\n"
236
+ return 0
237
+ else
238
+ printf "no\n"
239
+ return 1
240
+ fi
241
+ }
242
+
243
+ tryflag () {
244
+ printf "checking whether compiler accepts %s... " "$2"
245
+ echo "int main() {return 0;}" > "$tmpc"
246
+ # shellcheck disable=SC2086
247
+ if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
248
+ printf "yes\n"
249
+ eval "$1=\"\${$1} \$2\""
250
+ eval "$1=\${$1# }"
251
+ return 0
252
+ else
253
+ printf "no\n"
254
+ return 1
255
+ fi
256
+ }
257
+
258
+ tryldflag () { # var, flag, other_arguments (optional)
259
+ printf "checking whether linker accepts %s %s... " "$2" "$3"
260
+ echo "int main(){return 0;}" > "$tmpc"
261
+ # shellcheck disable=SC2086
262
+ if $CC $LDFLAGS "$2" $3 -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
263
+ printf "yes\n"
264
+ eval "$1=\"\${$1} \$2\""
265
+ eval "$1=\${$1# }"
266
+ return 0
267
+ else
268
+ printf "no\n"
269
+ return 1
270
+ fi
271
+ }
272
+
273
+ trysharedldflag () {
274
+ printf "checking whether linker accepts %s... " "$2"
275
+ echo "typedef int x;" > "$tmpc"
276
+ # shellcheck disable=SC2086
277
+ if $CC $LDFLAGS -shared "$2" -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
278
+ printf "yes\n"
279
+ eval "$1=\"\${$1} \$2\""
280
+ eval "$1=\${$1# }"
281
+ return 0
282
+ else
283
+ printf "no\n"
284
+ return 1
285
+ fi
286
+ }
287
+
288
+ # Beginning of actual script
289
+ if [ "$CROSS_COMPILING" = "" ]; then
290
+ CROSS_COMPILING=no
291
+ fi
292
+
293
+ if [ "$NO_THREADING" = "" ]; then
294
+ NO_THREADING="0"
295
+ fi
296
+
297
+ CFLAGS_AUTO=
298
+ CFLAGS_TRY=
299
+ LDFLAGS_AUTO=
300
+
301
+ # shellcheck disable=SC2034
302
+ LDFLAGS_TRY=
303
+
304
+ # CONFIGFILE=$CONFIGFILE
305
+ if [ "$CONFIGFILE" = "" ]; then
306
+ CONFIGFILE=config.mk
307
+ fi
308
+
309
+ if [ "$ARCH" = "" ] ; then
310
+ if [ "$CROSS_COMPILING" = "no" ]; then
311
+ ARCH=native
312
+ else
313
+ ARCH=none
314
+ fi
315
+ fi
316
+
317
+ # check prefixes first, since others may be derived from it unless overridden
318
+ # PREFIX=$PREFIX
319
+ for arg ; do
320
+ case "$arg" in
321
+ --prefix=*) PREFIX=${arg#*=} ;;
322
+ esac
323
+ done
324
+ if [ "$PREFIX" = "" ]; then
325
+ PREFIX=/usr/local
326
+ elif [ "$PREFIX" = "${PREFIX#/}" ]; then
327
+ PREFIX="$PWD/$PREFIX"
328
+ fi
329
+
330
+ # EXEC_PREFIX=$EXEC_PREFIX
331
+ for arg ; do
332
+ case "$arg" in
333
+ --exec-prefix=*) EXEC_PREFIX=${arg#*=} ;;
334
+ esac
335
+ done
336
+ if [ "$EXEC_PREFIX" = "" ]; then
337
+ EXEC_PREFIX=$PREFIX
338
+ elif [ "$EXEC_PREFIX" = "${EXEC_PREFIX#/}" ]; then
339
+ EXEC_PREFIX="$PWD/$EXEC_PREFIX"
340
+ fi
341
+
342
+ DOCDIR="$PREFIX/share/doc"
343
+ MANDIR="$PREFIX/share/man"
344
+
345
+ MINIMAL=no
346
+
347
+ TRY_SHEET=auto
348
+ BUILD_SHAREDLIB=0
349
+ TRY_LTO=no
350
+ TRY_WHOLE_PROGRAM=auto
351
+ FORCE_AVX2=auto
352
+ FORCE_AVX=auto
353
+ FORCE_SSE2=auto
354
+
355
+ NO_STDIN=
356
+
357
+ usepie=auto
358
+ usepic=auto
359
+ usetermcap=auto
360
+
361
+ ZSV_NO_PARALLEL=
362
+ ZSV_PARALLEL_TEMPFILE=
363
+ ZSV_NO_TOON=
364
+ ZSV_NO_TAB_AUTO_RECOGNIZE=
365
+ NCURSES_DYNAMIC=
366
+ for arg ; do
367
+ case "$arg" in
368
+ --help|-h) usage ;;
369
+ --host=*) host=${arg#*=} ;;
370
+
371
+ --arch=*) ARCH=${arg#*=} ;;
372
+ ARCH=*) ARCH=${arg#*=} ;;
373
+
374
+ --config-file=*) CONFIGFILE=${arg#*=} ;;
375
+ CONFIGFILE=*) CONFIGFILE=${arg#*=} ;;
376
+
377
+ --jq-prefix=*) JQ_PREFIX=${arg#*=} ;;
378
+ JQ_PREFIX=*) JQ_PREFIX=${arg#*=} ;;
379
+
380
+ --pcre2-8-prefix=*) PCRE2_8_PREFIX=${arg#*=} ;;
381
+ PCRE2_8_PREFIX=*) PCRE2_8_PREFIX=${arg#*=} ;;
382
+
383
+ --prefix=*) ;; # already handled
384
+ --exec-prefix=*) ;; # already handled EXEC_PREFIX=${arg#*=} ;;
385
+ --libdir=*) LIBDIR=${arg#*=} ;;
386
+ --docdir=*) DOCDIR=${arg#*=} ;;
387
+ --mandir=*) MANDIR=${arg#*=} ;;
388
+ --minimal|--minimal=yes) MINIMAL=yes;;
389
+
390
+ --no-parallel) ZSV_NO_PARALLEL=1;;
391
+ --parallel-tempfile|--parallel-tempfile=yes) ZSV_PARALLEL_TEMPFILE=1;;
392
+ --parallel-tempfile=no) ZSV_PARALLEL_TEMPFILE=;;
393
+
394
+ --try-avx512|--try-avx512=yes) TRY_AVX512=yes;;
395
+ --try-avx512=no) TRY_AVX512=no;;
396
+
397
+ --force-avx2|--force-avx2=yes) FORCE_AVX2=yes;;
398
+ --force-avx2=no) FORCE_AVX2=no;;
399
+
400
+ --force-avx|--force-avx=yes) FORCE_AVX=yes;;
401
+ --force-avx=no) FORCE_AVX=no;;
402
+
403
+ --force-sse2|--force-sse2=yes) FORCE_SSE2=yes;;
404
+ --force-sse2=no) FORCE_SSE2=no;;
405
+
406
+ --default-parser=fast) DEFAULT_PARSER_FAST=1;;
407
+ --default-parser=compat) DEFAULT_PARSER_FAST=;;
408
+
409
+ --ncurses-dynamic) NCURSES_DYNAMIC=1;;
410
+
411
+ --enable-sheet|--enable-sheet=yes) TRY_SHEET=yes;;
412
+ --enable-sheet=auto) TRY_SHEET=auto;;
413
+ --disable-sheet|--enable-sheet=no) TRY_SHEET=no;;
414
+ --with-pdcurses|--with-pdcurses=yes) USE_PDCURSES=yes;;
415
+ --without-pdcurses|--with-pdcurses=no) USE_PDCURSES=no;;
416
+
417
+ --enable-simdutf|--enable-simdutf=yes) USE_SIMDUTF=1;;
418
+ --enable-simdutf=auto) USE_SIMDUTF=0;;
419
+ --disable-simdutf|--enable-simdutf=no) USE_SIMDUTF=0;;
420
+
421
+ --enable-only-crlf|--enable-only-crlf=yes) ZSV_NO_ONLY_CRLF=0;;
422
+ --enable-only-crlf=auto) ZSV_NO_ONLY_CRLF=0;;
423
+ --disable-only-crlf|--enable-only-crlf=no) ZSV_NO_ONLY_CRLF=1;;
424
+
425
+ --enable-toon|--enable-toon=yes) ZSV_NO_TOON=0;;
426
+ --disable-toon|--enable-toon=no) ZSV_NO_TOON=1;;
427
+
428
+ --enable-tab-auto-recognize|--enable-tab-auto-recognize=yes) ZSV_NO_TAB_AUTO_RECOGNIZE=0;;
429
+ --disable-tab-auto-recognize|--enable-tab-auto-recognize=no) ZSV_NO_TAB_AUTO_RECOGNIZE=1;;
430
+
431
+ --enable-shared|--enable-shared=yes) BUILD_SHAREDLIB=1;;
432
+ --disable-shared|--enable-shared=no) BUILD_SHAREDLIB=0;;
433
+
434
+ --enable-lto|--enable-lto=yes) TRY_LTO=yes;;
435
+ --enable-lto=auto) TRY_LTO=auto;;
436
+ --disable-lto|--enable-lto=no) TRY_LTO=no;;
437
+
438
+ --enable-whole-program|--enable-whole-program=yes) TRY_WHOLE_PROGRAM=yes ;;
439
+ --disable-whole-program|--enable-whole-program=no) TRY_WHOLE_PROGRAM=no ;;
440
+
441
+ --enable-pie|--enable-pie=yes) usepie=yes ;;
442
+ --enable-pie=auto) usepie=auto ;;
443
+ --disable-pie|--enable-pie=no) usepie=no ;;
444
+
445
+ --enable-pic|enable-pic=yes) usepic=yes ;;
446
+ --enable-termcap|--enable-termcap=yes) usetermcap=yes ;;
447
+ --enable-termcap=auto) usetermcap=auto ;;
448
+ --disable-termcap|--enable-termcap=no) usetermcap=no ;;
449
+
450
+ --disable-stdin|--enable-stdin=no) NO_STDIN=1 ;;
451
+
452
+ --enable-pic=auto) usepic=auto ;;
453
+ --disable-pic|--enable-pic=no) usepic=no ;;
454
+ --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
455
+ -* ) echo "$0: unknown option $arg" ;;
456
+ CC=*) CC=${arg#*=} ;;
457
+ CFLAGS=*) CFLAGS=${arg#*=} ;;
458
+ CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
459
+ LDFLAGS=*) LDFLAGS=${arg#*=} ;;
460
+ *=*) ;;
461
+ *) ;;
462
+ esac
463
+ done
464
+
465
+ echo "config will be saved to $CONFIGFILE"
466
+
467
+ for i in PREFIX EXEC_PREFIX DOCDIR MANDIR ; do
468
+ stripdir $i
469
+ done
470
+
471
+ #
472
+ # Get a temp filename we can use
473
+ #
474
+ i=0
475
+ set -C
476
+ while : ; do
477
+ i=$((i+1))
478
+ tmpc="./conf$$-$PPID-$i.c"
479
+ tmpo="./conf$$-$PPID-$i.o"
480
+ tmpe="./conf$$-$PPID-$i._"
481
+ # shellcheck disable=SC2188
482
+ 2>|/dev/null > "$tmpc" && break
483
+ test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
484
+ done
485
+ set +C
486
+ trap 'rm -f "$tmpc" "$tmpo" "$tmpe"' EXIT QUIT TERM HUP
487
+ trap 'rm -f "$tmpc" "$tmpo" "$tmpe" && echo && fail "$0: interrupted"' INT
488
+
489
+ #
490
+ # Find an AWK tool to use
491
+ #
492
+ printf "checking for AWK tool... "
493
+ for a in awk gawk mawk nawk; do tryawk "$a"; done
494
+ printf "%s\n" "$AWK"
495
+ test -n "$AWK" || fail "$0: cannot find an AWK tool"
496
+
497
+ #
498
+ # Find a MAKE tool to use
499
+ #
500
+ printf "checking for MAKE tool... "
501
+ for a in make gmake ; do trymake "$a"; done
502
+ printf "%s\n" "$MAKE"
503
+ test -n "$MAKE" || fail "$0: cannot find a MAKE tool"
504
+
505
+ #
506
+ # Find a C compiler to use
507
+ #
508
+ printf "checking for C compiler... "
509
+ for c in cc gcc gcc-15 gcc-14 gcc-13 gcc-12 gcc-11 gcc-10 gcc-9 gcc-8 gcc-7 clang; do trycc1 "$c"; done
510
+ for c in cc gcc gcc-15 gcc-14 gcc-13 gcc-12 gcc-11 gcc-10 gcc-9 gcc-8 gcc-7 clang; do trycc2 "$c"; done
511
+ printf "%s\n" "$CC"
512
+ test -n "$CC" || fail "$0: cannot find a C compiler"
513
+
514
+ printf "checking whether C compiler works... "
515
+ echo "typedef int x;" > "$tmpc"
516
+ # shellcheck disable=SC2086
517
+ if output=$($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1) ; then
518
+ printf "yes\n"
519
+ else
520
+ fail "no; compiler output follows:\n%s\n" "$output"
521
+ fi
522
+
523
+ #
524
+ # Get compiler search paths
525
+ #
526
+ # shellcheck disable=SC2016
527
+ CCSEARCHPATH=$(echo | ${CC} -E -Wp,-v - 2>&1 | ${AWK} '/ \//{print substr($0,2);}')
528
+
529
+ #
530
+ # Check if it is clang, and the llvm tools instead
531
+ #
532
+ # shellcheck disable=SC2016
533
+ compiler=$(${CC} -v 2>&1 | ${AWK} '/ +version +/{for(i=1;i<=NF;i++){if($i=="version"){printf("%s\n",(last=="LLVM")?"clang":last);exit 0;}last=$i;}}')
534
+ if test "$compiler" = "clang"; then
535
+ arlist="$CC-llvm-ar $host-llvm-ar $CC-ar $host-ar llvm-ar $(ls /usr/bin/llvm-ar* 2>/dev/null) ar"
536
+ ranliblist="$CC-llvm-ranlib $host-llvm-ranlib $CC-ranlib $host-ranlib llvm-ranlib $(ls /usr/bin/llvm-ranlib* 2>/dev/null) ranlib"
537
+ else
538
+ arlist="$CC-ar $host-$compiler-ar $host-ar $compiler-ar ar"
539
+ ranliblist="$CC-ranlib $host-$compiler-ranlib $host-ranlib $compiler-ranlib $compiler-ranlib ranlib"
540
+ fi
541
+
542
+ #
543
+ # Find ar and ranlib to use
544
+ #
545
+ printf "checking for ar... "
546
+ for a in $arlist; do tryar "$a"; done
547
+ printf "%s\n" "$AR"
548
+ test -n "$AR" || fail "$0: cannot find ar"
549
+
550
+ printf "checking for ranlib... "
551
+ for r in $ranliblist ; do tryranlib "$r"; done
552
+ printf "%s\n" "$RANLIB"
553
+ test -n "$RANLIB" || fail "$0: cannot find ranlib"
554
+
555
+ #
556
+ # Detect the host system
557
+ #
558
+ printf 'checking host system type... '
559
+ test -n "$host" || host=$($CC -dumpmachine 2>/dev/null) || fail "could not determine host"
560
+ printf '%s\n' "$host"
561
+
562
+ # start the log
563
+ cat >"$CONFIGFILE".log <<_ACEOF
564
+ Config log. Invocation command line was
565
+ $ $0 $@
566
+
567
+ _ACEOF
568
+
569
+ #
570
+ # Figure out options to force errors on unknown flags.
571
+ #
572
+ tryflag CFLAGS_TRY -Werror=unknown-warning-option
573
+ tryflag CFLAGS_TRY -Werror=unused-command-line-argument
574
+ tryflag CFLAGS_TRY -Werror=ignored-optimization-argument
575
+ tryldflag LDFLAGS_STATIC -static
576
+ tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
577
+ tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
578
+ tryldflag LDFLAGS_TRY -Werror=ignored-optimization-argument
579
+
580
+ CFLAGS_STD="-std=gnu11 -D_POSIX_C_SOURCE=200809L -U_XOPEN_SOURCE -D_XOPEN_SOURCE=700"
581
+ MINGW=0
582
+ case "$host" in
583
+ *-*freebsd*) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE -D__BSD_VISIBLE=1" ;;
584
+ *-*netbsd*) CFLAGS_STD="$CFLAGS_STD -D_NETBSD_SOURCE" ;;
585
+ *-*bsd*) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE" ;;
586
+ *-*darwin*) CFLAGS_STD="$CFLAGS_STD -D_DARWIN_C_SOURCE" ;;
587
+ riscv*|*-riscv*) ARCH=none ;;
588
+ *-*mingw32|*-*msys*|*-windows-gnu)
589
+ CFLAGS_STD="$CFLAGS_STD -D__USE_MINGW_ANSI_STDIO"
590
+ MINGW=1
591
+ ARCH=none
592
+ usepie=no
593
+ usepic=no
594
+ ;;
595
+ esac
596
+
597
+ # config.mk's MINGW tells the Makefiles to build for Windows (.exe, Win32 code). An
598
+ # MSYS-runtime host shares the settings above but runs POSIX code, so it gets 0
599
+ case "$host" in
600
+ *-*msys*) MINGW_TARGET=0 ;;
601
+ *) MINGW_TARGET=$MINGW ;;
602
+ esac
603
+
604
+ #
605
+ # Find windres, which compiles the application manifest every Windows executable
606
+ # links (app/win/utf8-manifest.rc). A prefixed one (from the host triple, or from
607
+ # CC as in x86_64-w64-mingw32-clang) targets the right machine; a bare windres
608
+ # may default to another
609
+ #
610
+ if test "$MINGW_TARGET" = "1" ; then
611
+ printf "checking for windres... "
612
+ for w in "$host-windres" "${CC%-*}-windres" windres; do trywindres "$w"; done
613
+ printf "%s\n" "$WINDRES"
614
+ test -n "$WINDRES" || fail "$0: cannot find windres"
615
+ fi
616
+
617
+ if test "$usepie" = "auto" ; then
618
+ usepie=yes
619
+ fi
620
+
621
+ if test "$usepic" = "auto" ; then
622
+ usepic=yes
623
+ fi
624
+
625
+ tryflag CFLAGS_VECTORIZE -fvectorize
626
+ tryflag CFLAGS_VECTORIZE -ftree-vectorize
627
+ tryflag CFLAGS_VECTORIZE_OPTIMIZED -fopt-info-vec-optimized
628
+ tryflag CFLAGS_VECTORIZE_MISSED -fopt-info-vec-missed
629
+ tryflag CFLAGS_VECTORIZE_ALL -fopt-info-vec-all
630
+ tryflag CFLAGS_OPENMP -fopenmp
631
+
632
+ if [ "$TRY_SHEET" != "no" ]; then
633
+ # Curses backend selection. Exactly one library is chosen so that the
634
+ # HAVE_* macro (which selects the include in app/sheet/curses.h), the
635
+ # linked library, and NCLIB always agree. Defining more than one HAVE_*
636
+ # while linking only one library is what produced the "undefined reference
637
+ # to set_escdelay" link failure: the ncurses header declared the function
638
+ # but only PDCurses (which lacks it) was linked.
639
+ #
640
+ # On Windows/MinGW we prefer PDCurses (native Win32 console, no terminfo
641
+ # dependency); opt out with --without-pdcurses. Elsewhere we use
642
+ # ncursesw/ncurses. When PDCurses is preferred but not already installed
643
+ # (its header AND library), PDCURSES_BUILTIN is set and the Makefile
644
+ # bootstraps a private copy into the build directory from the vendored
645
+ # app/external/PDCurses tarball (see app/Makefile and app/external/build.mk).
646
+ case "$CONFIGURE_HOST" in
647
+ *mingw*) pdcurses_default=yes ;;
648
+ *) pdcurses_default=no ;;
649
+ esac
650
+ [ -z "$USE_PDCURSES" ] && USE_PDCURSES=$pdcurses_default
651
+
652
+ NCLIB=
653
+ PDCURSES_BUILTIN=0
654
+ if [ "$USE_PDCURSES" = "yes" ] ; then
655
+ NCLIB=pdcurses
656
+ if [ "$NCURSES_DYNAMIC" = "" ] ; then
657
+ CFLAGS_NCURSES="-DHAVE_PDCURSES -DPDCURSES_STATIC"
658
+ else
659
+ CFLAGS_NCURSES="-DHAVE_PDCURSES"
660
+ fi
661
+ # Probe for an already-usable PDCurses: its header must compile AND the
662
+ # library must link. A link-only probe is not enough -- e.g. a prefix
663
+ # may ship libpdcurses.a without the top-level curses.h.
664
+ printf "checking for an installed PDCurses (curses.h + -lpdcurses)... "
665
+ cat > "$tmpc" <<EOF
666
+ #include <curses.h>
667
+ int main(void) { initscr(); endwin(); return 0; }
668
+ EOF
669
+ # shellcheck disable=SC2086
670
+ if $CC $CPPFLAGS $CFLAGS_TRY $LDFLAGS "$tmpc" -lpdcurses -o "$tmpo" >/dev/null 2>&1 ; then
671
+ printf "yes\n"
672
+ LDFLAGS_NCURSES=-lpdcurses
673
+ else
674
+ printf "no; the build will bootstrap a private copy\n"
675
+ PDCURSES_BUILTIN=1
676
+ # Link flags for the builtin copy are supplied by the Makefile.
677
+ LDFLAGS_NCURSES=
678
+ fi
679
+ elif tryldflag LDFLAGS_NCURSESW -lncursesw -L"$PREFIX"/lib ; then
680
+ NCLIB=ncursesw
681
+ LDFLAGS_NCURSES=-lncursesw
682
+ if [ "$NCURSES_DYNAMIC" = "" ] ; then
683
+ CFLAGS_NCURSES="-DHAVE_NCURSESW -DNCURSES_STATIC"
684
+ else
685
+ CFLAGS_NCURSES="-DHAVE_NCURSESW"
686
+ fi
687
+ elif tryldflag LDFLAGS_NCURSES_PROBE -lncurses -L"$PREFIX"/lib ; then
688
+ NCLIB=ncurses
689
+ LDFLAGS_NCURSES=-lncurses
690
+ if [ "$NCURSES_DYNAMIC" = "" ] ; then
691
+ CFLAGS_NCURSES="-DHAVE_NCURSES -DNCURSES_STATIC"
692
+ else
693
+ CFLAGS_NCURSES="-DHAVE_NCURSES"
694
+ fi
695
+ fi
696
+
697
+ # 'sheet' renders multibyte (UTF-8) cells via the wide-character curses API
698
+ # (addnwstr/mvaddnwstr). A narrow curses library declares no such symbols, so
699
+ # a selected library is necessary but not sufficient: verify the chosen
700
+ # library actually links a wide-char call before enabling the feature.
701
+ # PDCurses is built/linked with PDC_WIDE (see app/sheet/curses.h), so it is
702
+ # treated as wide-capable without a probe; for the builtin PDCurses path the
703
+ # library does not exist yet (the Makefile bootstraps it), so a probe would
704
+ # spuriously fail. The ncurses/ncursesw probe compiles AND links (never runs
705
+ # the binary), so it is valid when cross-compiling.
706
+ HAVE_WIDE_CURSES=0
707
+ case "$NCLIB" in
708
+ pdcurses)
709
+ HAVE_WIDE_CURSES=1
710
+ ;;
711
+ ncursesw|ncurses)
712
+ printf "checking whether %s provides wide-character curses (addnwstr)... " "$NCLIB"
713
+ rm -f "$tmpc"
714
+ cat > "$tmpc" <<EOF
715
+ #define _GNU_SOURCE
716
+ #define _XOPEN_SOURCE_EXTENDED
717
+ #include <wchar.h>
718
+ #include "sheet/curses.h"
719
+ int main(void) { wchar_t w[1] = {0}; addnwstr(w, 0); return 0; }
720
+ EOF
721
+ # shellcheck disable=SC2086
722
+ if $CC $CPPFLAGS $CFLAGS_NCURSES -Iapp "$tmpc" $LDFLAGS $LDFLAGS_NCURSES -o "$tmpo" >/dev/null 2>&1 ; then
723
+ HAVE_WIDE_CURSES=1
724
+ printf "yes\n"
725
+ else
726
+ printf "no\n"
727
+ fi
728
+ ;;
729
+ esac
730
+
731
+ ZSVSHEET_BUILD=1
732
+ # A selected library (NCLIB) is what makes sheet buildable. For the builtin
733
+ # PDCurses path LDFLAGS_NCURSES is intentionally empty (filled in by the
734
+ # Makefile), so we must not gate on it here.
735
+ if [ "$NCLIB" = "" ] ; then
736
+ ZSVSHEET_BUILD=0
737
+ echo "WARNING: could not find a curses library; cannot build 'sheet' feature"
738
+ if [ "$TRY_SHEET" = "yes" ] ; then
739
+ echo "Error: --enable-sheet requested but no curses library is available"
740
+ exit 1
741
+ fi
742
+ elif [ "$HAVE_WIDE_CURSES" != "1" ] ; then
743
+ ZSVSHEET_BUILD=0
744
+ echo "WARNING: curses library '$NCLIB' lacks wide-character support (addnwstr); cannot build 'sheet' feature. Install a wide-character curses (e.g. ncursesw) to enable it."
745
+ if [ "$TRY_SHEET" = "yes" ] ; then
746
+ echo "Error: --enable-sheet requested but the available curses library lacks wide-character support (addnwstr)"
747
+ exit 1
748
+ fi
749
+ fi
750
+ fi
751
+
752
+ if test "$usepie" = "yes" ; then
753
+ tryflag CFLAGS_PIE -fpie || tryflag CFLAGS_PIE -fPIE
754
+ fi
755
+
756
+ if test "$usepic" = "yes" ; then
757
+ tryflag CFLAGS_PIC -fpic || tryflag CFLAGS_PIC -fPIC
758
+ fi
759
+
760
+ test "$usepie" = "yes" && tryldflag LDFLAGS_PIE -pie
761
+
762
+ if test "$usepic" = "yes" ; then
763
+ trysharedldflag LDFLAGS_PIC -fpic || trysharedldflag LDFLAGS_PIC -fPIC
764
+ fi
765
+
766
+ test "$usepie" = "no" && tryflag CFLAGS_PIE -fno-pie
767
+ test "$usepic" = "no" && tryflag CFLAGS_PIC -fno-pic
768
+ test "$usepie" = "no" && tryldflag LDFLAGS_PIE -no-pie
769
+ test "$usepic" = "no" && trysharedldflag LDFLAGS_PIC -fno-pic
770
+
771
+ tryflag CFLAGS -pipe
772
+
773
+ # Try flags to optimize speed
774
+ tryflag CFLAGS -ffunction-sections
775
+ tryflag CFLAGS -fdata-sections
776
+
777
+ CFLAGS_AVX=
778
+ if [ "$FORCE_AVX2" = "no" ]; then
779
+ tryflag CFLAGS -mno-avx2
780
+ elif [ "$FORCE_AVX2" = "yes" ] ; then
781
+ CFLAGS_AVX=-mavx2
782
+ if [ "$CROSS_COMPILING" = "no" ] ; then
783
+ trycpusupport avx2 || echo "WARNING: avx2 forced but not supported on native CPU"
784
+ fi
785
+ elif [ "$FORCE_AVX2" = "auto" ] && [ "$CROSS_COMPILING" = "no" ] ; then
786
+ trycpusupport avx2 && CFLAGS_AVX=-mavx2
787
+ fi
788
+
789
+ if [ "$FORCE_AVX" = "no" ]; then
790
+ tryflag CFLAGS -mno-avx
791
+ elif [ "$FORCE_AVX" = "yes" ] ; then
792
+ CFLAGS_AVX=-mavx || echo "WARNING: avx forced but not supported on native CPU"
793
+ elif [ "$FORCE_AVX" = "auto" ] && [ "$CFLAGS_AVX" = "" ] && [ "$CROSS_COMPILING" = "no" ] ; then
794
+ trycpusupport avx && CFLAGS_AVX=-mavx
795
+ fi
796
+
797
+ if [ "$FORCE_SSE2" = "no" ]; then
798
+ tryflag CFLAGS -mno-sse2
799
+ elif [ "$FORCE_SSE2" = "yes" ] ; then
800
+ CFLAGS_SSE=-msse2
801
+ if "$CC" --version | grep -i emcc >/dev/null; then
802
+ CFLAGS_SSE="$CFLAGS_SSE -msimd128 -experimental-wasm-simd"
803
+ fi
804
+ if [ "$CROSS_COMPILING" = "no" ] ; then
805
+ trycpusupport sse2 || echo "WARNING: sse2 forced but not supported on native CPU"
806
+ fi
807
+ elif [ "$FORCE_SSE2" = "auto" ] && [ "$CROSS_COMPILING" = "no" ] ; then
808
+ if [ "$CFLAGS_SSE" = "" ] && [ "$CROSS_COMPILING" = "no" ] ; then
809
+ if trycpusupport sse2 && tryflag CFLAGS_SSE -msse2 ; then
810
+ if "$CC" --version | grep -i emcc >/dev/null; then
811
+ CFLAGS_SSE="$CFLAGS_SSE -msimd128 -experimental-wasm-simd"
812
+ fi
813
+ fi
814
+ fi
815
+ fi
816
+
817
+ # Detect aarch64 NEON support (enables fast branchless parser engine)
818
+ HAVE_NEON=
819
+ if [ "$CROSS_COMPILING" = "no" ] ; then
820
+ rm -f "$tmpc"
821
+ printf "checking for aarch64 NEON support... "
822
+ cat > "$tmpc" <<EOF
823
+ #if defined(__aarch64__)
824
+ #include <arm_neon.h>
825
+ int main() { uint8x16_t v = vdupq_n_u8(0); (void)v; return 0; }
826
+ #else
827
+ #error "not aarch64"
828
+ #endif
829
+ EOF
830
+ if $CC $CFLAGS -o "$tmpe" "$tmpc" >/dev/null 2>&1 ; then
831
+ echo "yes"
832
+ HAVE_NEON=1
833
+ else
834
+ echo "no"
835
+ fi
836
+ fi
837
+
838
+ HAVE_LTO=0
839
+ if [ "$TRY_LTO" = "yes" ]; then
840
+ HAVE_LTO=1
841
+ CFLAGS_LTO="$CFLAGS_LTO -flto"
842
+ elif [ "$TRY_LTO" = "auto" ]; then
843
+ tryflag CFLAGS_LTO -flto && HAVE_LTO=1
844
+ fi
845
+
846
+ if [ "$TRY_WHOLE_PROGRAM" = "yes" ] ; then
847
+ if [ "$HAVE_LTO" = "0" ] ; then
848
+ LDFLAGS_OPT="$LDFLAGS_OPT -fwhole-program"
849
+ else
850
+ echo "Error: whole-program and lto are mutually exclusive; disable one or set both to auto"
851
+ exit 1
852
+ fi
853
+ elif [ "$TRY_WHOLE_PROGRAM" = "auto" ] ; then
854
+ if [ "$HAVE_LTO" = "0" ] ; then
855
+ tryldflag LDFLAGS_OPT -fwhole-program
856
+ else
857
+ echo "Have LTO, not trying -fwhole-program"
858
+ fi
859
+ fi
860
+
861
+ tryflag CFLAGS_VISIBILITY_HIDDEN -fvisibility=hidden
862
+ tryldflag LDFLAGS_AUTO -Wl,--gc-sections
863
+
864
+ if [ "$ARCH" != "none" ] ; then
865
+ if ! tryflag CFLAGS -march="$ARCH" ; then
866
+ echo "Flag -march=$ARCH failed!"
867
+ exit 1
868
+ fi
869
+ fi
870
+ tryldflag LDFLAGS_OPT -ldl
871
+
872
+ # Try hardening flags
873
+ if test "$usepie" = "yes" ; then
874
+ case "$LDFLAGS_PIE" in
875
+ *pie*)
876
+ tryldflag LDFLAGS_PIE -Wl,-z,now
877
+ tryldflag LDFLAGS_PIE -Wl,-z,relro
878
+ ;;
879
+ esac
880
+ fi
881
+ if test "$usepic" = "yes" ; then
882
+ case "$LDFLAGS_PIC" in
883
+ *pic*)
884
+ tryldflag LDFLAGS_PIC -Wl,-z,now
885
+ tryldflag LDFLAGS_PIC -Wl,-z,relro
886
+ ;;
887
+ esac
888
+ fi
889
+
890
+ # Check function availability
891
+ if [ "$TRY_AVX512" = "yes" ]; then
892
+ printf "checking whether avx512 instructions are available... "
893
+ HAVE_AVX512=
894
+ tryccfn CFLAGS_AVX_512 "_mm512_movepi8_mask" "immintrin.h" && \
895
+ trycchdr CFLAGS_AVX_512 "immintrin.h" && \
896
+ ( tryccfn CFLAGS_AVX_512 "_blsr_u64" "immintrin.h" || tryccfn CFLAGS_AVX_512 "__blsr_u64" "immintrin.h" ) && \
897
+ tryflag CFLAGS_AVX_512 "-mbmi" && \
898
+ tryflag CFLAGS_AVX_512 "-mavx512bw" && \
899
+ CFLAGS_AVX_512="-mbmi -mavx512bw -DHAVE_AVX512=1" && \
900
+ HAVE_AVX512=1
901
+ if [ "$HAVE_AVX512" = "1" ]; then
902
+ echo "yes"
903
+ else
904
+ echo "no"
905
+ echo "WARNING: --try-avx512 option enabled, but no avx512 instruction set available"
906
+ fi
907
+ fi
908
+
909
+ tryccfn CFLAGS_AUTO "memmem" "string.h"
910
+
911
+ if [ "$usetermcap" = "yes" ] || [ "$usetermcap" = "auto" ] ; then
912
+ # shellcheck disable=SC2015
913
+ tryccfn TERMCAP_H "tgetent" "termcap.h" && \
914
+ tryldflag LDFLAGS_TERMCAP -ltermcap && \
915
+ tryccfn CFLAGS_AUTO "tgetent" "termcap.h" termcap || \
916
+ if test "$usetermcap" = "yes"; then
917
+ echo "Error: --enable-termcap specified, but not found"
918
+ exit 1
919
+ fi
920
+ fi
921
+
922
+ # Auto-adopt the install PREFIX's jq only for a native build. When
923
+ # cross-compiling we cannot validate the host prefix's libjq (and the -ljq probe
924
+ # below is itself gated on CROSS_COMPILING=no, so the library would never get
925
+ # onto the link line). Leaving JQ_PREFIX empty routes the cross build to the
926
+ # vendored libjq, which app/Makefile cross-compiles via --host=$CONFIGURE_HOST.
927
+ if [ "$JQ_PREFIX" = "" ] && [ "$PREFIX" != "" ] && [ -f "$PREFIX/include/jq.h" ] && [ "$CROSS_COMPILING" = "no" ] ; then
928
+ JQ_PREFIX="$PREFIX"
929
+ fi
930
+
931
+ if [ "$JQ_PREFIX" != "" ] && [ "$CROSS_COMPILING" = "no" ] ; then
932
+ printf '%s' "checking --jq-prefix ${JQ_PREFIX} ... "
933
+ if ! tryldflag LDFLAGS_JQ -ljq -L"$JQ_PREFIX"/lib ; then
934
+ echo "Error: Failed to compile with -ljq and -L$JQ_PREFIX/lib"
935
+ exit 1
936
+ else # elif [ "$JQ_PREFIX" != "$PREFIX" ]; then
937
+ LDFLAGS_JQ="$LDFLAGS_JQ -L$JQ_PREFIX/lib"
938
+ fi
939
+ fi
940
+
941
+ tryldflag LDFLAGS_JQ -lm
942
+ tryldflag LDFLAGS_JQ -lshlwapi
943
+ if [ "$NO_THREADING" != "1" ]; then
944
+ if [ "$MINGW" = "1" ]; then
945
+ tryldflag LDFLAGS_TMP -pthread && STATIC_LIBS="$STATIC_LIBS -pthread"
946
+ else
947
+ tryldflag LDFLAGS_JQ -pthread
948
+ fi
949
+ fi
950
+
951
+ HAVE_PCRE2_8=
952
+ if [ "$PCRE2_8_PREFIX" = "" ] ; then
953
+ PCRE2_8_PREFIX=builtin
954
+ fi
955
+ if [ "$PCRE2_8_PREFIX" = "builtin" ] ; then
956
+ HAVE_PCRE2_8=1
957
+ else
958
+ if [ "$PCRE2_8_PREFIX" = "" ] && [ "$PREFIX" != "" ] && [ -f "$PREFIX/include/pcre2.h" ] ; then
959
+ PCRE2_8_PREFIX="$PREFIX"
960
+ fi
961
+
962
+ if [ "$PCRE2_8_PREFIX" != "no " ] ; then
963
+ if [ "$PCRE2_8_PREFIX" != "" ] && [ "$CROSS_COMPILING" = "no" ] ; then
964
+ # TO DO: check for pcre2 static lib
965
+ printf "%s" "checking --pcre2-8-prefix ${PCRE2_8_PREFIX} ... "
966
+ if ! tryldflag LDFLAGS_PCRE2_8 -lpcre2-8 -L"$PCRE2_8_PREFIX"/lib ; then
967
+ echo "Error: Failed to compile with -lpcre2-8 and -L$PCRE2_8_PREFIX/lib"
968
+ else
969
+ HAVE_PCRE2_8=1
970
+ fi
971
+ fi
972
+ fi
973
+ fi
974
+
975
+ tryccfn CFLAGS_AUTO "arc4random_uniform" "stdlib.h" || tryccfn CFLAGS_AUTO "rand_s" "stdlib.h" "" "#define _CRT_RAND_S"
976
+ tryccfn CFLAGS_AUTO "getentropy" "unistd.h"
977
+ tryccfn1 CFLAGS_AUTO "__builtin_expect" "0,0"
978
+ tryccfn1 CFLAGS_AUTO "__builtin_expect_with_probability" "0,0,0.5"
979
+
980
+ # Optional features
981
+ # shellcheck disable=SC2154
982
+ if test "$usedebugstderr" = "yes" ; then
983
+ USE_DEBUG_STDERR=1
984
+ else
985
+ USE_DEBUG_STDERR=0
986
+ fi
987
+
988
+ ZSV_EXTRAS=
989
+ if test "$MINIMAL" = "no" ; then
990
+ ZSV_EXTRAS=1
991
+ fi
992
+
993
+ if [ "$NO_THREADING" = "1" ]; then
994
+ ZSV_NO_PARALLEL=1
995
+ fi
996
+
997
+ printf "creating %s... " "$CONFIGFILE"
998
+
999
+ cmdline=$(quote "$0")
1000
+ for i ; do cmdline="$cmdline $(quote "$i")" ; done
1001
+
1002
+ exec 3>&1 1> "$CONFIGFILE"
1003
+
1004
+ [ -z "$LIBDIR" ] && LIBDIR=$EXEC_PREFIX/lib
1005
+
1006
+ cat << EOF
1007
+ # This version of $CONFIGFILE was generated by:
1008
+ # $cmdline
1009
+ # Any changes made here will be lost if configure is re-run
1010
+ PREFIX = $PREFIX
1011
+ EXEC_PREFIX = $EXEC_PREFIX
1012
+ BINDIR = $EXEC_PREFIX/bin
1013
+ LIBDIR = $LIBDIR
1014
+ INCLUDEDIR = $EXEC_PREFIX/include
1015
+
1016
+ DOCPREFIX = $DOCDIR
1017
+ MANPREFIX = $MANDIR
1018
+ CC = $CC
1019
+ AWK = $AWK
1020
+ MAKE = $MAKE
1021
+
1022
+ MINGW = $MINGW_TARGET
1023
+ AR = $AR
1024
+ RANLIB = $RANLIB
1025
+ WINDRES = $WINDRES
1026
+ CFLAGS = $CFLAGS
1027
+ LDFLAGS = $LDFLAGS
1028
+ CFLAGS_STD = $CFLAGS_STD
1029
+ LDFLAGS_STD = $LDFLAGS_STD
1030
+ CFLAGS_VISIBILITY_HIDDEN = $CFLAGS_VISIBILITY_HIDDEN
1031
+ LDFLAGS_OPT = $LDFLAGS_OPT
1032
+ LDFLAGS_TERMCAP = $LDFLAGS_TERMCAP
1033
+ JQ_PREFIX = $JQ_PREFIX
1034
+ LDFLAGS_JQ = $LDFLAGS_JQ
1035
+
1036
+ CONFIGURE_HOST = $host
1037
+
1038
+ HAVE_PCRE2_8 = $HAVE_PCRE2_8
1039
+ PCRE2_8_PREFIX = $PCRE2_8_PREFIX
1040
+
1041
+ STATIC_LIBS = $STATIC_LIBS
1042
+ CFLAGS_AUTO = $CFLAGS_AUTO
1043
+ CFLAGS_LTO = $CFLAGS_LTO
1044
+ LDFLAGS_AUTO = $LDFLAGS_AUTO
1045
+
1046
+ HAVE_AVX512 = $HAVE_AVX512
1047
+
1048
+ CFLAGS_AVX_512 = $CFLAGS_AVX_512
1049
+ CFLAGS_AVX = $CFLAGS_AVX
1050
+ CFLAGS_SSE = $CFLAGS_SSE
1051
+
1052
+ HAVE_NEON = $HAVE_NEON
1053
+
1054
+ DEFAULT_PARSER_FAST = $DEFAULT_PARSER_FAST
1055
+
1056
+ CFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g -Wall -Wextra -Wno-missing-field-initializers -Wunused # -g3 -ggdb
1057
+ LDFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g # -g3 -ggdb
1058
+ CFLAGS_PIC = $CFLAGS_PIC
1059
+ LDFLAGS_PIC = $LDFLAGS_PIC
1060
+ CFLAGS_PIE = $CFLAGS_PIE
1061
+ LDFLAGS_PIE = $LDFLAGS_PIE
1062
+ LDFLAGS_STATIC = $LDFLAGS_STATIC
1063
+ USE_DEBUG_STDERR = $USE_DEBUG_STDERR
1064
+ CFLAGS_VECTORIZE = $CFLAGS_VECTORIZE
1065
+ CFLAGS_VECTORIZE_OPTIMIZED = $CFLAGS_VECTORIZE_OPTIMIZED
1066
+ CFLAGS_VECTORIZE_MISSED = $CFLAGS_VECTORIZE_MISSED
1067
+ CFLAGS_VECTORIZE_ALL = $CFLAGS_VECTORIZE_ALL
1068
+ CFLAGS_OPENMP = $CFLAGS_OPENMP
1069
+
1070
+ LDFLAGS_NCURSES = $LDFLAGS_NCURSES
1071
+ CFLAGS_NCURSES = $CFLAGS_NCURSES
1072
+ PDCURSES_BUILTIN = $PDCURSES_BUILTIN
1073
+
1074
+ ZSV_EXTRAS = $ZSV_EXTRAS
1075
+
1076
+ BUILD_SHAREDLIB = $BUILD_SHAREDLIB
1077
+
1078
+ ZSVSHEET_BUILD = $ZSVSHEET_BUILD
1079
+
1080
+ NO_THREADING = $NO_THREADING
1081
+ ZSV_NO_PARALLEL = $ZSV_NO_PARALLEL
1082
+ ZSV_PARALLEL_TEMPFILE = $ZSV_PARALLEL_TEMPFILE
1083
+
1084
+ NO_STDIN = $NO_STDIN
1085
+
1086
+ USE_SIMDUTF = $USE_SIMDUTF
1087
+
1088
+ ZSV_NO_ONLY_CRLF = $ZSV_NO_ONLY_CRLF
1089
+
1090
+ ZSV_NO_TOON = $ZSV_NO_TOON
1091
+
1092
+ ZSV_NO_TAB_AUTO_RECOGNIZE = $ZSV_NO_TAB_AUTO_RECOGNIZE
1093
+
1094
+ $NO_HAVE
1095
+ $USE_LIBS
1096
+
1097
+ EOF
1098
+ exec 1>&3 3>&-
1099
+
1100
+ printf "done\n"
1101
+
1102
+ echo ""
1103
+ echo "*****************************************************************"
1104
+ echo "* zsv build configuration *"
1105
+ echo "*****************************************************************"
1106
+
1107
+ if [ "$JQ_PREFIX" != "" ]; then
1108
+ printf '%-64s*\n' "* - jq-prefix: $JQ_PREFIX"
1109
+ fi
1110
+
1111
+ if [ "$PCRE2_8_PREFIX" != "" ] && [ "$HAVE_PCRE2_8" = "1" ]; then
1112
+ printf '%-64s*\n' "* - pcre2-8-prefix: $PCRE2_8_PREFIX"
1113
+ else
1114
+ printf '%-64s*\n' "* - pcre2-8 -> NOT FOUND"
1115
+ printf '%-64s*\n' " select and sheet regex features will not be built"
1116
+ fi
1117
+
1118
+ if [ "$LDFLAGS_TERMCAP" = "" ]; then
1119
+ printf '%-64s*\n' "* - termcap: no. \`pretty\` will use default width assumption"
1120
+ else
1121
+ printf '%-64s*\n' "* - termcap: yes"
1122
+ fi
1123
+
1124
+ if [ "$BUILD_SHAREDLIB" = "1" ]; then
1125
+ printf '%-64s*\n' "* - build shared library: yes"
1126
+ else
1127
+ printf '%-64s*\n' "* - build shared library: no"
1128
+ fi
1129
+
1130
+ if [ "$ZSVSHEET_BUILD" = "1" ]; then
1131
+ printf '%-64s*\n' "* - build sheet feature: yes"
1132
+ if [ "$NCLIB" = "ncurses" ]; then
1133
+ printf '%-64s*\n' "* curses library: ncurses"
1134
+ elif [ "$NCLIB" = "ncursesw" ]; then
1135
+ printf '%-64s*\n' "* curses library: ncursesw"
1136
+ elif [ "$NCLIB" = "pdcurses" ]; then
1137
+ if [ "$PDCURSES_BUILTIN" = "1" ]; then
1138
+ printf '%-64s*\n' "* curses library: pdcurses (bootstrapped into build dir)"
1139
+ else
1140
+ printf '%-64s*\n' "* curses library: pdcurses"
1141
+ fi
1142
+ fi
1143
+ else
1144
+ printf '%-64s*\n' "* - build sheet feature: no"
1145
+ fi
1146
+
1147
+ if [ "$HAVE_AVX512" = "1" ]; then
1148
+ printf '%-64s*\n' "* - using 512-bit AVX instruction set"
1149
+ elif [ "$CFLAGS_AVX" = "-mavx2" ]; then
1150
+ printf '%-64s*\n' "* - using 256-bit AVX2 instruction set"
1151
+ elif [ "$CFLAGS_AVX" = "-mavx" ]; then
1152
+ printf '%-64s*\n' "* - using 128-bit + AVX instruction set"
1153
+ else
1154
+ printf '%-64s*\n' "* - using 128-bit vector size, no AVX"
1155
+ fi
1156
+
1157
+ if [ "$ZSV_NO_PARALLEL" = "1" ]; then
1158
+ printf '%-64s*\n' "* - CLI parallelization: DISABLED"
1159
+ else
1160
+ printf '%-64s*\n' "* - CLI parallelization: enabled"
1161
+ fi
1162
+
1163
+ if [ "$USE_SIMDUTF" = "1" ]; then
1164
+ printf '%-64s*\n' "* - CLI check utf8: using simdutf"
1165
+ else
1166
+ printf '%-64s*\n' "* - CLI check utf8: not using simdutf"
1167
+ fi
1168
+
1169
+ if [ "$ZSV_NO_ONLY_CRLF" = "1" ]; then
1170
+ printf '%-64s*\n' "* - only-crlf mode: DISABLED"
1171
+ else
1172
+ printf '%-64s*\n' "* - only-crlf mode: enabled"
1173
+ fi
1174
+
1175
+ if [ "$ZSV_NO_TOON" = "1" ]; then
1176
+ printf '%-64s*\n' "* - TOON features: DISABLED"
1177
+ else
1178
+ printf '%-64s*\n' "* - TOON features: enabled"
1179
+ fi
1180
+
1181
+ if [ "$ZSV_NO_TAB_AUTO_RECOGNIZE" = "1" ]; then
1182
+ printf '%-64s*\n' "* - .tab auto-recognize: DISABLED (.tsv still recognized)"
1183
+ else
1184
+ printf '%-64s*\n' "* - .tab/.tsv auto-recognize: enabled"
1185
+ fi
1186
+
1187
+ echo "*****************************************************************"
1188
+
1189
+ if ! [ "$MAKE" = "" ]; then
1190
+ echo
1191
+ echo "To build and install, run"
1192
+ echo " $MAKE install"
1193
+ echo
1194
+ echo "Other common commands:"
1195
+ echo " $MAKE # print available make commands"
1196
+ echo " (cd src && $MAKE install) # install library"
1197
+ echo " (cd app && $MAKE install) # install library and zsv CLI"
1198
+ echo " $MAKE uninstall # uninstall library and zsv CLI"
1199
+ echo " $MAKE clean # remove build artifacts"
1200
+ echo
1201
+ fi
1202
+
1203
+ if ! "$CC" --version | grep -i gcc >/dev/null && ! "$CC" --version | grep -i clang >/dev/null ; then
1204
+ echo "*********************** WARNING!! ***********************"
1205
+ echo "* Non-gcc/clang compiler untested; use at your own risk *"
1206
+ echo "* consider using gcc or clang instead e.g.: *"
1207
+ echo "* ./configure CC=gcc-11 *"
1208
+ echo "*********************************************************"
1209
+ echo ""
1210
+ fi
1211
+
1212
+ exit 0