Skip to content

Commit c71b03d

Browse files
committed
Merge branch 'es/meson-cleanup' into seen
Code clean-up for meson-based build infrastructure. * es/meson-cleanup: meson: only check for missing networking syms on non-Windows; add compat impls meson: fix typo in function check that prevented checking for hstrerror meson: add a couple missing networking dependencies meson: do a full usage-based compile check for sysinfo meson: check for getpagesize before using it meson: simplify and parameterize various standard function checks
2 parents 84f43b4 + 8bc6dc7 commit c71b03d

File tree

1 file changed

+49
-56
lines changed

1 file changed

+49
-56
lines changed

meson.build

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,10 +1109,6 @@ if compiler.has_header('alloca.h')
11091109
libgit_c_args += '-DHAVE_ALLOCA_H'
11101110
endif
11111111

1112-
if compiler.has_header('sys/sysinfo.h')
1113-
libgit_c_args += '-DHAVE_SYSINFO'
1114-
endif
1115-
11161112
# Windows has libgen.h and a basename implementation, but we still need our own
11171113
# implementation to threat things like drive prefixes specially.
11181114
if host_machine.system() == 'windows' or not compiler.has_header('libgen.h')
@@ -1135,18 +1131,22 @@ if host_machine.system() == 'windows'
11351131
networking_dependencies += winsock
11361132
endif
11371133
else
1138-
libresolv = compiler.find_library('resolv', required: false)
1139-
if libresolv.found()
1140-
networking_dependencies += libresolv
1141-
endif
1134+
networking_dependencies += [
1135+
compiler.find_library('nsl', required: false),
1136+
compiler.find_library('resolv', required: false),
1137+
compiler.find_library('socket', required: false),
1138+
]
11421139
endif
11431140
libgit_dependencies += networking_dependencies
11441141

1145-
foreach symbol : ['inet_ntop', 'inet_pton', 'strerror']
1146-
if not compiler.has_function(symbol, dependencies: networking_dependencies)
1147-
libgit_c_args += '-DNO_' + symbol.to_upper()
1148-
endif
1149-
endforeach
1142+
if host_machine.system() != 'windows'
1143+
foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror']
1144+
if not compiler.has_function(symbol, dependencies: networking_dependencies)
1145+
libgit_c_args += '-DNO_' + symbol.to_upper()
1146+
libgit_sources += 'compat/' + symbol + '.c'
1147+
endif
1148+
endforeach
1149+
endif
11501150

11511151
has_ipv6 = compiler.has_function('getaddrinfo', dependencies: networking_dependencies)
11521152
if not has_ipv6
@@ -1323,6 +1323,10 @@ if host_machine.system() != 'windows'
13231323
endif
13241324
endif
13251325

1326+
if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include <sys/sysinfo.h>')
1327+
libgit_c_args += '-DHAVE_SYSINFO'
1328+
endif
1329+
13261330
if compiler.has_member('struct stat', 'st_mtimespec.tv_nsec', prefix: '#include <sys/stat.h>')
13271331
libgit_c_args += '-DUSE_ST_TIMESPEC'
13281332
elif not compiler.has_member('struct stat', 'st_mtim.tv_nsec', prefix: '#include <sys/stat.h>')
@@ -1341,23 +1345,42 @@ if not compiler.has_member('struct passwd', 'pw_gecos', prefix: '#include <pwd.h
13411345
libgit_c_args += '-DNO_GECOS_IN_PWENT'
13421346
endif
13431347

1344-
if compiler.has_function('sync_file_range')
1345-
libgit_c_args += '-DHAVE_SYNC_FILE_RANGE'
1346-
endif
1348+
checkfuncs = [
1349+
'strcasestr',
1350+
'memmem',
1351+
'strlcpy',
1352+
# no compat
1353+
'strtoull',
1354+
'setenv',
1355+
'mkdtemp',
1356+
# no compat
1357+
'initgroups',
1358+
# no compat
1359+
'getpagesize',
1360+
]
13471361

1348-
if not compiler.has_function('strcasestr')
1349-
libgit_c_args += '-DNO_STRCASESTR'
1350-
libgit_sources += 'compat/strcasestr.c'
1362+
if host_machine.system() == 'windows'
1363+
libgit_c_args += '-DUSE_WIN32_MMAP'
1364+
else
1365+
checkfuncs += [
1366+
'mmap',
1367+
# unsetenv is provided by compat/mingw.c.
1368+
'unsetenv',
1369+
]
13511370
endif
13521371

1353-
if not compiler.has_function('memmem')
1354-
libgit_c_args += '-DNO_MEMMEM'
1355-
libgit_sources += 'compat/memmem.c'
1356-
endif
1372+
foreach func: checkfuncs
1373+
if not compiler.has_function(func)
1374+
libgit_c_args += '-DNO_' + func.to_upper()
1375+
impl = 'compat/' + func + '.c'
1376+
if fs.exists(impl)
1377+
libgit_sources += impl
1378+
endif
1379+
endif
1380+
endforeach
13571381

1358-
if not compiler.has_function('strlcpy')
1359-
libgit_c_args += '-DNO_STRLCPY'
1360-
libgit_sources += 'compat/strlcpy.c'
1382+
if compiler.has_function('sync_file_range')
1383+
libgit_c_args += '-DHAVE_SYNC_FILE_RANGE'
13611384
endif
13621385

13631386
if not compiler.has_function('strdup')
@@ -1373,45 +1396,15 @@ if not compiler.has_function('strtoumax')
13731396
]
13741397
endif
13751398

1376-
if not compiler.has_function('strtoull')
1377-
libgit_c_args += '-DNO_STRTOULL'
1378-
endif
1379-
1380-
if not compiler.has_function('setenv')
1381-
libgit_c_args += '-DNO_SETENV'
1382-
libgit_sources += 'compat/setenv.c'
1383-
endif
1384-
13851399
if not compiler.has_function('qsort')
13861400
libgit_c_args += '-DINTERNAL_QSORT'
13871401
endif
13881402
libgit_sources += 'compat/qsort_s.c'
13891403

1390-
# unsetenv is provided by compat/mingw.c.
1391-
if host_machine.system() != 'windows' and not compiler.has_function('unsetenv')
1392-
libgit_c_args += '-DNO_UNSETENV'
1393-
libgit_sources += 'compat/unsetenv.c'
1394-
endif
1395-
1396-
if not compiler.has_function('mkdtemp')
1397-
libgit_c_args += '-DNO_MKDTEMP'
1398-
libgit_sources += 'compat/mkdtemp.c'
1399-
endif
1400-
1401-
if not compiler.has_function('initgroups')
1402-
libgit_c_args += '-DNO_INITGROUPS'
1403-
endif
1404-
14051404
if compiler.has_function('getdelim')
14061405
libgit_c_args += '-DHAVE_GETDELIM'
14071406
endif
14081407

1409-
if host_machine.system() == 'windows'
1410-
libgit_c_args += '-DUSE_WIN32_MMAP'
1411-
elif not compiler.has_function('mmap')
1412-
libgit_c_args += '-DNO_MMAP'
1413-
libgit_sources += 'compat/mmap.c'
1414-
endif
14151408

14161409
if compiler.has_function('clock_gettime')
14171410
libgit_c_args += '-DHAVE_CLOCK_GETTIME'

0 commit comments

Comments
 (0)