Skip to content

Commit 0c83bbc

Browse files
ramsay-jonesgitster
authored andcommitted
build: fix FreeBSD build when sysinfo compat library installed
Commit 50dec7c ("config.mak.uname: add sysinfo() configuration for cygwin", 2025-04-17) and later commit 187ce02 ("configure.ac: upgrade to a compilation check for sysinfo", 2025-05-19) added a 'sysinfo()' check to the autoconf build. The FreeBSD system has an optional sysinfo compatibility library, used to assist in porting software, which causes the build to fail when it is installed. The reason for the failure is the lack of '-lsysinfo' during the linking step. Several solutions were considered: - add a 'linking' check to configure.ac in order to determine the need to link a separate library (-lsysinfo). (This would require a similar change to meson.build). - change the order of the preprocessor conditionals in the total_ram() function in 'builtin/gc.c', so that the *BSD sysctl() function (in the HAVE_BSD_SYSCTL block) takes priority over the sysinfo() function (in the HAVE_SYSINFO block). - suppress the setting of HAVE_SYSINFO when HAVE_BSD_SYSCTL has been defined (in both configure.ac and meson.build). The first solution above, while simple, adds unnecessary code (the sysinfo compat function is likely implemented using sysctl() anyway) when git is happy to use sysctl() on *BSD systems. The second solution would only be required by the autoconf and meson build systems, the Makefile already sets the build variables to the required values (since they are not 'auto-detected'). Here we opt for the final solution above, since it only requires that we prioritise the 'auto-detected' build variables in the autoconf and meson builds. In order to fix the FreeBSD build, move the sysinfo() check after the determination of the HAVE_BSD_SYSCTL build variable, suppressing the setting of HAVE_SYSINFO if HAVE_BSD_SYSCTL is defined. Apply this logic to both the configure.ac and meson.build file. [Thanks go to Renato Botelho <[email protected]> for testing this patch on FreeBSD.] Tested-by: Renato Botelho <[email protected]> Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16bd9f2 commit 0c83bbc

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

configure.ac

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,32 +1067,6 @@ AC_CHECK_LIB([iconv], [locale_charset],
10671067
[CHARSET_LIB=-lcharset])])
10681068
GIT_CONF_SUBST([CHARSET_LIB])
10691069

1070-
#
1071-
# Define HAVE_SYSINFO=YesPlease if sysinfo is available.
1072-
#
1073-
AC_DEFUN([HAVE_SYSINFO_SRC], [
1074-
AC_LANG_PROGRAM([[
1075-
#include <stdint.h>
1076-
#include <sys/sysinfo.h>
1077-
]], [[
1078-
struct sysinfo si;
1079-
uint64_t t = 0;
1080-
if (!sysinfo(&si)) {
1081-
t = si.totalram;
1082-
if (si.mem_unit > 1)
1083-
t *= (uint64_t)si.mem_unit;
1084-
}
1085-
return t;
1086-
]])])
1087-
1088-
AC_MSG_CHECKING([for sysinfo])
1089-
AC_COMPILE_IFELSE([HAVE_SYSINFO_SRC],
1090-
[AC_MSG_RESULT([yes])
1091-
HAVE_SYSINFO=YesPlease],
1092-
[AC_MSG_RESULT([no])
1093-
HAVE_SYSINFO=])
1094-
GIT_CONF_SUBST([HAVE_SYSINFO])
1095-
10961070
#
10971071
# Define HAVE_CLOCK_GETTIME=YesPlease if clock_gettime is available.
10981072
GIT_CHECK_FUNC(clock_gettime,
@@ -1221,6 +1195,41 @@ AC_COMPILE_IFELSE([BSD_SYSCTL_SRC],
12211195
HAVE_BSD_SYSCTL=])
12221196
GIT_CONF_SUBST([HAVE_BSD_SYSCTL])
12231197

1198+
#
1199+
# Define HAVE_SYSINFO=YesPlease if sysinfo is available.
1200+
#
1201+
1202+
HAVE_SYSINFO=
1203+
# on a *BSD system, sysctl() takes precedence over the
1204+
# sysinfo() compatibility library (if installed).
1205+
1206+
if test -z "$HAVE_BSD_SYSCTL"; then
1207+
1208+
AC_DEFUN([HAVE_SYSINFO_SRC], [
1209+
AC_LANG_PROGRAM([[
1210+
#include <stdint.h>
1211+
#include <sys/sysinfo.h>
1212+
]], [[
1213+
struct sysinfo si;
1214+
uint64_t t = 0;
1215+
if (!sysinfo(&si)) {
1216+
t = si.totalram;
1217+
if (si.mem_unit > 1)
1218+
t *= (uint64_t)si.mem_unit;
1219+
}
1220+
return t;
1221+
]])])
1222+
1223+
AC_MSG_CHECKING([for sysinfo])
1224+
AC_COMPILE_IFELSE([HAVE_SYSINFO_SRC],
1225+
[AC_MSG_RESULT([yes])
1226+
HAVE_SYSINFO=YesPlease],
1227+
[AC_MSG_RESULT([no])
1228+
HAVE_SYSINFO=])
1229+
GIT_CONF_SUBST([HAVE_SYSINFO])
1230+
1231+
fi
1232+
12241233
## Other checks.
12251234
# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
12261235
# Enable it on Windows. By default, symrefs are still used.

meson.build

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,10 +1331,6 @@ if host_machine.system() != 'windows'
13311331
endif
13321332
endif
13331333

1334-
if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include <sys/sysinfo.h>')
1335-
libgit_c_args += '-DHAVE_SYSINFO'
1336-
endif
1337-
13381334
if compiler.has_member('struct stat', 'st_mtimespec.tv_nsec', prefix: '#include <sys/stat.h>')
13391335
libgit_c_args += '-DUSE_ST_TIMESPEC'
13401336
elif not compiler.has_member('struct stat', 'st_mtim.tv_nsec', prefix: '#include <sys/stat.h>')
@@ -1449,6 +1445,12 @@ if compiler.has_header('sys/sysctl.h')
14491445
endif
14501446
endif
14511447

1448+
if not has_bsd_sysctl
1449+
if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include <sys/sysinfo.h>')
1450+
libgit_c_args += '-DHAVE_SYSINFO'
1451+
endif
1452+
endif
1453+
14521454
if not meson.is_cross_build() and compiler.run('''
14531455
#include <stdio.h>
14541456

0 commit comments

Comments
 (0)