Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kyle J. McKay authored and Junio C Hamano committed Mar 10, 2015
1 parent 9874fca commit 9529080
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -348,6 +348,8 @@ all::
#
# Define NO_HMAC_CTX_CLEANUP if your OpenSSL is version 0.9.6b or earlier to
# cleanup the HMAC context with the older HMAC_cleanup function.
#
# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.

GIT-VERSION-FILE: FORCE
@$(SHELL_PATH) ./GIT-VERSION-GEN
Expand Down Expand Up @@ -1414,6 +1416,10 @@ ifdef HAVE_CLOCK_MONOTONIC
BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
endif

ifdef HAVE_BSD_SYSCTL
BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
endif

ifeq ($(TCLTK_PATH),)
NO_TCLTK = NoThanks
endif
Expand Down
5 changes: 5 additions & 0 deletions config.mak.uname
Expand Up @@ -107,6 +107,7 @@ ifeq ($(uname_S),Darwin)
COMPAT_OBJS += compat/precompose_utf8.o
BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
BASIC_CFLAGS += -DPROTECT_HFS_DEFAULT=1
HAVE_BSD_SYSCTL = YesPlease
endif
ifeq ($(uname_S),SunOS)
NEEDS_SOCKET = YesPlease
Expand Down Expand Up @@ -199,6 +200,7 @@ ifeq ($(uname_S),FreeBSD)
PYTHON_PATH = /usr/local/bin/python
HAVE_PATHS_H = YesPlease
GMTIME_UNRELIABLE_ERRORS = UnfortunatelyYes
HAVE_BSD_SYSCTL = YesPlease
endif
ifeq ($(uname_S),OpenBSD)
NO_STRCASESTR = YesPlease
Expand All @@ -208,13 +210,15 @@ ifeq ($(uname_S),OpenBSD)
BASIC_CFLAGS += -I/usr/local/include
BASIC_LDFLAGS += -L/usr/local/lib
HAVE_PATHS_H = YesPlease
HAVE_BSD_SYSCTL = YesPlease
endif
ifeq ($(uname_S),MirBSD)
NO_STRCASESTR = YesPlease
NO_MEMMEM = YesPlease
USE_ST_TIMESPEC = YesPlease
NEEDS_LIBICONV = YesPlease
HAVE_PATHS_H = YesPlease
HAVE_BSD_SYSCTL = YesPlease
endif
ifeq ($(uname_S),NetBSD)
ifeq ($(shell expr "$(uname_R)" : '[01]\.'),2)
Expand All @@ -225,6 +229,7 @@ ifeq ($(uname_S),NetBSD)
USE_ST_TIMESPEC = YesPlease
NO_MKSTEMPS = YesPlease
HAVE_PATHS_H = YesPlease
HAVE_BSD_SYSCTL = YesPlease
endif
ifeq ($(uname_S),AIX)
DEFAULT_PAGER = more
Expand Down
23 changes: 23 additions & 0 deletions configure.ac
Expand Up @@ -1046,6 +1046,29 @@ GIT_CONF_SUBST([NO_INITGROUPS])
#
# Define NO_ICONV if your libc does not properly support iconv.

AC_DEFUN([BSD_SYSCTL_SRC], [
AC_LANG_PROGRAM([[
#include <stddef.h>
#include <sys/types.h>
#include <sys/sysctl.h>
]],[[
int val, mib[2];
size_t len;
mib[0] = CTL_HW;
mib[1] = 1;
len = sizeof(val);
return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0;
]])])

#
# Define HAVE_BSD_SYSCTL=YesPlease if a BSD-compatible sysctl function is available.
AC_MSG_CHECKING([for BSD sysctl])
AC_COMPILE_IFELSE([BSD_SYSCTL_SRC],
[AC_MSG_RESULT([yes])
HAVE_BSD_SYSCTL=YesPlease],
[AC_MSG_RESULT([no])
HAVE_BSD_SYSCTL=])
GIT_CONF_SUBST([HAVE_BSD_SYSCTL])

## Other checks.
# Define USE_PIC if you need the main git objects to be built with -fPIC
Expand Down
3 changes: 3 additions & 0 deletions git-compat-util.h
Expand Up @@ -127,6 +127,9 @@
#else
#include <poll.h>
#endif
#ifdef HAVE_BSD_SYSCTL
#include <sys/sysctl.h>
#endif

#if defined(__MINGW32__)
/* pull in Windows compatibility stuff */
Expand Down

0 comments on commit 9529080

Please sign in to comment.