Skip to content

Commit 61fb226

Browse files
eli-schwartzgitster
authored andcommitted
meson: simplify and parameterize various standard function checks
This is repetitive logic. We either want to use some -lc function, or if it is not available we define it as -DNO_XXX and usually (but not always) provide some custom compatibility impl instead. Checking the intent of each block when reading through the file is slow and not very DRY. Switch to taking an array of checkable functions instead. Not all functions are straightforward to move, since different macro prefixes are used. Signed-off-by: Eli Schwartz <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4bbb303 commit 61fb226

File tree

1 file changed

+29
-56
lines changed

1 file changed

+29
-56
lines changed

meson.build

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,11 +1133,6 @@ else
11331133
build_options_config.set('NO_UNIX_SOCKETS', '1')
11341134
endif
11351135

1136-
if not compiler.has_function('pread')
1137-
libgit_c_args += '-DNO_PREAD'
1138-
libgit_sources += 'compat/pread.c'
1139-
endif
1140-
11411136
if host_machine.system() == 'darwin'
11421137
libgit_sources += 'compat/precompose_utf8.c'
11431138
libgit_c_args += '-DPRECOMPOSE_UNICODE'
@@ -1290,77 +1285,55 @@ if not compiler.has_member('struct passwd', 'pw_gecos', prefix: '#include <pwd.h
12901285
libgit_c_args += '-DNO_GECOS_IN_PWENT'
12911286
endif
12921287

1293-
if compiler.has_function('sync_file_range')
1294-
libgit_c_args += '-DHAVE_SYNC_FILE_RANGE'
1295-
endif
1288+
checkfuncs = {
1289+
'strcasestr' : ['strcasestr.c'],
1290+
'memmem' : ['memmem.c'],
1291+
'strlcpy' : ['strlcpy.c'],
1292+
'strtoull' : [],
1293+
'setenv' : ['setenv.c'],
1294+
'mkdtemp' : ['mkdtemp.c'],
1295+
'initgroups' : [],
1296+
'strtoumax' : ['strtoumax.c', 'strtoimax.c'],
1297+
'pread' : ['pread.c'],
1298+
}
12961299

1297-
if not compiler.has_function('strcasestr')
1298-
libgit_c_args += '-DNO_STRCASESTR'
1299-
libgit_sources += 'compat/strcasestr.c'
1300+
if host_machine.system() == 'windows'
1301+
libgit_c_args += '-DUSE_WIN32_MMAP'
1302+
else
1303+
checkfuncs += {
1304+
'mmap' : ['mmap.c'],
1305+
# provided by compat/mingw.c.
1306+
'unsetenv' : ['unsetenv.c'],
1307+
}
13001308
endif
13011309

1302-
if not compiler.has_function('memmem')
1303-
libgit_c_args += '-DNO_MEMMEM'
1304-
libgit_sources += 'compat/memmem.c'
1305-
endif
1310+
foreach func, impls : checkfuncs
1311+
if not compiler.has_function(func)
1312+
libgit_c_args += '-DNO_' + func.to_upper()
1313+
foreach impl : impls
1314+
libgit_sources += 'compat/' + impl
1315+
endforeach
1316+
endif
1317+
endforeach
13061318

1307-
if not compiler.has_function('strlcpy')
1308-
libgit_c_args += '-DNO_STRLCPY'
1309-
libgit_sources += 'compat/strlcpy.c'
1319+
if compiler.has_function('sync_file_range')
1320+
libgit_c_args += '-DHAVE_SYNC_FILE_RANGE'
13101321
endif
13111322

13121323
if not compiler.has_function('strdup')
13131324
libgit_c_args += '-DOVERRIDE_STRDUP'
13141325
libgit_sources += 'compat/strdup.c'
13151326
endif
13161327

1317-
if not compiler.has_function('strtoumax')
1318-
libgit_c_args += '-DNO_STRTOUMAX'
1319-
libgit_sources += [
1320-
'compat/strtoumax.c',
1321-
'compat/strtoimax.c',
1322-
]
1323-
endif
1324-
1325-
if not compiler.has_function('strtoull')
1326-
libgit_c_args += '-DNO_STRTOULL'
1327-
endif
1328-
1329-
if not compiler.has_function('setenv')
1330-
libgit_c_args += '-DNO_SETENV'
1331-
libgit_sources += 'compat/setenv.c'
1332-
endif
1333-
13341328
if not compiler.has_function('qsort')
13351329
libgit_c_args += '-DINTERNAL_QSORT'
13361330
endif
13371331
libgit_sources += 'compat/qsort_s.c'
13381332

1339-
# unsetenv is provided by compat/mingw.c.
1340-
if host_machine.system() != 'windows' and not compiler.has_function('unsetenv')
1341-
libgit_c_args += '-DNO_UNSETENV'
1342-
libgit_sources += 'compat/unsetenv.c'
1343-
endif
1344-
1345-
if not compiler.has_function('mkdtemp')
1346-
libgit_c_args += '-DNO_MKDTEMP'
1347-
libgit_sources += 'compat/mkdtemp.c'
1348-
endif
1349-
1350-
if not compiler.has_function('initgroups')
1351-
libgit_c_args += '-DNO_INITGROUPS'
1352-
endif
1353-
13541333
if compiler.has_function('getdelim')
13551334
libgit_c_args += '-DHAVE_GETDELIM'
13561335
endif
13571336

1358-
if host_machine.system() == 'windows'
1359-
libgit_c_args += '-DUSE_WIN32_MMAP'
1360-
elif not compiler.has_function('mmap')
1361-
libgit_c_args += '-DNO_MMAP'
1362-
libgit_sources += 'compat/mmap.c'
1363-
endif
13641337

13651338
if compiler.has_function('clock_gettime')
13661339
libgit_c_args += '-DHAVE_CLOCK_GETTIME'

0 commit comments

Comments
 (0)