@@ -1086,10 +1086,6 @@ if compiler.has_header('alloca.h')
10861086 libgit_c_args += ' -DHAVE_ALLOCA_H'
10871087endif
10881088
1089- if compiler.has_header(' sys/sysinfo.h' )
1090- libgit_c_args += ' -DHAVE_SYSINFO'
1091- endif
1092-
10931089# Windows has libgen.h and a basename implementation, but we still need our own
10941090# implementation to threat things like drive prefixes specially.
10951091if host_machine .system() == ' windows' or not compiler.has_header(' libgen.h' )
@@ -1112,18 +1108,22 @@ if host_machine.system() == 'windows'
11121108 networking_dependencies += winsock
11131109 endif
11141110else
1115- libresolv = compiler.find_library (' resolv' , required : false )
1116- if libresolv.found()
1117- networking_dependencies += libresolv
1118- endif
1111+ networking_dependencies += [
1112+ compiler.find_library (' nsl' , required : false ),
1113+ compiler.find_library (' resolv' , required : false ),
1114+ compiler.find_library (' socket' , required : false ),
1115+ ]
11191116endif
11201117libgit_dependencies += networking_dependencies
11211118
1122- foreach symbol : [' inet_ntop' , ' inet_pton' , ' strerror' ]
1123- if not compiler.has_function(symbol, dependencies : networking_dependencies)
1124- libgit_c_args += ' -DNO_' + symbol.to_upper()
1125- endif
1126- endforeach
1119+ if host_machine .system() != ' windows'
1120+ foreach symbol : [' inet_ntop' , ' inet_pton' , ' hstrerror' ]
1121+ if not compiler.has_function(symbol, dependencies : networking_dependencies)
1122+ libgit_c_args += ' -DNO_' + symbol.to_upper()
1123+ libgit_sources += ' compat/' + symbol + ' .c'
1124+ endif
1125+ endforeach
1126+ endif
11271127
11281128has_ipv6 = compiler.has_function(' getaddrinfo' , dependencies : networking_dependencies)
11291129if not has_ipv6
@@ -1161,11 +1161,6 @@ else
11611161 build_options_config.set(' NO_UNIX_SOCKETS' , ' 1' )
11621162endif
11631163
1164- if not compiler.has_function(' pread' )
1165- libgit_c_args += ' -DNO_PREAD'
1166- libgit_sources += ' compat/pread.c'
1167- endif
1168-
11691164if host_machine .system() == ' darwin'
11701165 libgit_sources += ' compat/precompose_utf8.c'
11711166 libgit_c_args += ' -DPRECOMPOSE_UNICODE'
@@ -1300,6 +1295,10 @@ if host_machine.system() != 'windows'
13001295 endif
13011296endif
13021297
1298+ if compiler.has_member(' struct sysinfo' , ' totalram' , prefix : ' #include <sys/sysinfo.h>' )
1299+ libgit_c_args += ' -DHAVE_SYSINFO'
1300+ endif
1301+
13031302if compiler.has_member(' struct stat' , ' st_mtimespec.tv_nsec' , prefix : ' #include <sys/stat.h>' )
13041303 libgit_c_args += ' -DUSE_ST_TIMESPEC'
13051304elif not compiler.has_member(' struct stat' , ' st_mtim.tv_nsec' , prefix : ' #include <sys/stat.h>' )
@@ -1318,77 +1317,57 @@ if not compiler.has_member('struct passwd', 'pw_gecos', prefix: '#include <pwd.h
13181317 libgit_c_args += ' -DNO_GECOS_IN_PWENT'
13191318endif
13201319
1321- if compiler.has_function(' sync_file_range' )
1322- libgit_c_args += ' -DHAVE_SYNC_FILE_RANGE'
1323- endif
1320+ checkfuncs = {
1321+ ' strcasestr' : [' strcasestr.c' ],
1322+ ' memmem' : [' memmem.c' ],
1323+ ' strlcpy' : [' strlcpy.c' ],
1324+ ' strtoull' : [],
1325+ ' setenv' : [' setenv.c' ],
1326+ ' mkdtemp' : [' mkdtemp.c' ],
1327+ ' initgroups' : [],
1328+ ' strtoumax' : [' strtoumax.c' , ' strtoimax.c' ],
1329+ ' pread' : [' pread.c' ],
1330+ }
13241331
1325- if not compiler.has_function(' strcasestr' )
1326- libgit_c_args += ' -DNO_STRCASESTR'
1327- libgit_sources += ' compat/strcasestr.c'
1332+ if host_machine .system() == ' windows'
1333+ libgit_c_args += ' -DUSE_WIN32_MMAP'
1334+ else
1335+ checkfuncs += {
1336+ ' mmap' : [' mmap.c' ],
1337+ # provided by compat/mingw.c.
1338+ ' unsetenv' : [' unsetenv.c' ],
1339+ # provided by compat/mingw.c.
1340+ ' getpagesize' : [],
1341+ }
13281342endif
13291343
1330- if not compiler.has_function(' memmem' )
1331- libgit_c_args += ' -DNO_MEMMEM'
1332- libgit_sources += ' compat/memmem.c'
1333- endif
1344+ foreach func, impls : checkfuncs
1345+ if not compiler.has_function(func)
1346+ libgit_c_args += ' -DNO_' + func.to_upper()
1347+ foreach impl : impls
1348+ libgit_sources += ' compat/' + impl
1349+ endforeach
1350+ endif
1351+ endforeach
13341352
1335- if not compiler.has_function(' strlcpy' )
1336- libgit_c_args += ' -DNO_STRLCPY'
1337- libgit_sources += ' compat/strlcpy.c'
1353+ if compiler.has_function(' sync_file_range' )
1354+ libgit_c_args += ' -DHAVE_SYNC_FILE_RANGE'
13381355endif
13391356
13401357if not compiler.has_function(' strdup' )
13411358 libgit_c_args += ' -DOVERRIDE_STRDUP'
13421359 libgit_sources += ' compat/strdup.c'
13431360endif
13441361
1345- if not compiler.has_function(' strtoumax' )
1346- libgit_c_args += ' -DNO_STRTOUMAX'
1347- libgit_sources += [
1348- ' compat/strtoumax.c' ,
1349- ' compat/strtoimax.c' ,
1350- ]
1351- endif
1352-
1353- if not compiler.has_function(' strtoull' )
1354- libgit_c_args += ' -DNO_STRTOULL'
1355- endif
1356-
1357- if not compiler.has_function(' setenv' )
1358- libgit_c_args += ' -DNO_SETENV'
1359- libgit_sources += ' compat/setenv.c'
1360- endif
1361-
13621362if not compiler.has_function(' qsort' )
13631363 libgit_c_args += ' -DINTERNAL_QSORT'
13641364endif
13651365libgit_sources += ' compat/qsort_s.c'
13661366
1367- # unsetenv is provided by compat/mingw.c.
1368- if host_machine .system() != ' windows' and not compiler.has_function(' unsetenv' )
1369- libgit_c_args += ' -DNO_UNSETENV'
1370- libgit_sources += ' compat/unsetenv.c'
1371- endif
1372-
1373- if not compiler.has_function(' mkdtemp' )
1374- libgit_c_args += ' -DNO_MKDTEMP'
1375- libgit_sources += ' compat/mkdtemp.c'
1376- endif
1377-
1378- if not compiler.has_function(' initgroups' )
1379- libgit_c_args += ' -DNO_INITGROUPS'
1380- endif
1381-
13821367if compiler.has_function(' getdelim' )
13831368 libgit_c_args += ' -DHAVE_GETDELIM'
13841369endif
13851370
1386- if host_machine .system() == ' windows'
1387- libgit_c_args += ' -DUSE_WIN32_MMAP'
1388- elif not compiler.has_function(' mmap' )
1389- libgit_c_args += ' -DNO_MMAP'
1390- libgit_sources += ' compat/mmap.c'
1391- endif
13921371
13931372if compiler.has_function(' clock_gettime' )
13941373 libgit_c_args += ' -DHAVE_CLOCK_GETTIME'
0 commit comments