170170
171171project (' git' , ' c' ,
172172 meson_version : ' >=0.61.0' ,
173- version : ' v2.47.GIT' ,
173+ # The version is only of cosmetic nature, so if we cannot find a shell yet we
174+ # simply don't set up a version at all. This may be the case for example on
175+ # Windows systems, where we first have to bootstrap the host environment.
176+ version : find_program (' sh' , required : false ).found() ? run_command (
177+ ' GIT-VERSION-GEN' , meson .current_source_dir(), ' --format=@GIT_VERSION@' ,
178+ capture : true ,
179+ check : true ,
180+ ).stdout().strip() : ' unknown' ,
181+ default_options : [
182+ # Git requires C99 with GNU extensions, which of course isn't supported by
183+ # MSVC. Funny enough, C99 doesn't work with MSVC either, as it has only
184+ # learned to define __STDC_VERSION__ with C11 and later. We thus require
185+ # GNU C99 and fall back to C11. Meson only learned to handle the fallback
186+ # with version 1.3.0, so on older versions we use GNU C99 unconditionally.
187+ ' c_std=' + (meson .version().version_compare(' >=1.3.0' ) ? ' gnu99,c11' : ' gnu99' ),
188+ ],
174189)
175190
176191fs = import (' fs' )
@@ -481,6 +496,13 @@ libgit_sources = [
481496 ' xdiff/xutils.c' ,
482497]
483498
499+ libgit_sources += custom_target (
500+ input : ' command-list.txt' ,
501+ output : ' command-list.h' ,
502+ command : [shell, meson .current_source_dir() + ' /generate-cmdlist.sh' , meson .current_source_dir(), ' @OUTPUT@' ],
503+ env : script_environment,
504+ )
505+
484506builtin_sources = [
485507 ' builtin/add.c' ,
486508 ' builtin/am.c' ,
@@ -608,14 +630,7 @@ builtin_sources = [
608630 ' builtin/write-tree.c' ,
609631]
610632
611- libgit_sources += custom_target (
612- input : ' command-list.txt' ,
613- output : ' command-list.h' ,
614- command : [shell, meson .current_source_dir() + ' /generate-cmdlist.sh' , meson .current_source_dir(), ' @OUTPUT@' ],
615- env : script_environment,
616- )
617-
618- libgit_sources += custom_target (
633+ builtin_sources += custom_target (
619634 output : ' config-list.h' ,
620635 command : [
621636 shell,
@@ -626,7 +641,7 @@ libgit_sources += custom_target(
626641 env : script_environment,
627642)
628643
629- libgit_sources += custom_target (
644+ builtin_sources += custom_target (
630645 input : ' Documentation/githooks.txt' ,
631646 output : ' hook-list.h' ,
632647 command : [
@@ -1331,6 +1346,7 @@ if not meson.is_cross_build() and fs.exists('/dev/tty')
13311346 libgit_c_args += ' -DHAVE_DEV_TTY'
13321347endif
13331348
1349+ csprng_backend = get_option (' csprng_backend' )
13341350https_backend = get_option (' https_backend' )
13351351sha1_backend = get_option (' sha1_backend' )
13361352sha1_unsafe_backend = get_option (' sha1_unsafe_backend' )
@@ -1342,7 +1358,7 @@ if https_backend == 'auto' and security_framework.found()
13421358 https_backend = ' CommonCrypto'
13431359endif
13441360
1345- openssl_required = ' openssl' in [https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1361+ openssl_required = ' openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
13461362openssl = dependency (' openssl' , required : openssl_required, default_options : [' default_library=static' ])
13471363if https_backend == ' auto' and openssl.found()
13481364 https_backend = ' openssl'
@@ -1427,18 +1443,30 @@ else
14271443 error (' Unhandled SHA256 backend ' + sha256_backend)
14281444endif
14291445
1430- if compiler.has_header_symbol(' stdlib.h' , ' arc4random_buf' )
1446+ # Backends are ordered to reflect our preference for more secure and faster
1447+ # ones over the ones that are less so.
1448+ if csprng_backend in [' auto' , ' arc4random' ] and compiler.has_header_symbol(' stdlib.h' , ' arc4random_buf' , required : csprng_backend == ' arc4random' )
14311449 libgit_c_args += ' -DHAVE_ARC4RANDOM'
1432- elif compiler.has_header_symbol(' bsd/stdlib.h' , ' arc4random_buf' )
1450+ csprng_backend = ' arc4random'
1451+ elif csprng_backend in [' auto' , ' arc4random_bsd' ] and compiler.has_header_symbol(' bsd/stdlib.h' , ' arc4random_buf' , required : csprng_backend == ' arc4random_bsd' )
14331452 libgit_c_args += ' -DHAVE_ARC4RANDOM_BSD'
1434- elif compiler.has_function(' getrandom' , prefix : ' #include <sys/random.h>' )
1453+ csprng_backend = ' arc4random_bsd'
1454+ elif csprng_backend in [' auto' , ' getrandom' ] and compiler.has_header_symbol(' sys/random.h' , ' getrandom' , required : csprng_backend == ' getrandom' )
14351455 libgit_c_args += ' -DHAVE_GETRANDOM'
1436- elif compiler.has_function(' getentropy' , prefix : ' #include <unistd.h>' )
1456+ csprng_backend = ' getrandom'
1457+ elif csprng_backend in [' auto' , ' getentropy' ] and compiler.has_header_symbol(' unistd.h' , ' getentropy' , required : csprng_backend == ' getentropy' )
14371458 libgit_c_args += ' -DHAVE_GETENTROPY'
1438- elif compiler.has_function(' RtlGenRandom' , prefix : ' #include <windows.h>\n #include <ntsecapi.h>' )
1459+ csprng_backend = ' getentropy'
1460+ elif csprng_backend in [' auto' , ' rtlgenrandom' ] and compiler.has_header_symbol(' ntsecapi.h' , ' RtlGenRandom' , prefix : ' #include <windows.h>' , required : csprng_backend == ' rtlgenrandom' )
14391461 libgit_c_args += ' -DHAVE_RTLGENRANDOM'
1440- elif openssl.found()
1462+ csprng_backend = ' rtlgenrandom'
1463+ elif csprng_backend in [' auto' , ' openssl' ] and openssl.found()
14411464 libgit_c_args += ' -DHAVE_OPENSSL_CSPRNG'
1465+ csprng_backend = ' openssl'
1466+ elif csprng_backend in [' auto' , ' urandom' ]
1467+ csprng_backend = ' urandom'
1468+ else
1469+ error (' Unsupported CSPRNG backend: ' + csprng_backend)
14421470endif
14431471
14441472if get_option (' runtime_prefix' )
@@ -1906,6 +1934,10 @@ if get_option('tests')
19061934 subdir (' t' )
19071935endif
19081936
1937+ if get_option (' fuzzers' )
1938+ subdir (' oss-fuzz' )
1939+ endif
1940+
19091941subdir (' bin-wrappers' )
19101942if get_option (' docs' ) != []
19111943 subdir (' Documentation' )
@@ -1941,6 +1973,27 @@ configure_file(
19411973 configuration : build_options_config,
19421974)
19431975
1976+ # Development environments can be used via `meson devenv -C <builddir>`. This
1977+ # allows you to execute test scripts directly with the built Git version and
1978+ # puts the built version of Git in your PATH.
1979+ devenv = environment ()
1980+ devenv.set(' GIT_BUILD_DIR' , meson .current_build_dir())
1981+ devenv.prepend(' PATH' , meson .current_build_dir() / ' bin-wrappers' )
1982+ meson .add_devenv(devenv)
1983+
1984+ # Generate the 'version' file in the distribution tarball. This is used via
1985+ # `meson dist -C <builddir>` to populate the source archive with the Git
1986+ # version that the archive is being generated from.
1987+ meson .add_dist_script(
1988+ shell,
1989+ ' -c' ,
1990+ ' "$1" "$2" "$3" --format="@GIT_VERSION@" "$MESON_DIST_ROOT/version"' ,
1991+ ' GIT-VERSION-GEN' ,
1992+ shell,
1993+ meson .current_source_dir() / ' GIT-VERSION-GEN' ,
1994+ meson .current_source_dir(),
1995+ )
1996+
19441997summary ({
19451998 ' curl' : curl.found(),
19461999 ' expat' : expat.found(),
@@ -1954,6 +2007,7 @@ summary({
19542007}, section : ' Auto-detected features' )
19552008
19562009summary ({
2010+ ' csprng' : csprng_backend,
19572011 ' https' : https_backend,
19582012 ' sha1' : sha1_backend,
19592013 ' sha1_unsafe' : sha1_unsafe_backend,
0 commit comments