forked from networkupstools/nut
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure.ac
5559 lines (5042 loc) · 219 KB
/
configure.ac
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
dnl +------------------------------------------------------------------+
dnl | Network UPS Tools: configure.ac |
dnl +------------------------------------------------------------------+
dnl # Support for older autoconf without m4_esyscmd_s
m4_ifndef([m4_chomp_all], [m4_define([m4_chomp_all], [m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [/], [/ ]), [/*$]), [$1])])])
m4_ifndef([m4_esyscmd_s], [m4_define([m4_esyscmd_s], [m4_chomp_all(m4_esyscmd([$1]))])])
dnl NUT version number is defined here, with a Git suffixed macro like
dnl NUT_VERSION_MACRO "2.7.4-2838-gdfc3ac08"
dnl defined separately in include/nut_version.h (generated by make)
dnl ...or not defined, for quicker rebuilds, depending on settings.
dnl Old hard-coded approach (mangled a bit):
dnl AC INIT([nut],[2.8.2.1],[https://github.com/networkupstools/nut/issues])
dnl Note: srcdir is only set after AC INIT has completed, but $0 points
dnl to the generated configure script which is part of dist tarball and
dnl should be at source root too.
dnl Note: this gets evaluated (script called) a lot of times during autoconf
dnl but ends up as static strings in the generated configure script. It may
dnl be beneficial to have a `version.m4` generated by `autogen.sh` and/or
dnl shipped in a tarball, allowing for a singular include into configure.ac
dnl See https://github.com/networkupstools/nut/issues/1949 for details.
dnl Oddly, autoconf-2.69 on CentOS 7 both complains that AC INIT argument
dnl is not a literal, and does contain expected values in the generated
dnl script and include/config.h. A "pure" m4 solution would be quieter.
AC_INIT([nut],
m4_esyscmd_s([NUT_VERSION_QUERY=VER50 "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null]),
[https://github.com/networkupstools/nut/issues],[nut],
m4_esyscmd_s([NUT_VERSION_QUERY=URL "`dirname "$0"`/tools/gitlog2version.sh" 2>/dev/null]))
dnl See docs/maintainer-guide.txt about releases - updating the version
dnl above is a small part of the consistent ritual!
dnl Note: this refers to GITREV at the time of configure script running
dnl primarily for better messaging in the script itself (also to render
dnl the PDF documentation revision history via docs/docinfo.xml.in).
dnl If the NUT codebase in this workspace is being developed and rebuilt
dnl without reconfiguration, detailed version in the binaries will differ
dnl (that one comes from the NUT_VERSION_MACRO from nut_version.h file).
dnl # Example: NUT_SOURCE_GITREV='2.8.2.695.1-696-g0e00f0777'
NUT_SOURCE_GITREV="`NUT_VERSION_QUERY=DESC50 "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`"
dnl A true/false (literally) response that can be used for prettier messages
dnl emitted by NUT code.
NUT_SOURCE_GITREV_IS_RELEASE="`NUT_VERSION_QUERY=IS_RELEASE "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`"
AS_IF([$NUT_SOURCE_GITREV_IS_RELEASE], [NUT_SOURCE_GITREV_DEVREL="release"], [NUT_SOURCE_GITREV_DEVREL="development iteration"])
dnl Semantic version of most-recent NUT release this code is derived from.
dnl It may equal the NUT_SOURCE_GITREV and NUT_SOURCE_GITREV_NUMERIC, but
dnl this situation is only expected if NUT_SOURCE_GITREV_IS_RELEASE==true.
NUT_SOURCE_GITREV_SEMVER="`NUT_VERSION_QUERY=SEMVER "${srcdir}/tools/gitlog2version.sh" 2>/dev/null`"
dnl Gitrev-based build identifier which can be used for e.g. PyPI uploads:
dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1.696'
dnl # NUT_SOURCE_GITREV_NUMERIC="`echo "${NUT_SOURCE_GITREV}" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-/./g'`"
dnl # Without the commit-count since tag (dash-separated part):
dnl # Example: NUT_SOURCE_GITREV_NUMERIC='2.8.2.695.1'
NUT_SOURCE_GITREV_NUMERIC="`echo "${NUT_SOURCE_GITREV}" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-@<:@0-9@:>@*$//'`"
dnl Note: except for experiments, do not pass this into config.h - use
dnl the NUT_VERSION_MACRO from nut_version.h instead. Developers may
dnl want to disable their "force-nut-version-header" configure option
dnl to reduce rebuild scope and so speed up the iterations with ccache.
dnl New "config.h" contents for every reconfig would defeat that purpose!
dnl ### AS_IF([test -n "${NUT_SOURCE_GITREV-}"],
dnl ### [AC_DEFINE_UNQUOTED([NUT_SOURCE_GITREV], ["${NUT_SOURCE_GITREV}"], [NUT source revision when the build was configured])],
dnl ### [AC_DEFINE([NUT_SOURCE_GITREV], [NULL], [NUT source revision when the build was configured: not detected])])
dnl Keep track of command-line options passed to this script:
AC_MSG_CHECKING([for CONFIG_FLAGS])
CONFIG_FLAGS=""
dnl Keep each token quoted, in case spaces or other special chars crawl in:
_flag_enable_inplace_runtime=""
for F in "$@" ; do
case "$F" in
*=*" "*) NF="$(echo "$F" | sed "s,=,=',")""'" && F="$NF" ;;
esac
case "$F" in
--disable-inplace-runtime|--enable-inplace-runtime=no) _flag_enable_inplace_runtime="no" ;;
--enable-inplace-runtime*) _flag_enable_inplace_runtime="$F" ;;
*)
test -z "${CONFIG_FLAGS}" \
&& CONFIG_FLAGS="$F" \
|| CONFIG_FLAGS="${CONFIG_FLAGS} $F"
;;
esac
done
dnl Keep it "known" that we tried to re-use at least some local configuration
dnl so unspecified options are not necessarily at default values for this script
AS_IF([test x"${NUT_VERSION_DEPLOYED-}" = x"<reenter>"], [_flag_enable_inplace_runtime="reenter"])
F=""
AS_IF([test x"${NUT_VERSION_DEPLOYED-}" != x && test x"${NUT_VERSION_DEPLOYED-}" != x"<reenter>"], [
dnl Even if explicitly disabled... did we re-enter? Save the value to be seen:
F="--enable-inplace-runtime='${NUT_VERSION_DEPLOYED}'"
],[
AS_CASE(["${_flag_enable_inplace_runtime}"],
[no|""|reenter], [],
[F="${_flag_enable_inplace_runtime}"])
])
AS_IF([test x"$F" != x], [
test -z "${CONFIG_FLAGS}" \
&& CONFIG_FLAGS="$F" \
|| CONFIG_FLAGS="${CONFIG_FLAGS} $F"
])
unset _flag_enable_inplace_runtime
unset F
unset NF
AC_MSG_RESULT([${CONFIG_FLAGS}])
AC_DEFINE_UNQUOTED([CONFIG_FLAGS],["${CONFIG_FLAGS}"],[Flags passed to configure script])
AC_SUBST(CONFIG_FLAGS)
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_SRCDIR(server/upsd.c)
AC_CONFIG_MACRO_DIR([m4])
AS_IF([test x"${NUT_SOURCE_GITREV}" = x],
[echo "Network UPS Tools version ${PACKAGE_VERSION}"],
[AS_IF([test x"${NUT_SOURCE_GITREV}" = x"${PACKAGE_VERSION}"],
[echo "Network UPS Tools version ${PACKAGE_VERSION} ${NUT_SOURCE_GITREV_DEVREL}"],
[echo "Network UPS Tools version ${PACKAGE_VERSION} (${NUT_SOURCE_GITREV}) ${NUT_SOURCE_GITREV_DEVREL}"])
])
AC_CANONICAL_TARGET
NUT_CHECK_OS
NUT_STASH_WARNINGS
AC_CONFIG_HEADERS([include/config.h])
AC_PREFIX_DEFAULT(/usr/local/ups)
AM_INIT_AUTOMAKE([subdir-objects])
AS_CASE([${target_os}],
[*mingw*], [AS_CASE([${CFLAGS-}${CXXFLAGS-}],
[*"-std=c"*|*-ansi*], [
AC_MSG_NOTICE(
[-----------------------------------------------------------------------
WARNING: It seems you are building with MinGW and requested a strict C/C++
language mode. Per https://stackoverflow.com/a/76780217/4715872 MinGW may
not define WIN32 and other options needed for proper building and linking.
If this happens, please retry with GNU C/C++ language mode options instead.
-----------------------------------------------------------------------])
sleep 5
])]
)
dnl +-------------------------------------------------------------------
dnl Help avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2"
dnl at least if we intend to tune --with-debuginfo anyway (where we check
dnl if the caller asked for specific optimizations). Following some
dnl experimentation, we do not want to actually mangle the flags provided
dnl by autoconf - for GCC at least, the rightmost mentions of conflicting
dnl flags on command line win. We just want to know when it is okay to add
dnl ours. They may be inherited from "in-place" build setup though.
test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS="${CFLAGS-}"
test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS="${CXXFLAGS-}"
dnl +-------------------------------------------------------------------
dnl Default to `configure --enable-silent-rules` or `make V=1` for details?
dnl This feature seems to require automake-1.13 or newer (1.11+ by other info)
dnl On very old systems can comment it away with little loss (then automake-1.10
dnl is known to suffice):
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
[AC_MSG_NOTICE([Silent Rules feature not defined in this automake version, skipped])])
dnl +-------------------------------------------------------------------
dnl we need Autoconf 2.61 or better to enable features of Posix that are extensions to C
dnl (and actually 2.64 or better for m4/ax_check_compile_flag.m4 when it is sourced)
dnl UPDATE: As tested on CentOS 6, its "autoconf-2.63-5.1.el6.noarch" also suffices.
dnl But OpenBSD 6.5 requires autoconf-2.65 and automake-1.13 or newer...
dnl AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"])
dnl AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"])
AC_MSG_CHECKING(for autoconf macro to enable system extensions)
m4_version_prereq(2.61, [
AC_MSG_RESULT(yes)
dnl Causes calls to ac_prog stuff, so dittoed below if "no"
AC_USE_SYSTEM_EXTENSIONS
], [
AC_MSG_RESULT(no)
AC_PROG_CC
])
AC_PREREQ([2.63])
dnl #AC_PREREQ([2.64])
dnl Macro AC_PROG_CC_C99 is obsolete; use AC_PROG_CC
dnl Note that NUT does not support building with C89 anyway
dnl AC_PROG_CC_C99
dnl Needed for per-target flags
AM_PROG_CC_C_O
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_CXX_C_O
CFLAGS_AFTER_ACPROG="${CFLAGS-}"
CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"
dnl AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"])
dnl AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"])
dnl # LEGACY DEFAULT FALLBACK which NUT had since 2005 or before:
dnl # if autoconf does not set any options, use default/moderate optimizations
CFLAGS=${CFLAGS-"-O"}
dnl # Not so far a legacy, added for consistency in 2024 :)
CXXFLAGS=${CXXFLAGS-"-O"}
dnl +-------------------------------------------------------------------
dnl Use "./configure --enable-maintainer-mode" to keep Makefile.in and Makefile
dnl in sync after Git updates.
AM_MAINTAINER_MODE
dnl GNU and BSD make are okay with the syntax, but Sun make/dmake are not:
AC_MSG_CHECKING([whether this make implementation supports export VAR=VAL syntax])
dnl # using printf formatting for some funniner shells out there
nut_am_output="`printf 'export VAR=VAL\ntest:\n\t@echo "VAR=%s%sVAR%s"\n' '\$' '(' ')' | ${MAKE-make} -f - test`"
nut_am_result="$?"
AS_IF([test x"${nut_am_result}" = x0 -a x"${nut_am_output}" = x"VAR=VAL"], [
NUT_AM_MAKE_CAN_EXPORT=""
AC_MSG_RESULT(yes)
], [
NUT_AM_MAKE_CAN_EXPORT="#ThisMakeCanNotExport# "
AC_MSG_RESULT(no: got '${nut_am_output}')
])
AC_SUBST(NUT_AM_MAKE_CAN_EXPORT)
dnl Some systems have older autotools without direct macro support for PKG_CONF*
NUT_CHECK_PKGCONFIG
dnl Various version related processing
dnl ----------------------------------
dnl # the following is commented out, because the UPS_VERSION macro now
dnl # resides in include/nut_version.h, which is generated by Makefile.am,
dnl # rather than in include/config.h, which is generated by configure. The
dnl # reason is that the SVN revision should be computed at compile time,
dnl # not configure time.
dnl AC_DEFINE_UNQUOTED(UPS_VERSION, "${PACKAGE_VERSION}", [NUT version])
dnl However, automatically define the tree version (mostly for AC_SUBST)
dnl FIXME: This just picks first 3 chars, assuming single-digit components
dnl separated by a dot:
TREE_VERSION="`echo ${PACKAGE_VERSION} | awk '{ print substr($0,1,3) }'`"
AC_DEFINE_UNQUOTED(TREE_VERSION, "${TREE_VERSION}", [NUT tree version])
dnl Should not be necessary, since old servers have well-defined errors for
dnl unsupported commands:
NUT_NETVERSION="1.3"
AC_DEFINE_UNQUOTED(NUT_NETVERSION, "${NUT_NETVERSION}", [NUT network protocol version])
dnl Fix this early so we can expand with eval later
test "${prefix}" = "NONE" && prefix="${ac_default_prefix}"
test "${exec_prefix}" = "NONE" && exec_prefix='${prefix}'
dnl Note: for practical and platform-independent use, see AX_REALPATH macro
AC_CHECK_PROGS([REALPATH], [realpath], [])
dnl FIXME: remove after dev-testing
dnl UNITTEST_AX_REALPATH
dnl exit
dnl NOTE: for definition of NUT_* autoconf macros, see m4/ directory
dnl and docs/macros.txt
dnl +------------------------------------------------------------------+
dnl | default values for things later on (can be overridden) |
STATEPATH="/var/state/ups"
dnl Historically this refers to *system location* for PID files,
dnl and more specifically that for `upsmon` (running as `root`).
dnl See also ALTPIDPATH (defaulted to STATEPATH) setting below
dnl for the unprivileged daemons (`upsd`, drivers).
PIDPATH="/var/run"
dnl Honour new LFS recommendations if applied on the build system:
AS_IF([test -d "/run"], [PIDPATH="/run"])
AC_CHECK_PROGS([GETENT], [getent], [])
AC_CHECK_PROGS([ID], [id], [])
PROBE_OS_USER="false"
PROBE_OS_GROUP="false"
AS_IF([test x"${GETENT}" != x], [
PROBE_OS_USER="${GETENT} passwd "
PROBE_OS_GROUP="${GETENT} group "
],[
AS_IF([test x"${ID}" != x], [
PROBE_OS_USER="${ID} -u "
PROBE_OS_GROUP="${ID} -g "
],[
AC_MSG_WARN([Can not check existence of user and group accounts on this system])
])
]
)
dnl Defaults for respective configure options below
dnl Note these defaults may change further below depending on OS and
dnl certain other configure options (e.g. "in-place replacement")
RUN_AS_USER="nobody"
RUN_AS_GROUP="nobody"
AS_IF([test -n "`${PROBE_OS_GROUP} nogroup`" && ! test -n "`${PROBE_OS_GROUP} "${RUN_AS_GROUP}"`"],
[RUN_AS_GROUP="nogroup"]
)
dnl NOTE: NUT legacy default, keep as is for least surprise
dnl Distributions are however welcome to specify the option to use tmpfs
AS_CASE([${target_os}],
[*mingw*], [POWERDOWNFLAG="C:\\\\killpower"], dnl NOTE: Double backslashes (times escaping) are correct!
[POWERDOWNFLAG="/etc/killpower"] dnl POSIX systems default
)
cgiexecdir='${exec_prefix}/cgi-bin'
driverexecdir='${exec_prefix}/bin'
dnl Note: htmldir per se is originally for nut-cgi resources
htmldir='${prefix}/html'
htmldocdir='${docdir}/html-doc'
htmlmandir='${docdir}/html-man'
pkgconfigdir='${libdir}/pkgconfig'
dnl Detection of augeas lens dirs is a bit troublesome, since
dnl they (if present) reside in location not controlled by NUT.
dnl Try detecting based on build parameters, or fall back to
dnl hard-coded default location (may break e.g. distcheck).
dnl Note it would not work too well for "/usr/local/ups" :)
auglensdir='${datarootdir}/augeas/lenses/dist'
conftemp="${auglensdir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
if test ! -d "${conftemp}"; then
auglensdir='${datarootdir}/augeas/lenses'
conftemp="${auglensdir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
if test ! -d "${conftemp}"; then
auglensdir='/usr/share/augeas/lenses/dist'
if test ! -d "${auglensdir}"; then
auglensdir='/usr/share/augeas/lenses'
if test ! -d "${auglensdir}"; then
auglensdir=''
fi
fi
fi
fi
dnl ### NUT_CHECK_LIBREGEX ### Detect below as part of libusb etc.
dnl ### LIBREGEX_LIBS=''
dnl Disable Hotplug, DevD and udev support on Windows
dnl (useful when cross-compiling)
case "${target_os}" in
*mingw* )
dnl TODO: Actually detect it? See also nut_check_libregex.m4 for same.
dnl Here we assumed from practice that it is available...
dnl ### if test x"${LIBREGEX_LIBS}" = x ; then
dnl ### LIBREGEX_LIBS='-lregex'
dnl ### fi
hotplugdir=''
udevdir=''
devddir=''
;;
* )
hotplugdir='/etc/hotplug'
if test ! -d "${hotplugdir}"; then
hotplugdir=''
fi
udevdir='/lib/udev'
if test ! -d "${udevdir}"; then
udevdir='/etc/udev'
if test ! -d "${udevdir}"; then
udevdir=''
fi
fi
devddir='/usr/local/etc/devd'
if test ! -d "${devddir}"; then
devddir='/etc/devd'
if test ! -d "${devddir}"; then
devddir=''
fi
fi
;;
esac
dnl Note: this deals with run-time settings so that the newly built
dnl programs can be "just executed" to use same configuration files
dnl and filesystem object permissions as an older deployment of NUT
dnl on this system; this specifically does not deal with trying to
dnl use same prefix and other paths to fully replace an older setup
dnl (a different option might be crafted to do that, but really the
dnl arcane distro-dependent packaging recipes are a better way here).
dnl This feature is intended for users who want to see if a custom
dnl build of NUT supports their hardware or other use-cases better.
NUT_ARG_ENABLE([inplace-runtime],
[Request configure option defaults for runtime user/group/confpath based on currently installed NUT (to extent these can be detected)],
[no])
dnl Check for not re-entering in this run - whether NUT_VERSION_DEPLOYED is set
AS_IF([test x"$nut_enable_inplace_runtime" = xyes -a x"${NUT_VERSION_DEPLOYED-}" = x], [
AC_MSG_NOTICE([checking for location, CONFIG_FLAGS and version of an already deployed NUT build (if it reports those)])
dnl If existing NUT installation reports its build options, re-run this
dnl script with those flags (overridden by any options passed currently):
conftemp="${sbindir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
PREFIX_SBINDIR="${conftemp}"
conftemp="${bindir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
PREFIX_BINDIR="${conftemp}"
DEPLOYED_SBINDIR="${PREFIX_SBINDIR}"
DEPLOYED_BINDIR="${PREFIX_BINDIR}"
dnl Note use of AC_PATH_PROG for specific pathname (not AC_CHECK_PROGS which picks filename variants)!
dnl Note: "ordinary" users might not have "sbin" in their default PATH, so appending it:
dnl Note: in some systems, the file in PATH is a shell
dnl wrapper for /etc/nut/nut.conf MODE support
AC_PATH_PROG([DEPLOYED_UPSD], [upsd], [], [${PREFIX_SBINDIR}:${PATH}:/sbin:/usr/sbin:/usr/local/sbin])
dnl ...however "upsc" is a userland tool so should be there:
AC_PATH_PROG([DEPLOYED_UPSC], [upsc], [], [${PREFIX_BINDIR}:${PATH}])
AS_IF([test -x "${DEPLOYED_UPSD}"], [
AX_REALPATH([$DEPLOYED_UPSD], [DEPLOYED_UPSD])
DEPLOYED_SBINDIR="`dirname "${DEPLOYED_UPSD}"`"
])
AS_IF([test -x "${DEPLOYED_UPSC}"], [
AX_REALPATH([$DEPLOYED_UPSC], [DEPLOYED_UPSC])
DEPLOYED_BINDIR="`dirname "${DEPLOYED_UPSC}"`"
])
DEPLOYED_PREFIX=""
AS_IF([test -d "${DEPLOYED_SBINDIR}"],
[DEPLOYED_PREFIX="`dirname "${DEPLOYED_SBINDIR}"`"],
[AS_IF([test -d "${DEPLOYED_BINDIR}"],
[DEPLOYED_PREFIX="`dirname "${DEPLOYED_BINDIR}"`"])]
)
AC_MSG_CHECKING([for CONFIG_FLAGS of an already deployed NUT build (if it reports those)])
CONFIG_FLAGS_DEPLOYED=""
NUT_VERSION_DEPLOYED=""
dnl TODO: Similar query can be done for BINDIR tools
dnl and for libupsclient-config if deployed locally
for DEPLOYED_TOOL in \
"${DEPLOYED_UPSD}" \
"${DEPLOYED_UPSC}" \
; do
AS_IF([test x"${DEPLOYED_TOOL}" = x], [continue])
AS_IF([test -x "${DEPLOYED_TOOL}"], [], [continue])
AC_MSG_CHECKING([for CONFIG_FLAGS from ${DEPLOYED_TOOL}])
CONFIG_FLAGS_DEPLOYED="`"${DEPLOYED_TOOL}" -DV 2>&1 | grep 'configured with flags:' | head -1 | sed 's,^.*configured with flags: *,,'`" \
&& test x"${CONFIG_FLAGS_DEPLOYED}" != x \
|| CONFIG_FLAGS_DEPLOYED=""
NUT_VERSION_DEPLOYED="`"${DEPLOYED_TOOL}" -DV 2>&1 | grep 'configured with flags:' | head -1 | sed 's,^.*Network UPS Tools version \(.*\) configured with flags:.*$,\1,'`" \
&& test x"${NUT_VERSION_DEPLOYED}" != x \
|| NUT_VERSION_DEPLOYED=""
AS_IF([test x"${CONFIG_FLAGS_DEPLOYED}${NUT_VERSION_DEPLOYED}" = x], [], [break])
done
AS_IF([test x"${CONFIG_FLAGS_DEPLOYED}" != x], [
AC_MSG_RESULT([CONFIG_FLAGS_DEPLOYED: ${CONFIG_FLAGS_DEPLOYED}])
],[
AC_MSG_RESULT([CONFIG_FLAGS_DEPLOYED: not reported])
])
dnl Account for custom paths if known/found:
AS_IF([test x"${DEPLOYED_PREFIX}" != x && test x"${DEPLOYED_PREFIX}" != x"${prefix}"],
AC_MSG_WARN([Deployed NUT installation uses a PREFIX different from one specified (wins) or derived (loses) for this build: '${DEPLOYED_PREFIX}' vs. '${prefix}'])
[AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--prefix=*], [],
[CONFIG_FLAGS_DEPLOYED="${CONFIG_FLAGS_DEPLOYED} --prefix='${DEPLOYED_PREFIX}'"])
])
AS_IF([test x"${DEPLOYED_SBINDIR}" != x && test x"${DEPLOYED_SBINDIR}" != x"${PREFIX_SBINDIR}"],
AC_MSG_WARN([Deployed NUT installation uses a SBINDIR different from one specified (wins) or derived (loses) for this build: '${DEPLOYED_SBINDIR}' vs. '${sbindir}'])
[AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--sbindir=*], [],
[CONFIG_FLAGS_DEPLOYED="${CONFIG_FLAGS_DEPLOYED} --sbindir='${DEPLOYED_SBINDIR}'"])
])
AS_IF([test x"${DEPLOYED_BINDIR}" != x && test x"${DEPLOYED_BINDIR}" != x"${PREFIX_BINDIR}"],
AC_MSG_WARN([Deployed NUT installation uses a BINDIR different from one specified (wins) or derived (loses) for this build: '${DEPLOYED_BINDIR}' vs. '${bindir}'])
[AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--bindir=*], [],
[CONFIG_FLAGS_DEPLOYED="${CONFIG_FLAGS_DEPLOYED} --bindir='${DEPLOYED_BINDIR}'"])
])
AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--sysconfdir=*], [
for F in ${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS} ; do
case "$F" in
"--sysconfdir="*) sysconfdir="`echo "$F" | ( IFS='=' read K V ; echo "$V" )`" ;;
esac
done
],
[
dnl If there was no custom --sysconfdir=/etc/myNUT passed,
dnl try to default it to something from existing deployment.
dnl NOTE: Single-quotes are correct for autotools default,
dnl expanded at runtime (see conftemp tricks below)
AC_MSG_CHECKING([for in-place replacement default sysconfdir (better than '${sysconfdir}')])
DEPLOYED_SYSCONFDIR=""
dnl TODO: Any more reasonable defaults? Pile them on here :)
for D in \
/etc/nut /etc/ups \
/usr/etc/nut /usr/etc/ups \
/usr/local/etc/nut /usr/local/etc/ups \
/usr/local/nut/etc /usr/local/ups/etc \
; do
if test -e "$D/ups.conf" || test -e "$D/upsmon.conf" \
|| ( test -e "$D/upsd.conf" && test -e "$D/upsd.users" ) \
; then
DEPLOYED_SYSCONFDIR="$D"
break
else
if test -d "$D/" && test ! -r "$D/" ; then
dnl Keeping order of preference defined by "for" loop:
AC_MSG_WARN([Picking directory '${D}' which exists but current build user may not read])
DEPLOYED_SYSCONFDIR="$D"
break
fi
fi
done
AS_IF([test -n "${DEPLOYED_SYSCONFDIR}"], [
AC_MSG_RESULT([${DEPLOYED_SYSCONFDIR}])
dnl May be used in searches below:
sysconfdir="${DEPLOYED_SYSCONFDIR}"
CONFIG_FLAGS_DEPLOYED="${CONFIG_FLAGS_DEPLOYED} --sysconfdir='${DEPLOYED_SYSCONFDIR}'"
], [
AC_MSG_RESULT([not detected])
])
])
dnl Prepare paths that may be used in user/group searches below:
conftemp="${sysconfdir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
CONFPATH="${conftemp}"
AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--libdir=*], [
for F in ${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS} ; do
case "$F" in
"--libdir="*) libdir="`echo "$F" | ( IFS='=' read K V ; echo "$V" )`" ;;
esac
done
]
)
conftemp="${libdir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
LIBDIR="${conftemp}"
AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--libexecdir=*], [
for F in ${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS} ; do
case "$F" in
"--libexecdir="*) libexecdir="`echo "$F" | ( IFS='=' read K V ; echo "$V" )`" ;;
esac
done
]
)
conftemp="${libexecdir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
LIBEXECDIR="${conftemp}"
AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--with-pkgconfig-dir=*], [
for F in ${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS} ; do
case "$F" in
"--with-pkgconfig-dir="*) pkgconfigdir="`echo "$F" | ( IFS='=' read K V ; echo "$V" )`" ;;
esac
done
]
)
dnl pkgconfigdir may have more indirections:
conftemp="${pkgconfigdir}"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
eval conftemp=\"${conftemp}\"
PKGCONFIGDIR="${conftemp}"
AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--with-group=*], [],
[
AC_MSG_CHECKING([for in-place replacement default group (better than '${RUN_AS_GROUP}')])
nut_inplace_group=""
AS_IF([test -d "${udevdir}/rules.d"],
[for F in "${udevdir}/rules.d"/*-nut-*.rules ; do
if test -s "$F" ; then
nut_inplace_group="`grep GROUP= "$F" | head -1 | sed 's,^.* GROUP="*\(.*\)"*.*$,\1,'`" \
&& test -n "`${PROBE_OS_GROUP} "${nut_inplace_group}"`" \
&& AC_MSG_RESULT([Got from ${F}]) \
&& break \
|| nut_inplace_group=""
fi
done
])
AS_IF([test -z "${nut_inplace_group}"],
[AS_IF([test -n "`${PROBE_OS_GROUP} nut`"], [nut_inplace_group="nut"],
[AS_IF([test -n "`${PROBE_OS_GROUP} ups`"], [nut_inplace_group="ups"])])])
AS_IF([test -n "${nut_inplace_group}"], [
AC_MSG_RESULT([${nut_inplace_group}])
CONFIG_FLAGS_DEPLOYED="${CONFIG_FLAGS_DEPLOYED} --with-group='${nut_inplace_group}'"
], [
AC_MSG_RESULT([not detected])
])
])
AS_CASE(["${CONFIG_FLAGS_DEPLOYED} ${CONFIG_FLAGS}"],
[*--with-user=*], [],
[
AC_MSG_CHECKING([for in-place replacement default user (better than '${RUN_AS_USER}')])
nut_inplace_user=""
dnl Beside currently active setting, check the built-in default sugestion
AS_IF([test -s "${CONFPATH}/upsmon.conf"],
[for nut_inplace_user in \
`grep -E '^ *RUN_AS_USER' "${CONFPATH}/upsmon.conf" | awk '{print $2}'`\
`grep -E '^ *##*RUN_AS_USER' "${CONFPATH}/upsmon.conf" | awk '{print $2}'`\
`grep -E '^ *##* *RUN_AS_USER' "${CONFPATH}/upsmon.conf" | awk '{print $3}'`\
; do \
AS_IF([test -z "${nut_inplace_user}"], [
test -n "`${PROBE_OS_USER} "${nut_inplace_user}"`" \
&& AC_MSG_RESULT([Got from ${CONFPATH}/upsmon.conf]) \
|| nut_inplace_user=""])
done
])
AS_IF([test -s "${CONFPATH}/upsmon.conf.sample" && test -z "${nut_inplace_user}"],
[for nut_inplace_user in \
`grep -E '^ *RUN_AS_USER' "${CONFPATH}/upsmon.conf.sample" | awk '{print $2}'`\
`grep -E '^ *##*RUN_AS_USER' "${CONFPATH}/upsmon.conf.sample" | awk '{print $2}'`\
`grep -E '^ *##* *RUN_AS_USER' "${CONFPATH}/upsmon.conf.sample" | awk '{print $3}'`\
; do \
AS_IF([test -z "${nut_inplace_user}"], [
test -n "`${PROBE_OS_USER} "${nut_inplace_user}"`" \
&& AC_MSG_RESULT([Got from ${CONFPATH}/upsmon.conf]) \
|| nut_inplace_user=""])
done
])
dnl Note: with default short inplace and no prefix, this would look under
dnl /usr/local/ups/lib/pkgconfig which may be irrelevant for packaged setups
dnl TODO: Any more reasonable defaults? Pile them on here :)
for F in \
"${PKGCONFDIR}/libupsclient.pc" \
"${PKGCONFDIR}/libnutclient.pc" \
"${LIBDIR}/pkgconfig/libupsclient.pc" \
"${LIBDIR}/pkgconfig/libnutclient.pc" \
; do
AS_IF([test -z "${nut_inplace_user}" && test -s "$F"],
[nut_inplace_user="`grep -E '^ *nutuser=' "$F" | sed 's,^ *nutuser=,,'`" \
&& test -n "`${PROBE_OS_USER} "${nut_inplace_user}"`" \
&& AC_MSG_RESULT([Got from $F]) \
|| nut_inplace_user=""
])
done
AS_IF([test -z "${nut_inplace_user}"],
[AS_IF([test -n "`${PROBE_OS_USER} nut`"], [nut_inplace_user="nut"],
[AS_IF([test -n "`${PROBE_OS_USER} ups`"], [nut_inplace_user="ups"])])])
AS_IF([test -n "${nut_inplace_user}"], [
AC_MSG_RESULT([${nut_inplace_user}])
CONFIG_FLAGS_DEPLOYED="${CONFIG_FLAGS_DEPLOYED} --with-user='${nut_inplace_user}'"
], [
AC_MSG_RESULT([not detected])
])
])
AS_IF([test x"${CONFIG_FLAGS_DEPLOYED}" != x], [
AC_MSG_NOTICE([Detected CONFIG_FLAGS of an already deployed NUT installation, using them for --inplace-runtime configuration (restarting script)])
dnl For multiply-specified flags with conflicting values, last mention wins:
AC_MSG_NOTICE([exec "$0" $CONFIG_FLAGS_DEPLOYED $CONFIG_FLAGS --disable-inplace-runtime])
AS_IF([test x"${NUT_VERSION_DEPLOYED}" != x], [
AC_MSG_NOTICE([NUT_VERSION_DEPLOYED: ${NUT_VERSION_DEPLOYED}])
],[
NUT_VERSION_DEPLOYED="<reenter>"
])
export NUT_VERSION_DEPLOYED
dnl # Avoid replacement after re-entering:
test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS=" "
test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS=" "
export CONFIG_CFLAGS
export CONFIG_CXXFLAGS
AC_MSG_NOTICE([Moving config.log of the original invocation to config.log.inplace-outer just before exec...])
mv -f config.log config.log.inplace-outer || true
eval exec "$0" $CONFIG_FLAGS_DEPLOYED $CONFIG_FLAGS --disable-inplace-runtime
],[
AC_MSG_NOTICE([No CONFIG_FLAGS were reported or discovered from existing NUT deployment (if any); restarting script for a clean run])
NUT_VERSION_DEPLOYED="<reenter>"
export NUT_VERSION_DEPLOYED
dnl # Avoid replacement after re-entering:
test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS=" "
test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS=" "
export CONFIG_CFLAGS
export CONFIG_CXXFLAGS
AC_MSG_NOTICE([Moving config.log of the original invocation to config.log.inplace-outer just before exec...])
mv -f config.log config.log.inplace-outer || true
AC_MSG_NOTICE([exec "$0" $CONFIG_FLAGS --disable-inplace-runtime])
eval exec "$0" $CONFIG_FLAGS --disable-inplace-runtime
])
])
dnl Define directory where LIBOBJS replacement functions are
AC_CONFIG_LIBOBJ_DIR([common])
dnl +-------------------------------------------------------------------
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_PROG_LN_S
AC_PROG_EGREP
AC_PATH_PROG(AR, ar)
AC_CHECK_TOOL(RANLIB, ranlib, :)
dnl Postpone call to LT_INIT/AC_CONFIG_FILES to allow disabling static lib
AC_C_BIGENDIAN
AC_C_INLINE
AC_C_FLEXIBLE_ARRAY_MEMBER
AC_C_VARARRAYS
NUT_ARG_ENABLE([keep_nut_report_feature],
[Request that we keep config.nut_report_feature.log (normally deleted by configure script after displaying)],
[no])
AS_IF([test x"${NUT_SOURCE_GITREV}" = x],
[NUT_REPORT([configured version], [${PACKAGE_VERSION}])],
[AS_IF([test x"${NUT_SOURCE_GITREV}" = x"${PACKAGE_VERSION}"],
[NUT_REPORT([configured version], [${PACKAGE_VERSION} ${NUT_SOURCE_GITREV_DEVREL}])],
[NUT_REPORT([configured version], [${PACKAGE_VERSION} (${NUT_SOURCE_GITREV}) ${NUT_SOURCE_GITREV_DEVREL}])])
])
dnl Note: the compiler/pragma/attr methods below are custom for NUT codebase:
NUT_COMPILER_FAMILY
dnl Note: DO NOT AC_DEFINE the "FULL" items: they are generally multi-line.
dnl NUT_REPORT_TARGET([CC_VERSION_FULL], ["${CC_VERSION_FULL}"], [Version and other details of C compiler])
dnl NUT_REPORT_TARGET([CXX_VERSION_FULL], ["${CXX_VERSION_FULL}"], [Version and other details of C++ compiler])
dnl NUT_REPORT_TARGET([CPP_VERSION_FULL], ["${CPP_VERSION_FULL}"], [Version and other details of C preprocessor])
NUT_REPORT_TARGET([CC_VERSION], ["${CC_VERSION}"], [Compact version of C compiler])
NUT_REPORT_TARGET([CXX_VERSION], ["${CXX_VERSION}"], [Compact version of C++ compiler])
NUT_REPORT_TARGET([CPP_VERSION], ["${CPP_VERSION}"], [Compact version of C preprocessor])
dnl Help find warning/error details in a wall of text (must be processed before NUT_COMPILER_FAMILY_FLAGS):
NUT_ARG_ENABLE([Wcolor],
[Request that compiler output is colorized (no = leave it up to compiler defaults)],
[no])
NUT_COMPILER_FAMILY_FLAGS
AX_C_PRAGMAS
AX_C___ATTRIBUTE__
AX_C_PRINTF_STRING_NULL
dnl Check if the system provides a boolean type and how it is spelled
NUT_CHECK_BOOL
dnl All current systems provide time.h; it need not be checked for.
dnl Not all systems provide sys/time.h, but those that do, all allow
dnl you to include it and time.h simultaneously.
dnl NUT codebase provides the include/timehead.h to wrap these nuances.
AC_CHECK_HEADERS_ONCE([sys/time.h time.h sys/types.h])
dnl ###obsolete### AC_HEADER_TIME
AS_IF([test "$ac_cv_header_sys_time_h" = yes],
[AC_DEFINE([TIME_WITH_SYS_TIME],[1],[Define to 1 if you can safely include both <sys/time.h>
and <time.h>. This macro is deemed obsolete by autotools.])
], [])
CODE_TIMEINCL="
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
"
AC_CHECK_HEADERS_ONCE([fcntl.h sys/stat.h sys/socket.h netdb.h])
AC_CHECK_FUNCS(flock lockf fcvt fcvtl dup dup2 abs_val abs)
AC_CHECK_HEADER([float.h],
[AC_DEFINE([HAVE_FLOAT_H], [1],
[Define to 1 if you have <float.h>.])])
AC_CHECK_HEADER([math.h],
[AC_DEFINE([HAVE_MATH_H], [1],
[Define to 1 if you have <math.h>.])])
AC_CHECK_DECLS([fabs, fabsf, fabsl, pow10, round], [], [],
[#ifdef HAVE_MATH_H
# include <math.h>
#endif
#ifdef HAVE_FLOAT_H
# include <float.h>
#endif
])
AC_CHECK_HEADER([limits.h],
[AC_DEFINE([HAVE_LIMITS_H], [1],
[Define to 1 if you have <limits.h>.])])
AC_CHECK_HEADER([stdlib.h],
[AC_DEFINE([HAVE_STDLIB_H], [1],
[Define to 1 if you have <stdlib.h>.])])
AC_CHECK_DECLS(realpath, [], [],
[#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
])
AC_CHECK_HEADER([signal.h],
[AC_DEFINE([HAVE_SIGNAL_H], [1],
[Define to 1 if you have <signal.h>.])])
AC_CHECK_HEADER([sys/signal.h],
[AC_DEFINE([HAVE_SYS_SIGNAL_H], [1],
[Define to 1 if you have <sys/signal.h>.])])
AC_CHECK_HEADER([sys/resource.h],
[AC_MSG_CHECKING([for struct rlimit and getrlimit()])
AC_LANG_PUSH([C])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <sys/resource.h>
],
[struct rlimit limit;
getrlimit(RLIMIT_NOFILE, &limit);
/* Do not care about actual return value in this test,
* normally check for non-zero meaning to look in errno */
]
)],
[AC_DEFINE([HAVE_SYS_RESOURCE_H], [1],
[Define to 1 if you have <sys/resource.h> with usable struct rlimit and getrlimit().])
AC_MSG_RESULT([ok])
],
[AC_MSG_RESULT([no])]
)
AC_LANG_POP([C])
]
)
AC_CHECK_HEADER([poll.h],
[AC_DEFINE([HAVE_POLL_H], [1],
[Define to 1 if you have <poll.h>.])])
SEMLIBS=""
AC_CHECK_HEADER([semaphore.h],
[AC_DEFINE([HAVE_SEMAPHORE_H], [1],
[Define to 1 if you have <sys/semaphore.h>.])
AC_LANG_PUSH([C])
myLIBS="${LIBS}"
LIBS=""
SEMLIBS_LRT=""
dnl Solaris 8 builds complain about indirect dependency involved:
dnl sem_init nut_scanner-nut-scanner.o
dnl (symbol belongs to implicit dependency /usr/lib/librt.so.1)
AC_SEARCH_LIBS([sem_init], [pthread], [], [
unset ac_cv_search_sem_init
AC_SEARCH_LIBS([sem_init], [pthread], [SEMLIBS_LRT=" -lrt"], [], [-lrt])])
AC_SEARCH_LIBS([sem_open], [pthread], [], [
unset ac_cv_search_sem_open
AC_SEARCH_LIBS([sem_open], [pthread], [SEMLIBS_LRT=" -lrt"], [], [-lrt])])
AS_CASE([${ac_cv_search_sem_init}], [no*], [], [SEMLIBS="${ac_cv_search_sem_init}"])
AS_CASE([${ac_cv_search_sem_open}], [no*], [], ["${SEMLIBS}"], [], [SEMLIBS="${ac_cv_search_sem_open}"])
SEMLIBS="${SEMLIBS}${SEMLIBS_LRT}"
LIBS="${SEMLIBS}"
AC_MSG_CHECKING([for sem_t, sem_init() and sem_destroy()])
AX_RUN_OR_LINK_IFELSE([AC_LANG_PROGRAM([
#include <semaphore.h>
],
[sem_t semaphore;
sem_init(&semaphore, 0, 4);
sem_destroy(&semaphore);
/* Do not care about actual return value in this test,
* normally check for non-zero meaning to look in errno */
]
)],
[AC_DEFINE([HAVE_SEMAPHORE_UNNAMED], [1],
[Define to 1 if you have <sys/semaphore.h> with usable sem_t, sem_init() and sem_destroy() for unnamed semaphores.])
AC_MSG_RESULT([ok])
],
[AC_MSG_RESULT([no])]
)
AC_MSG_CHECKING([for sem_t, sem_open() and sem_close()])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#include <semaphore.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h> /* For O_* constants */
#endif
#ifdef SYS_STAT_H
# include <sys/stat.h> /* For mode constants */
#endif
],
[sem_t *semaphore = sem_open("/s", O_CREAT, 0644, 4);
if (semaphore != SEM_FAILED)
sem_close(semaphore);
/* Do not care about actual return value in this test,
* normally check for non-zero meaning to look in errno */
]
)],
[AC_DEFINE([HAVE_SEMAPHORE_NAMED], [1],
[Define to 1 if you have <sys/semaphore.h> with usable sem_t, sem_open() and sem_close() for named semaphores.])
AC_MSG_RESULT([ok])
],
[AC_MSG_RESULT([no])]
)
LIBS="${myLIBS}"
AC_LANG_POP([C])
]
)
AM_CONDITIONAL(HAVE_SEMAPHORE_LIBS, test -n "${SEMLIBS}")
AC_CHECK_FUNCS(cfsetispeed tcsendbreak)
AC_CHECK_FUNCS(seteuid setsid getpassphrase)
AC_CHECK_FUNCS(on_exit setlogmask)
AC_CHECK_DECLS(LOG_UPTO, [], [], [#include <syslog.h>])
dnl These common routines are not available in strict C standard library
dnl compilation modes (not part of ANSI or later standard), only in GNU,
dnl POSIX or other extension modes. Note that on modern systems they are
dnl available, just hidden in headers - so AC_CHECK_FUNCS() finds them
dnl by adding a declaration, while the "real" codebase can't use them.
AC_MSG_NOTICE(
[-----------------------------------------------------------------------
The next few tests look for required C library routines; if something is
not found, you may need to enable a different C standard or extension macro
version. You may also have to configure without extreme warning levels
since autotools tests fail those on their own and assume system lacks
stuff (although note we try to not involve standard -W* flags here).
-----------------------------------------------------------------------])
dnl# AC_CHECK_FUNCS(strcasecmp strncasecmp,
dnl# [], [AC_MSG_WARN([Required C library routine not found; try adding __EXTENSIONS__])])
dnl These appear with CFLAGS="-std=c99 -D_POSIX_C_SOURCE=200112L":
dnl# Methods below currently do not cause build errors for C99+ modes so are
dnl# not tested as thoroughly as those further below:
AC_CHECK_FUNCS(strtof strtok_r fileno sigemptyset sigaction,
[], [AC_MSG_WARN([Required C library routine not found by linker; try adding -D_POSIX_C_SOURCE=200112L])])
dnl For these we have a fallback implementation via the other,
dnl if at least one is available, so initial check is quiet.
dnl This typically pops up in POSIX vs. Windows builds:
dnl Reminder: the former checks for declarations in headers,
dnl the latter checks if known libraries suffice for linker.
dnl Might need AC_CHECK_LIBS as well to populate the list with
dnl known variants?
AC_CHECK_DECLS([localtime_r, localtime_s, gmtime_r, gmtime_s, timegm, _mkgmtime], [], [], [$CODE_TIMEINCL])
AC_CHECK_FUNCS(localtime_r localtime_s gmtime_r gmtime_s timegm _mkgmtime, [], [])
AC_MSG_CHECKING([for at least one gmtime implementation])
AS_IF([test x"${ac_cv_func_gmtime_s}-${ac_cv_func_gmtime_r}" = "xno-no" && test x"${ac_cv_have_decl_gmtime_s}-${ac_cv_have_decl_gmtime_r}" = "xno-no"], [
AC_MSG_RESULT([no])
AC_MSG_WARN([Required C library routine gmtime_s nor gmtime_r was not found by linker nor in headers; try adding -D_POSIX_C_SOURCE=200112L and/or -D_POSIX_THREAD_SAFE_FUNCTIONS=200112L])
],[
AC_MSG_RESULT([yes])
])
AC_MSG_CHECKING([for at least one localtime implementation])
AS_IF([test x"${ac_cv_func_localtime_s}-${ac_cv_func_localtime_r}" = "xno-no" && test x"${ac_cv_have_decl_localtime_s}-${ac_cv_have_decl_localtime_r}" = "xno-no"], [
AC_MSG_RESULT([no])
AC_MSG_WARN([Required C library routine localtime_s nor localtime_r was not found by linker nor in headers; try adding -D_POSIX_C_SOURCE=200112L and/or -D_POSIX_THREAD_SAFE_FUNCTIONS=200112L])
],[
AC_MSG_RESULT([yes])
])
AC_MSG_CHECKING([for at least one timegm implementation])
AS_IF([test x"${ac_cv_func_timegm}-${ac_cv_func__mkgmtime}" = "xno-no" && test x"${ac_cv_have_decl_timegm}-${ac_cv_have_decl__mkgmtime}" = "xno-no"], [
AC_MSG_RESULT([no])
AC_MSG_WARN([Required C library routine timegm nor _mkgmtime was not found by linker nor in headers])
AC_DEFINE_UNQUOTED([WANT_TIMEGM_FALLBACK], [1], [Defined if we want to use timegm_fallback()])
AM_CONDITIONAL([WANT_TIMEGM_FALLBACK], [true])
],[