-
Notifications
You must be signed in to change notification settings - Fork 5
/
configure
executable file
·1238 lines (1104 loc) · 32.5 KB
/
configure
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# rawhide - find files using pretty C expressions
# https://raf.org/rawhide
# https://github.com/raforg/rawhide
# https://codeberg.org/raforg/rawhide
#
# Copyright (C) 1990 Ken Stauffer, 2022-2023 raf <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses/>.
#
# 20231013 raf <[email protected]>
# Show the usage messge for --help
for opt in "$@"
do
case "$opt" in
--help|-h)
echo "$0 [options]"
echo "options:"
echo " --help, -h - Output this help message, then exit"
echo " --verbose, -v - Show resulting config diffs (Note: no option bundling)"
echo " --test, -n - Don't modify anything (Note: no option bundling)"
echo " --destdir=/path - Override DESTDIR in Makefile for building packages"
echo " --prefix=/path - Override platform-specific installation prefix"
echo " --etcdir=/path - Override platform-specific config directory"
echo " --mandir=/path - Override platform-specific manpage directory"
echo " --macports - Override default macOS config for macports"
echo " --macports-prefix=/path - Same as --macports with a non-default prefix"
echo " --enable-pcre2 - Enable PCRE2 support (default when present)"
echo " --disable-pcre2 - Disable PCRE2 support"
echo " --enable-acl - Enable ACL support (default when possible)"
echo " --disable-acl - Disable ACL support"
echo " --enable-ea - Enable EA support (default when possible)"
echo " --disable-ea - Disable EA support"
echo " --enable-attr - Enable attr/flag support (default when possible)"
echo " --disable-attr - Disable attr/flag support"
echo " --enable-flag - Alias for --enable-attr (BSD terminology)"
echo " --disable-flag - Alias for --disable-attr (BSD terminology)"
echo " --enable-magic - Enable libmagic support (default when possible)"
echo " --disable-magic - Disable libmagic support"
echo " --enable-ndebug - Enable NDEBUG (remove debugging code)"
echo " --disable-ndebug - Disable NDEBUG (keep debugging code - default)"
echo " --enable-mangz - Enable gzipped manpages (default on some systems)"
echo " --disable-mangz - Disable gzipped manpages (default)"
echo " --disable-major - Forget location of major/minor (for distribution)"
echo " --enable-gcov - Enable gcov test coverage measurement (do not install)"
echo " --disable-gcov - Disable gcov test coverage measurement (default)"
echo " --enable-ubsan - Enable the undefined behaviour sanitizer (do not install)"
echo " --disable-ubsan - Disable the undefined behaviour sanitizer (default)"
echo " --enable-asan - Enable the address sanitizer (do not install)"
echo " --disable-asan - Disable the address sanitizer (default)"
echo " --disable-cc-other - Forget non-default compiler (for distribution)"
echo " --static=SIZE - Adjust static memory: large (default), small, tiny"
echo " --default - Restore Makefile to its defaults (for distribution)"
echo
echo "Rawhide should compile on any POSIX system as is, but different systems"
echo "want software, configuration, and manpages to be in different locations."
echo "This configure script knows where to put things for several platforms:"
echo
echo " Linux, FreeBSD, OpenBSD, NetBSD, macOS/macports, Solaris, Cygwin"
echo ""
echo "To override the makefile \$(DESTDIR), use --destdir."
echo "This is for building packages and doesn't affect paths in the final binary."
echo ""
echo "To override a platform-specific install prefix, use --prefix (e.g. /opt/bin)."
echo "A synonym for --prefix=/usr/local is --prefix=default"
echo ""
echo "To override a platform-specific config directory, use --etcdir (e.g. /opt/etc)."
echo ""
echo "To override a platform-specific manpage directory, use --mandir (e.g. /opt/man)."
echo ""
echo "To compile for macports, use --macports (uses /opt/local for everything)."
echo "If you have a non-default macports prefix, use --macports-prefix instead."
echo ""
echo "It is highly recommended to have libpcre2-8 installed before running configure."
echo "It is optional, and rh is still much fun without it, but pcre greatly enhances"
echo "the level of fun to be had. It is enabled by default if it's available."
echo "To explicitly disable pcre2 and all the fun it brings, use --disable-pcre2."
echo ""
echo "If \$CC is set here, it will override the compiler in the Makefile."
echo ""
echo "\$CPPFLAGS, \$CFLAGS and \$LDFLAGS additions might need to be supplied to make"
echo "later."
echo ""
echo "The --static=SIZE option can reduce the sizes of static declarations for the"
echo "rawhide virtual machine. It might be useful on resource-constrained systems."
echo "But it just \"reduces\" unused virtual pages, so I'm not sure it does anything."
echo "But smaller settings do reduce resident memory noticeably, so it does something."
echo "See Makefile for more information."
echo ""
echo " large: code 2000000, stack 1000000, stringdata 200000, filerefs 10000 (default)"
echo " small: code 200000, stack 100000, stringdata 20000, filerefs 1000 (10%)"
echo " tiny: code 20000, stack 10000, stringdata 2000, filerefs 100 (1%)"
echo ""
echo "Note that small and tiny will cause tests/t12 parser error tests to fail."
echo "So you can run tests before changing this, or just not worry about them."
echo ""
echo "Note that --enable-ndebug will break the \"invalid -? option argument: wrong\""
echo "test in tests/t20. But that's OK."
echo ""
echo "The --enable-mangz and --disable-mangz are for systems that this configure"
echo "script doesn't know about. By default, manual entries are not gzipped, except"
echo "for the operating systems that configure knows prefer gzipped manual entries."
echo "If configure doesn't know about your operating system, and it does prefer"
echo "gzipped manual entries, then use --enable-mangz."
echo ""
echo "Don't --enable-gcov and then install the resulting binary."
echo ""
exit 0
;;
esac
done
# Record --verbose and --test early (for editconf)
test=0
verbose=0
for opt in "$@"
do
case "$opt" in
--verbose|-v)
verbose=1;
;;
--test|-n)
test=1;
;;
esac
done
# Handle --default (for distribution)
case "$1" in
--default|default)
set -- \
--destdir= --prefix=/usr/local --etcdir=/etc --mandir='$(PREFIX)/share/man' \
--disable-pcre2 --disable-acl --disable-ea --disable-attr --disable-magic \
--disable-ndebug --disable-mangz --disable-major --disable-gcov \
--disable-ubsan --disable-asan --disable-cc-other --static=large
;;
esac
# Fatal error message (for editconf)
die() { echo "$0: $@" >&2; exit 1; }
# Modify a file (Makefile) with sed (honours --verbose and --test)
editconf()
{
fname="$1"; shift
if [ $verbose = 1 ]
then
sed "$@" < "$fname" > "$fname.tmp"; diff -u "$fname" "$fname.tmp"; rm "$fname.tmp"
fi
if [ $test = 0 ]
then
sed "$@" < "$fname" > "$fname.tmp" && mv "$fname.tmp" "$fname" || die "failed to edit $fname"
fi
}
# Operating system preferences (installation locations and manual compression)
case "`uname`" in
Linux*) # prefix=/usr/local etcdir=/etc mandir=$prefix/share/man manzip=1
echo "Configuring for linux"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = /etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(MAN_GZIP =\) 0,\1 1,'
;;
FreeBSD*) # prefix=/usr/local etcdir=$prefix/etc mandir=$prefix/man manzip=1
echo "Configuring for freebsd"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = $(PREFIX)/etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/man,' \
-e 's,^\(MAN_GZIP =\) 0,\1 1,'
;;
NetBSD*) # prefix=/usr/pkg etcdir=$prefix/etc mandir=$prefix/man manzip=0
echo "Configuring for netbsd"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/pkg,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = $(PREFIX)/etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/man,' \
-e 's,^\(MAN_GZIP =\) 1,\1 0,'
;;
OpenBSD*) # prefix=/usr/local etcdir=$prefix/etc mandir=$prefix/man manzip=0
echo "Configuring for openbsd"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = $(PREFIX)/etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/man,' \
-e 's,^\(MAN_GZIP =\) 1,\1 0,'
;;
SunOS*|Solaris) # prefix=/usr/local etcdir=/etc mandir=$prefix/man manzip=0
echo "Configuring for Solaris"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = /etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(MAN_GZIP =\) 1,\1 0,'
;;
Darwin*) # prefix=/usr/local etcdir=/etc mandir=$prefix/share/man manzip=0
echo "Configuring for macos"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = /etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(MAN_GZIP =\) 1,\1 0,'
;;
CYGWIN_NT*) # prefix=/usr/local etcdir=/etc mandir=$prefix/share/man manzip=1
echo "Configuring for cygwin"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = /etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/share/man,' \
-e 's,^\(MAN_GZIP =\) 0,\1 1,'
;;
*)
echo "Unknown platform: Check Makefile for binary/config/manpage installation locations"
editconf Makefile \
-e 's,^\(PREFIX = \).*$,\1/usr/local,' \
-e 's,^ETCDIR,#ETCDIR,' -e 's,^#\(ETCDIR = $(PREFIX)/etc\),\1,' \
-e 's,^\(MAN_INSDIR = \).*$,\1$(PREFIX)/man,' \
-e 's,^\(MAN_GZIP =\) 1,\1 0,'
;;
esac
# Change from cc to gcc if cc is not in path (for Solaris)
[ -z "`command -v cc`" -a -n "`command -v gcc`" ] &&
editconf Makefile -e 's,^CC =,#CC =,' -e 's,^#\(CC = gcc\),\1,'
# Set CC from $CC (for macports)
if [ "x$CC" != x ]
then
echo "Configuring CC as $CC"
editconf Makefile \
-e 's/^\(CC = cc\)$/#\1/;' \
-e 's/^\(CC = gcc\)$/#\1/;' \
-e 's,^#CC = .*other$,CC = '"$CC"' # other,;'
fi
# Set $CC for tests below
[ -z "$CC" -a -n "`command -v cc`" ] && CC=cc
[ -z "$CC" -a -n "`command -v gcc`" ] && CC=gcc
# Compile a test program
compile_test()
{
"$CC" $CFLAGS $TEST_CFLAGS -o configchk configchk.c $TEST_LDFLAGS $LDFLAGS 2>/dev/null
rc=$?
if [ $rc != 0 ]; then TEST_CFLAGS=""; TEST_LDFLAGS=""; fi
rm -f configchk.c configchk
return $rc
}
# Look for ACL
create_acl_macos_code()
{
cat > configchk.c <<END
#include <stdio.h>
#include <sys/types.h>
#include <sys/acl.h>
int main(int ac, char **av)
{
acl_t acl;
if ((acl = acl_get_file(av[1], ACL_TYPE_EXTENDED))) /* ACL_TYPE_EXTENDED is an enum not a #define */
{
char *acl_text = acl_to_text(acl, NULL);
acl_free(acl);
if (acl_text)
{
printf("%s\n", acl_text);
acl_free(acl_text);
}
}
return 0;
}
END
}
test_acl_macos()
{
create_acl_macos_code
compile_test || return 1
echo "Configuring --enable-acl$acl_reason"
editconf Makefile \
-e 's,^#\(ACL_DEFINES =\).*$,\1 -DHAVE_ACL=1 -DHAVE_POSIX_ACL=1 -DHAVE_MACOS_ACL=1,' \
-e 's,^#\(ACL_CFLAGS =\).*$,\1,' \
-e 's,^#\(ACL_LDFLAGS =\).*$,\1,'
HAVE_ACL=1
return 0
}
create_acl_freebsd_code()
{
cat > configchk.c <<END
#include <stdio.h>
#include <sys/types.h>
#include <sys/acl.h>
int main(int ac, char **av)
{
acl_t acl;
if ((acl = acl_get_file(av[1], ACL_TYPE_NFS4)))
{
char *acl_text = acl_to_text(acl, NULL);
if (acl_text)
{
printf("%s\n", acl_text);
acl_free(acl_text);
}
acl_text = acl_to_text_np(acl, NULL, ACL_TEXT_VERBOSE);
acl_free(acl);
if (acl_text)
{
printf("%s\n", acl_text);
acl_free(acl_text);
}
}
return 0;
}
END
}
test_acl_freebsd()
{
create_acl_freebsd_code
compile_test || return 1
echo "Configuring --enable-acl$acl_reason"
editconf Makefile \
-e 's,^#\(ACL_DEFINES =\).*$,\1 -DHAVE_ACL=1 -DHAVE_POSIX_ACL=1 -DHAVE_FREEBSD_ACL=1,' \
-e 's,^#\(ACL_CFLAGS =\).*$,\1,' \
-e 's,^#\(ACL_LDFLAGS =\).*$,\1,'
HAVE_ACL=1
return 0
}
create_acl_posix_code()
{
cat > configchk.c <<END
#include <stdio.h>
#include <sys/types.h>
#include <sys/acl.h>
int main(int ac, char **av)
{
acl_t acl;
if ((acl = acl_get_file(av[1], ACL_TYPE_ACCESS)))
{
char *acl_text = acl_to_text(acl, NULL);
acl_free(acl);
if (acl_text)
{
printf("%s\n", acl_text);
acl_free(acl_text);
}
}
return 0;
}
END
}
test_acl_posix_native()
{
create_acl_posix_code
compile_test || return 1
echo "Configuring --enable-acl$acl_reason"
editconf Makefile \
-e 's,^#\(ACL_DEFINES =\).*$,\1 -DHAVE_ACL=1 -DHAVE_POSIX_ACL=1,' \
-e 's,^#\(ACL_CFLAGS =\).*$,\1,' \
-e 's,^#\(ACL_LDFLAGS =\).*$,\1,'
HAVE_ACL=1
return 0
}
test_acl_posix_libacl()
{
create_acl_posix_code
TEST_CFLAGS="`pkg-config --cflags libacl 2>/dev/null`"
[ $? = 0 ] || return 1
TEST_LDFLAGS="`pkg-config --libs libacl 2>/dev/null`"
compile_test || return 1
echo "Configuring --enable-acl$acl_reason"
editconf Makefile \
-e 's:^#\(ACL_DEFINES =\).*$:\1 -DHAVE_ACL=1 -DHAVE_POSIX_ACL=1:' \
-e 's:^#\(ACL_CFLAGS =\)$:\1 '"$TEST_CFLAGS"':' \
-e 's:^#\(ACL_LDFLAGS =\)$:\1 '"$TEST_LDFLAGS"':'
HAVE_ACL=1
TEST_CFLAGS=""
TEST_LDFLAGS=""
return 0
}
create_acl_solaris_code()
{
cat > configchk.c <<END
#include <stdlib.h>
#include <stdio.h>
#include <sys/acl.h>
int main(int ac, char **av)
{
acl_t *acl = NULL;
if (acl_get(av[1], ACL_NO_TRIVIAL, &acl) != -1 && acl)
{
char *acl_text = acl_totext(acl, ACL_COMPACT_FMT | ACL_SID_FMT);
acl_free(acl);
if (acl_text)
{
printf("%s\n", acl_text);
free(acl_text);
}
}
return 0;
}
END
}
test_solaris_acl_libsec()
{
create_acl_solaris_code
TEST_CFLAGS=""
TEST_LDFLAGS="-lsec"
compile_test || return 1
echo "Configuring --enable-acl$acl_reason"
editconf Makefile \
-e 's:^#\(ACL_DEFINES =\).*$:\1 -DHAVE_ACL=1 -DHAVE_SOLARIS_ACL=1:' \
-e 's:^#\(ACL_CFLAGS =\)$:\1 '"$TEST_CFLAGS"':' \
-e 's:^#\(ACL_LDFLAGS =\)$:\1 '"$TEST_LDFLAGS"':'
HAVE_ACL=1
TEST_CFLAGS=""
TEST_LDFLAGS=""
return 0
}
case "$*" in
*--disable-acl*)
;;
*)
case "$*" in *--enable-acl*) acl_reason="";; *) acl_reason=" (default)";; esac
test_acl_posix_libacl || test_acl_macos || test_acl_freebsd || test_solaris_acl_libsec || test_acl_posix_native
;;
esac
# Look for EA
create_ea_linux_code()
{
cat > configchk.c <<END
#include <stdio.h>
#include <sys/types.h>
#include <sys/xattr.h>
int main(int ac, char **av)
{
size_t keylistlen1 = listxattr(av[1], NULL, 0);
size_t keylistlen2 = llistxattr(av[1], NULL, 0);
size_t valuelen = getxattr(av[1], "key", NULL, 0);
return keylistlen1 && keylistlen2 && valuelen;
}
END
}
test_ea_linux()
{
[ "`uname`" = NetBSD ] && return 1 # NetBSD just sets errno = Not supported
create_ea_linux_code
compile_test || return 1
echo "Configuring --enable-ea$ea_reason"
editconf Makefile \
-e 's,^#\(EA_DEFINES =\).*$,\1 -DHAVE_EA=1 -DHAVE_LINUX_EA=1,' \
-e 's,^#\(EA_CFLAGS =\).*$,\1,' \
-e 's,^#\(EA_LDFLAGS =\).*$,\1,'
HAVE_EA=1
return 0
}
create_ea_macos_code()
{
cat > configchk.c <<END
#include <stdio.h>
#include <sys/xattr.h>
int main(int ac, char **av)
{
ssize_t keylistlen = listxattr(av[1], NULL, 0, XATTR_NOFOLLOW);
ssize_t varlen = getxattr(av[1], "name", NULL, 0, 0, XATTR_NOFOLLOW);
return keylistlen && varlen;
}
END
}
test_ea_macos()
{
create_ea_macos_code
compile_test || return 1
echo "Configuring --enable-ea$ea_reason"
editconf Makefile \
-e 's,^#\(EA_DEFINES =\).*$,\1 -DHAVE_EA=1 -DHAVE_MACOS_EA=1,' \
-e 's,^#\(EA_CFLAGS =\).*$,\1,' \
-e 's,^#\(EA_LDFLAGS =\).*$,\1,'
HAVE_EA=1
return 0
}
create_ea_freebsd_code()
{
cat > configchk.c <<END
#include <stdio.h>
#include <sys/types.h>
#include <sys/extattr.h>
int main(int ac, char **av)
{
ssize_t l = extattr_list_file(av[1], EXTATTR_NAMESPACE_USER, NULL, 0);
ssize_t g = extattr_get_file(av[1], EXTATTR_NAMESPACE_SYSTEM, "name", NULL, 0);
return l && g;
}
END
}
test_ea_freebsd()
{
[ "`uname`" = NetBSD ] && return 1 # NetBSD just sets errno = Not supported
create_ea_freebsd_code
compile_test || return 1
echo "Configuring --enable-ea$ea_reason"
editconf Makefile \
-e 's,^#\(EA_DEFINES =\).*$,\1 -DHAVE_EA=1 -DHAVE_FREEBSD_EA=1,' \
-e 's,^#\(EA_CFLAGS =\).*$,\1,' \
-e 's,^#\(EA_LDFLAGS =\).*$,\1,'
HAVE_EA=1
return 0
}
create_ea_solaris_code()
{
cat > configchk.c <<END
#include <unistd.h>
#include <fcntl.h>
int main(int ac, char **av)
{
long x = pathconf(av[1], _PC_XATTR_EXISTS);
int fd = attropen(av[1], ".", O_RDONLY | O_XATTR);
return x && fd;
}
END
}
test_ea_solaris()
{
create_ea_solaris_code
compile_test || return 1
echo "Configuring --enable-ea$ea_reason"
editconf Makefile \
-e 's,^#\(EA_DEFINES =\).*$,\1 -DHAVE_EA=1 -DHAVE_SOLARIS_EA=1,' \
-e 's,^#\(EA_CFLAGS =\).*$,\1,' \
-e 's,^#\(EA_LDFLAGS =\).*$,\1,'
HAVE_EA=1
return 0
}
case "$*" in
*--disable-ea*)
;;
*)
case "$*" in *--enable-ea*) ea_reason="";; *) ea_reason=" (default)";; esac
test_ea_linux || test_ea_macos || test_ea_freebsd || test_ea_solaris
;;
esac
# Look for Linux ext2-style attributes (pkg-config libe2p)
create_attr_linux_code()
{
cat > configchk.c << END
#include <e2p/e2p.h>
#include <ext2fs/ext2_fs.h>
int main(int ac, char **av)
{
char *fname = (ac > 1) ? av[1] : ".";
unsigned long flags, project, generation;
printf("%s:\n", fname);
if (fgetflags(fname, &flags) == -1)
perror("fgetflags");
if (fgetproject(fname, &project) == -1)
perror("fgetproject");
if (fgetversion(fname, &generation) == -1)
perror("fgetversion");
#define prflag(mask, label) if (flags & mask) printf("%s\n", label)
#ifdef EXT2_SECRM_FL
prflag(EXT2_SECRM_FL, " secrm");
#endif
#ifdef EXT2_UNRM_FL
prflag(EXT2_UNRM_FL, " unrm");
#endif
#ifdef EXT2_COMPR_FL
prflag(EXT2_COMPR_FL, " compr");
#endif
#ifdef EXT2_SYNC_FL
prflag(EXT2_SYNC_FL, " sync");
#endif
#ifdef EXT2_IMMUTABLE_FL
prflag(EXT2_IMMUTABLE_FL, " immutable");
#endif
#ifdef EXT2_APPEND_FL
prflag(EXT2_APPEND_FL, " append");
#endif
#ifdef EXT2_NODUMP_FL
prflag(EXT2_NODUMP_FL, " nodump");
#endif
#ifdef EXT2_NOATIME_FL
prflag(EXT2_NOATIME_FL, " noatime");
#endif
#ifdef EXT2_DIRTY_FL
prflag(EXT2_DIRTY_FL, " dirty");
#endif
#ifdef EXT2_COMPRBLK_FL
prflag(EXT2_COMPRBLK_FL, " comprblk");
#endif
#ifdef EXT2_NOCOMPR_FL
prflag(EXT2_NOCOMPR_FL, " nocompr");
#endif
#ifdef EXT4_ENCRYPT_FL
prflag(EXT4_ENCRYPT_FL, " encrypt");
#endif
#ifdef EXT2_INDEX_FL
prflag(EXT2_INDEX_FL, " index");
#endif
#ifdef EXT2_IMAGIC_FL
prflag(EXT2_IMAGIC_FL, " imagic");
#endif
#ifdef EXT3_JOURNAL_DATA_FL
prflag(EXT3_JOURNAL_DATA_FL, " journal_data");
#endif
#ifdef EXT2_NOTAIL_FL
prflag(EXT2_NOTAIL_FL, " notail");
#endif
#ifdef EXT2_DIRSYNC_FL
prflag(EXT2_DIRSYNC_FL, " dirsync");
#endif
#ifdef EXT2_TOPDIR_FL
prflag(EXT2_TOPDIR_FL, " topdir");
#endif
#ifdef EXT4_HUGE_FILE_FL
prflag(EXT4_HUGE_FILE_FL, " huge_file");
#endif
#ifdef EXT4_EXTENTS_FL
prflag(EXT4_EXTENTS_FL, " extents");
#endif
#ifdef EXT4_VERITY_FL
prflag(EXT4_VERITY_FL, " verity");
#endif
#ifdef EXT4_EA_INODE_FL
prflag(EXT4_EA_INODE_FL, " ea_inode");
#endif
#ifdef FS_NOCOW_FL
prflag(FS_NOCOW_FL, " nocow");
#endif
#ifdef EXT4_SNAPFILE_FL
prflag(EXT4_SNAPFILE_FL, " snapfile");
#endif
#ifdef FS_DAX_FL
prflag(FS_DAX_FL, " dax");
#endif
#ifdef EXT4_SNAPFILE_DELETED_FL
prflag(EXT4_SNAPFILE_DELETED_FL, " snapfile_deleted");
#endif
#ifdef EXT4_SNAPFILE_SHRUNK_FL
prflag(EXT4_SNAPFILE_SHRUNK_FL, " snapfile_shrunk");
#endif
#ifdef EXT4_INLINE_DATA_FL
prflag(EXT4_INLINE_DATA_FL, " inline_data");
#endif
#ifdef EXT4_PROJINHERIT_FL
prflag(EXT4_PROJINHERIT_FL, " projinherit");
#endif
#ifdef EXT4_CASEFOLD_FL
prflag(EXT4_CASEFOLD_FL, " casefold");
#endif
printf("project %lu\n", project);
printf("generation %lu\n", generation);
return 0;
}
END
}
test_attr_linux_libe2p()
{
create_attr_linux_code
TEST_CFLAGS="`pkg-config --cflags e2p 2>/dev/null`"
[ $? = 0 ] || return 1
TEST_LDFLAGS="`pkg-config --libs e2p 2>/dev/null`"
compile_test || return 1
echo "Configuring --enable-attr$attr_reason"
editconf Makefile \
-e 's:^#\(ATTR_DEFINES =\).*$:\1 -DHAVE_ATTR=1:' \
-e 's:^#\(ATTR_CFLAGS =\)$:\1 '"$TEST_CFLAGS"':' \
-e 's:^#\(ATTR_LDFLAGS =\)$:\1 '"$TEST_LDFLAGS"':'
HAVE_ATTR=1
TEST_CFLAGS=""
TEST_LDFLAGS=""
return 0
}
# Look for FreeBSD/OpenBSD/NetBSD/macOS flags
create_attr_bsd_code()
{
cat > configchk.c << END
#include <stdio.h>
#include <sys/stat.h>
int main(int ac, char **av)
{
struct stat buf[1];
if (stat(av[1], buf) == -1)
return 1;
if (buf->st_flags & SF_IMMUTABLE)
printf("immutable\n");
return 0;
}
END
}
test_attr_bsd()
{
create_attr_bsd_code
compile_test || return 1
echo "Configuring --enable-attr$attr_reason"
editconf Makefile \
-e 's:^#\(FLAG_DEFINES =\).*$:\1 -DHAVE_FLAGS=1:' \
-e 's:^#\(FLAG_CFLAGS =\)$:\1 '"$TEST_CFLAGS"':' \
-e 's:^#\(FLAG_LDFLAGS =\)$:\1 '"$TEST_LDFLAGS"':'
HAVE_ATTR=1
TEST_CFLAGS=""
TEST_LDFLAGS=""
return 0
}
case "$*" in
*--disable-attr*|*--disable-flag*)
;;
*)
case "$*" in *--enable-attr*|*--enable-flag*) attr_reason="";; *) attr_reason=" (default)";; esac
test_attr_linux_libe2p || test_attr_bsd
;;
esac
# Look for PCRE2 (pkg-config/pcre2-config libpcre2-8)
case "$*" in
*--disable-pcre2*)
;;
*)
case "$*" in *--enable-pcre2*) pcre2_reason="";; *) pcre2_reason=" (default)";; esac
PCRE2_CFLAGS="`pcre2-config --cflags 2>/dev/null`"
PCRE2_LDFLAGS="`pcre2-config --libs8 2>/dev/null`"
if [ $? != 0 ]
then
PCRE2_CFLAGS="`pkg-config --cflags libpcre2-8 2>/dev/null`"
PCRE2_LDFLAGS="`pkg-config --libs libpcre2-8 2>/dev/null`"
if [ $? != 0 ]
then
echo "Failed to find libpcre2-8 with pkg-config or pcre2-config."
echo "Please consider installing it, and then running $0 again."
echo "You won't regret it. But you don't have to. It is optional."
else
echo "Configuring --enable-pcre2$pcre2_reason"
editconf Makefile \
-e 's:^#\(PCRE2_DEFINES =\).*$:\1 -DHAVE_PCRE2=1:' \
-e 's:^#\(PCRE2_CFLAGS =\)$:\1 '"$PCRE2_CFLAGS"':' \
-e 's:^#\(PCRE2_LDFLAGS =\)$:\1 '"$PCRE2_LDFLAGS"':'
HAVE_PCRE2=1
fi
else
echo "Configuring --enable-pcre2$pcre2_reason"
editconf Makefile \
-e 's:^#\(PCRE2_DEFINES =\).*$:\1 -DHAVE_PCRE2=1:' \
-e 's:^#\(PCRE2_CFLAGS =\)$:\1 '"$PCRE2_CFLAGS"':' \
-e 's:^#\(PCRE2_LDFLAGS =\)$:\1 '"$PCRE2_LDFLAGS"':'
HAVE_PCRE2=1
fi
;;
esac
# Look for libmagic
create_libmagic_code()
{
cat > configchk.c <<END
#include <stdio.h>
#include <magic.h>
int main(int ac, char **av)
{
int flags = MAGIC_SYMLINK | MAGIC_COMPRESS | MAGIC_MIME | MAGIC_RAW;
magic_t m = magic_open(flags);
int loaded = magic_load(m, NULL);
printf("loaded = %d\n", loaded);
const char *output = magic_file(m, av[1]);
const char *error = magic_error(m);
printf("error: %s\n", error ? error : "(nil)");
printf("output: %s\n", output ? output : "(nil)");
magic_close(m);
return 0;
}
END
}
test_libmagic()
{
create_libmagic_code
TEST_CFLAGS="`pkg-config --cflags libmagic 2>/dev/null`"
[ $? = 0 ] || return 1
TEST_LDFLAGS="`pkg-config --libs libmagic 2>/dev/null`"
# The next line corrects a macports libmagic pkg-config file bug
[ x"$TEST_LDFLAGS" = x"-L/opt/local/lib -lmagic" ] && [ x"$TEST_CFLAGS" = x ] && TEST_CFLAGS="-I/opt/local/include"
compile_test || return 1
echo "Configuring --enable-magic$magic_reason"
editconf Makefile \
-e 's,^#\(MAGIC_DEFINES =\).*$,\1 -DHAVE_MAGIC=1,' \
-e 's,^#\(MAGIC_CFLAGS =\).*$,\1,' \
-e 's,^#\(MAGIC_LDFLAGS =\).*$,\1 -lmagic,'
HAVE_MAGIC=1
TEST_CFLAGS=""
TEST_LDFLAGS=""
return 0
}
case "$*" in
*--disable-magic*)
;;
*)
case "$*" in *--enable-magic*) magic_reason="";; *) magic_reason=" (default)";; esac
test_libmagic
;;
esac
# Look for major() and minor() in <sys/types.h> and <sys/mkdev.h> and <sys/sysmacros.h>.
create_major_minor_sys_types_code()
{
cat > configchk.c <<END
#include <sys/types.h>
int main(int ac, char **av)
{
dev_t d = (dev_t)0;
int major = major(d);
int minor = minor(d);
return 0;
}
END
}
test_major_minor_sys_types()
{
create_major_minor_sys_types_code
compile_test || return 1
#echo "Configuring without <sys/mkdev.h>"
#echo "Configuring without <sys/sysmacros.h>"
editconf Makefile \
-e 's,^\(HAVE_SYS_MKDEV =.*\)$,#\1,' \
-e 's,^\(HAVE_SYS_SYSMACROS =.*\)$,#\1,'
return 0
}
create_major_minor_sys_mkdev_code()
{
cat > configchk.c <<END
#include <sys/types.h>
#include <sys/mkdev.h>
int main(int ac, char **av)
{
dev_t d = (dev_t)0;
int major = major(d);
int minor = minor(d);
return 0;
}
END
}
test_major_minor_sys_mkdev()
{
create_major_minor_sys_mkdev_code
if compile_test
then
echo "Configuring with <sys/mkdev.h> (for major() and minor())"
editconf Makefile -e 's,^#\(HAVE_SYS_MKDEV =.*\)$,\1,'
return 0
else
#echo "Configuring without <sys/mkdev.h>"
editconf Makefile -e 's,^\(HAVE_SYS_MKDEV =.*\)$,#\1,'
return 1
fi
}
create_major_minor_sys_sysmacros_code()
{
cat > configchk.c <<END
#include <sys/types.h>
#include <sys/sysmacros.h>
int main(int ac, char **av)
{
dev_t d = (dev_t)0;
int major = major(d);
int minor = minor(d);
return 0;
}
END
}
test_major_minor_sys_sysmacros()
{
create_major_minor_sys_sysmacros_code
if compile_test
then
echo "Configuring with <sys/sysmacros.h> (for major() and minor())"
editconf Makefile -e 's,^#\(HAVE_SYS_SYSMACROS =.*\).*$,\1,'
return 0
else
#echo "Configuring without <sys/sysmacros.h>"
editconf Makefile -e 's,^\(HAVE_SYS_SYSMACROS =.*\)$,#\1,'
return 1
fi
}
case "$*" in
*--disable-major*)
;;
*)
# On Solaris <sys/mkdev.h> must be included, <sys/sysmacros.h> is optional but is not enough
# On old glibc, warnings happen via <sys/types.h> rather than <sys/sysmacros.h>
# So test mkdev then sysmacros then types
test_major_minor_sys_mkdev || test_major_minor_sys_sysmacros || test_major_minor_sys_types || echo "Failed to locate major() and minor(). Where are they?"
;;
esac
# Process command line options
for opt in "$@"
do
case "$opt" in
--verbose|-v)
;;
--test|-n)
;;
--destdir=*)
echo "Configuring $opt"
destdir="${opt#--destdir=}"
[ -n "$destdir" ] && destdir=" $destdir"
editconf Makefile 's,^\(DESTDIR =\).*$,\1'"$destdir"','