configure: support HAVE_BSD_SYSCTL option
On BSD-compatible systems some information such as the number of available CPUs may only be available via the sysctl function. Add support for a HAVE_BSD_SYSCTL option complete with autoconf support and include the sys/syctl.h header when the option is enabled to make the sysctl function available. Signed-off-by: Kyle J. McKay <mackyle@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kyle J. McKay committed
Mar 7, 2015 at 23:14 UTC
9529080de253b89474402f323e10470656764b3a
4 files changed
+37
Makefile
+6
@@ -348,6 +348,8 @@ all::
348
#
349
# Define NO_HMAC_CTX_CLEANUP if your OpenSSL is version 0.9.6b or earlier to
350
# cleanup the HMAC context with the older HMAC_cleanup function.
351
+#
352
+# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
353
354
GIT-VERSION-FILE: FORCE
355
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1414,6 +1416,10 @@ ifdef HAVE_CLOCK_MONOTONIC
1416
BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
1417
endif
1418
1419
+ifdef HAVE_BSD_SYSCTL
1420
+ BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
1421
+endif
1422
+
1423
ifeq ($(TCLTK_PATH),)
1424
NO_TCLTK = NoThanks
1425
endif
config.mak.uname
+5
@@ -107,6 +107,7 @@ ifeq ($(uname_S),Darwin)
107
COMPAT_OBJS += compat/precompose_utf8.o
108
BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
109
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
110
+ HAVE_BSD_SYSCTL = YesPlease
111
endif
112
ifeq ($(uname_S),SunOS)
113
NEEDS_SOCKET = YesPlease
@@ -199,6 +200,7 @@ ifeq ($(uname_S),FreeBSD)
200
PYTHON_PATH = /usr/local/bin/python
201
HAVE_PATHS_H = YesPlease
202
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
203
+ HAVE_BSD_SYSCTL = YesPlease
204
endif
205
ifeq ($(uname_S),OpenBSD)
206
NO_STRCASESTR = YesPlease
@@ -208,6 +210,7 @@ ifeq ($(uname_S),OpenBSD)
210
BASIC_CFLAGS += -I/usr/local/include
211
BASIC_LDFLAGS += -L/usr/local/lib
212
HAVE_PATHS_H = YesPlease
213
+ HAVE_BSD_SYSCTL = YesPlease
214
endif
215
ifeq ($(uname_S),MirBSD)
216
NO_STRCASESTR = YesPlease
@@ -215,6 +218,7 @@ ifeq ($(uname_S),MirBSD)
218
USE_ST_TIMESPEC = YesPlease
219
NEEDS_LIBICONV = YesPlease
220
HAVE_PATHS_H = YesPlease
221
+ HAVE_BSD_SYSCTL = YesPlease
222
endif
223
ifeq ($(uname_S),NetBSD)
224
ifeq ($(shell expr "$(uname_R)" : '[01]\.'),2)
@@ -225,6 +229,7 @@ ifeq ($(uname_S),NetBSD)
229
USE_ST_TIMESPEC = YesPlease
230
NO_MKSTEMPS = YesPlease
231
HAVE_PATHS_H = YesPlease
232
+ HAVE_BSD_SYSCTL = YesPlease
233
endif
234
ifeq ($(uname_S),AIX)
235
DEFAULT_PAGER = more
configure.ac
+23
@@ -1046,6 +1046,29 @@ GIT_CONF_SUBST([NO_INITGROUPS])
1046
#
1047
# Define NO_ICONV if your libc does not properly support iconv.
1048
1049
+AC_DEFUN([BSD_SYSCTL_SRC], [
1050
+AC_LANG_PROGRAM([[
1051
+#include <stddef.h>
1052
+#include <sys/types.h>
1053
+#include <sys/sysctl.h>
1054
+]],[[
1055
+int val, mib[2];
1056
+size_t len;
1057
+mib[0] = CTL_HW;
1058
+mib[1] = 1;
1059
+len = sizeof(val);
1060
+return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0;
1061
+]])])
1062
+
1063
+#
1064
+# Define HAVE_BSD_SYSCTL=YesPlease if a BSD-compatible sysctl function is available.
1065
+AC_MSG_CHECKING([for BSD sysctl])
1066
+AC_COMPILE_IFELSE([BSD_SYSCTL_SRC],
1067
+ [AC_MSG_RESULT([yes])
1068
+ HAVE_BSD_SYSCTL=YesPlease],
1069
+ [AC_MSG_RESULT([no])
1070
+ HAVE_BSD_SYSCTL=])
1071
+GIT_CONF_SUBST([HAVE_BSD_SYSCTL])
1072
1073
## Other checks.
1074
# Define USE_PIC if you need the main git objects to be built with -fPIC
git-compat-util.h
+3
@@ -127,6 +127,9 @@
127
#else
128
#include <poll.h>
129
#endif
130
+#ifdef HAVE_BSD_SYSCTL
131
+#include <sys/sysctl.h>
132
+#endif
133
134
#if defined(__MINGW32__)
135
/* pull in Windows compatibility stuff */