@@ -1086,10 +1086,6 @@ if compiler.has_header('alloca.h')
1086
1086
libgit_c_args += ' -DHAVE_ALLOCA_H'
1087
1087
endif
1088
1088
1089
- if compiler.has_header(' sys/sysinfo.h' )
1090
- libgit_c_args += ' -DHAVE_SYSINFO'
1091
- endif
1092
-
1093
1089
# Windows has libgen.h and a basename implementation, but we still need our own
1094
1090
# implementation to threat things like drive prefixes specially.
1095
1091
if host_machine .system() == ' windows' or not compiler.has_header(' libgen.h' )
@@ -1112,18 +1108,22 @@ if host_machine.system() == 'windows'
1112
1108
networking_dependencies += winsock
1113
1109
endif
1114
1110
else
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
+ ]
1119
1116
endif
1120
1117
libgit_dependencies += networking_dependencies
1121
1118
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
1127
1127
1128
1128
has_ipv6 = compiler.has_function(' getaddrinfo' , dependencies : networking_dependencies)
1129
1129
if not has_ipv6
@@ -1161,11 +1161,6 @@ else
1161
1161
build_options_config.set(' NO_UNIX_SOCKETS' , ' 1' )
1162
1162
endif
1163
1163
1164
- if not compiler.has_function(' pread' )
1165
- libgit_c_args += ' -DNO_PREAD'
1166
- libgit_sources += ' compat/pread.c'
1167
- endif
1168
-
1169
1164
if host_machine .system() == ' darwin'
1170
1165
libgit_sources += ' compat/precompose_utf8.c'
1171
1166
libgit_c_args += ' -DPRECOMPOSE_UNICODE'
@@ -1300,6 +1295,10 @@ if host_machine.system() != 'windows'
1300
1295
endif
1301
1296
endif
1302
1297
1298
+ if compiler.has_member(' struct sysinfo' , ' totalram' , prefix : ' #include <sys/sysinfo.h>' )
1299
+ libgit_c_args += ' -DHAVE_SYSINFO'
1300
+ endif
1301
+
1303
1302
if compiler.has_member(' struct stat' , ' st_mtimespec.tv_nsec' , prefix : ' #include <sys/stat.h>' )
1304
1303
libgit_c_args += ' -DUSE_ST_TIMESPEC'
1305
1304
elif 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
1318
1317
libgit_c_args += ' -DNO_GECOS_IN_PWENT'
1319
1318
endif
1320
1319
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
+ }
1324
1331
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
+ }
1328
1342
endif
1329
1343
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
1334
1352
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'
1338
1355
endif
1339
1356
1340
1357
if not compiler.has_function(' strdup' )
1341
1358
libgit_c_args += ' -DOVERRIDE_STRDUP'
1342
1359
libgit_sources += ' compat/strdup.c'
1343
1360
endif
1344
1361
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
-
1362
1362
if not compiler.has_function(' qsort' )
1363
1363
libgit_c_args += ' -DINTERNAL_QSORT'
1364
1364
endif
1365
1365
libgit_sources += ' compat/qsort_s.c'
1366
1366
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
-
1382
1367
if compiler.has_function(' getdelim' )
1383
1368
libgit_c_args += ' -DHAVE_GETDELIM'
1384
1369
endif
1385
1370
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
1392
1371
1393
1372
if compiler.has_function(' clock_gettime' )
1394
1373
libgit_c_args += ' -DHAVE_CLOCK_GETTIME'
0 commit comments