Skip to content

Commit a1b3bca

Browse files
committed
meson: Implement getopt logic from autoconf
Not replacing getopt/getopt_long definitely causes issues on mingw. It's not as clear whether the solaris & openbsd aspect is still needed, but if not, we should remove it from both autoconf and meson. Discussion: http://postgr.es/m/[email protected]
1 parent caeeabd commit a1b3bca

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

meson.build

+11-2
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,15 @@ posix4_dep = cc.find_library('posix4', required: false)
22652265

22662266
getopt_dep = cc.find_library('getopt', required: false)
22672267
gnugetopt_dep = cc.find_library('gnugetopt', required: false)
2268+
# Check if we want to replace getopt/getopt_long even if provided by the system
2269+
# - Mingw has adopted a GNU-centric interpretation of optind/optreset,
2270+
# so always use our version on Windows
2271+
# - On OpenBSD and Solaris, getopt() doesn't do what we want for long options
2272+
# (i.e., allow '-' as a flag character), so use our version on those platforms
2273+
# - We want to use system's getopt_long() only if the system provides struct
2274+
# option
2275+
always_replace_getopt = host_system in ['windows', 'openbsd', 'solaris']
2276+
always_replace_getopt_long = host_system == 'windows' or not cdata.has('HAVE_STRUCT_OPTION')
22682277

22692278
# Required on BSDs
22702279
execinfo_dep = cc.find_library('execinfo', required: false)
@@ -2295,8 +2304,8 @@ func_checks = [
22952304
['explicit_bzero'],
22962305
['fdatasync', {'dependencies': [rt_dep, posix4_dep], 'define': false}], # Solaris
22972306
['getifaddrs'],
2298-
['getopt', {'dependencies': [getopt_dep, gnugetopt_dep]}],
2299-
['getopt_long', {'dependencies': [getopt_dep, gnugetopt_dep]}],
2307+
['getopt', {'dependencies': [getopt_dep, gnugetopt_dep], 'skip': always_replace_getopt}],
2308+
['getopt_long', {'dependencies': [getopt_dep, gnugetopt_dep], 'skip': always_replace_getopt_long}],
23002309
['getpeereid'],
23012310
['getpeerucred'],
23022311
['inet_aton'],

0 commit comments

Comments
 (0)