Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/meson.build # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / meson.build` 2401 lines ยท 70936 bytes Raw Blame History 1 # Meson build system 2 # ================== 3 # 4 # The Meson build system is an alternative to our Makefile that you can use to 5 # build, test and install Git. Using Meson results in a couple of benefits: 6 # 7 # - Out-of-tree builds. 8 # - Better integration into IDEs. 9 # - Easy-to-use autoconfiguration of available features on your system. 10 # 11 # To use Meson from the command line you need to have both Meson and Ninja 12 # installed. Alternatively, if you do not have Python available on your system, 13 # you can also use Muon instead of Meson and Samurai instead of Ninja, both of 14 # which are drop-ins replacement that only depend on C. 15 # 16 # Basic usage 17 # =========== 18 # 19 # In the most trivial case, you can configure, build and install Git like this: 20 # 21 # 1. Set up the build directory. This only needs to happen once per build 22 # directory you want to have. You can also configure multiple different 23 # build directories with different configurations. 24 # 25 # $ meson setup build/ 26 # 27 # The build directory gets ignored by Git automatically as Meson will write 28 # a ".gitignore" file into it. From hereon, we will assume that you execute 29 # commands inside this build directory. 30 # 31 # 2. Compile Git. You can either use Meson, Ninja or Samurai to do this, so all 32 # of the following invocations are equivalent: 33 # 34 # $ meson compile 35 # $ ninja 36 # $ samu 37 # 38 # The different invocations should ultimately not make much of a difference. 39 # Using Meson also works with other generators though, like when the build 40 # directory has been set up for use with Microsoft Visual Studio. 41 # 42 # Ninja and Samurai use multiple jobs by default, scaling with the number of 43 # processor cores available. You can pass the `-jN` flag to change this. 44 # 45 # Meson automatically picks up ccache and sccache when these are installed 46 # when setting up the build directory. You can override this behaviour when 47 # setting up the build directory by setting the `CC` environment variable to 48 # your desired compiler. 49 # 50 # 3. Execute tests. Again, you can either use Meson, Ninja or Samurai to do this: 51 # 52 # $ meson test 53 # $ ninja test 54 # $ samu test 55 # 56 # It is recommended to use Meson in this case though as it also provides you 57 # additional features that the other build systems don't have available. 58 # You can e.g. pass additional arguments to the test executables or run 59 # individual tests: 60 # 61 # # Execute the t0000-basic integration test and t-reftable-stack unit test. 62 # $ meson test t0000-basic t-reftable-stack 63 # 64 # # Execute all reftable unit tests. 65 # $ meson test t-reftable-* 66 # 67 # # Execute all tests and stop with the first failure. 68 # $ meson test --maxfail 1 69 # 70 # # Execute single test interactively such that features like `debug ()` work. 71 # $ meson test -i --test-args='-ix' t1400-update-ref 72 # 73 # # Execute all benchmarks. 74 # $ meson test -i --benchmark 75 # 76 # # Execute single benchmark. 77 # $ meson test -i --benchmark p0000-* 78 # 79 # Test execution (but not benchmark execution) is parallelized by default and 80 # scales with the number of processor cores available. You can change the 81 # number of processes by passing the `-jN` flag to `meson test`. 82 # 83 # 4. Install the Git distribution. Again, this can be done via Meson, Ninja or 84 # Samurai: 85 # 86 # $ meson install 87 # $ ninja install 88 # $ samu install 89 # 90 # The prefix into which Git shall be installed is defined when setting up 91 # the build directory. More on that in the "Configuration" section. 92 # 93 # Meson supports multiple backends. The default backend generates Ninja build 94 # instructions, but it also supports the generation of Microsoft Visual 95 # Studio solutions as well as Xcode projects by passing the `--backend` option 96 # to `meson setup`. IDEs like Eclipse and Visual Studio Code provide plugins to 97 # import Meson files directly. 98 # 99 # Configuration 100 # ============= 101 # 102 # The exact configuration of Git is determined when setting up the build 103 # directory via `meson setup`. Unless told otherwise, Meson will automatically 104 # detect the availability of various bits and pieces. There are two different 105 # kinds of options that can be used to further tweak the build: 106 # 107 # - Built-in options provided by Meson. 108 # 109 # - Options defined by the project in the "meson_options.txt" file. 110 # 111 # Both kinds of options can be inspected by running `meson configure` in the 112 # build directory, which will give you a list of the current value for all 113 # options. 114 # 115 # Options can be configured either when setting up the build directory or can 116 # be changed in preexisting build directories: 117 # 118 # # Set up a new build directory with optimized settings that will be 119 # # installed into an alternative prefix. 120 # $ meson setup --buildtype release --optimization 3 --strip --prefix=/home/$USER build 121 # 122 # # Set up a new build directory with a higher warning level. Level 2 is 123 # # mostly equivalent to setting DEVELOPER=1, level 3 and "everything" 124 # # will enable even more warnings. 125 # $ meson setup -Dwarning_level=2 build 126 # 127 # # Set up a new build directory with 'address' and 'undefined' sanitizers 128 # # using Clang. 129 # $ CC=clang meson setup -Db_sanitize=address,undefined build 130 # 131 # # Disable tests in a preexisting build directory. 132 # $ meson configure -Dtests=false 133 # 134 # # Disable features based on Python 135 # $ meson configure -Dpython=disabled 136 # 137 # Options have a type like booleans, choices, strings or features. Features are 138 # somewhat special as they can have one of three values: enabled, disabled or 139 # auto. While the first two values are self-explanatory, "auto" will enable or 140 # disable the feature based on the availability of prerequisites to support it. 141 # Python-based features for example will be enabled automatically when a Python 142 # interpreter could be found. The default value of such features can be changed 143 # via `meson setup --auto-features={enabled,disabled,auto}`, which will set the 144 # value of all features with a value of "auto" to the provided one by default. 145 # 146 # It is also possible to store a set of configuration options in machine files. 147 # This can be useful in case you regularly want to reuse the same set of options: 148 # 149 # [binaries] 150 # c = ['clang'] 151 # ar = ['ar'] 152 # 153 # [project options] 154 # gettext = 'disabled' 155 # default_editor = 'vim' 156 # 157 # [built-in options] 158 # b_lto = true 159 # b_sanitize = 'address,undefined' 160 # 161 # These machine files can be passed to `meson setup` via the `--native-file` 162 # option. 163 # 164 # Fuzzing 165 # ======= 166 # 167 # Meson supports building the fuzzing targets by setting `-Dfuzzers=true`. By 168 # default, the targets will be built without libFuzzer and thus won't be usable 169 # for fuzzing. You have to configure a couple of options to properly wire up 170 # libFuzzer: 171 # 172 # $ meson setup build-fuzzers \ 173 # -Db_sanitize=address,fuzzer-no-link \ 174 # -Dfuzzers=true \ 175 # -Dfuzzers_link_args=-fsanitize=fuzzer 176 # $ meson compile -C build-fuzzers 177 # $ ./build-fuzzers/oss-fuzz/fuzz-config 178 # 179 # Cross compilation 180 # ================= 181 # 182 # Machine files can also be used in the context of cross-compilation to 183 # describe the target machine as well as the cross-compiler toolchain that 184 # shall be used. An example machine file could look like the following: 185 # 186 # [binaries] 187 # c = 'x86_64-w64-mingw32-gcc' 188 # cpp = 'x86_64-w64-mingw32-g++' 189 # ar = 'x86_64-w64-mingw32-ar' 190 # windres = 'x86_64-w64-mingw32-windres' 191 # strip = 'x86_64-w64-mingw32-strip' 192 # exe_wrapper = 'wine64' 193 # sh = 'C:/Program Files/Git for Windows/usr/bin/sh.exe' 194 # 195 # [host_machine] 196 # system = 'windows' 197 # cpu_family = 'x86_64' 198 # cpu = 'x86_64' 199 # endian = 'little' 200 # 201 # These machine files can be passed to `meson setup` via the `--cross-file` 202 # option. 203 # 204 # Note that next to the cross-compiler toolchain, the `[binaries]` section is 205 # also used to locate a couple of binaries that will be built into Git. This 206 # includes `sh`, `python` and `perl`, so when cross-compiling Git you likely 207 # want to set these binary paths in addition to the cross-compiler toolchain 208 # binaries. 209 # 210 # Subproject wrappers 211 # =================== 212 # 213 # Subproject wrappers are a feature provided by Meson that allows the automatic 214 # fallback to a "wrapped" dependency in case the dependency is not provided by 215 # the system. For example if the system is lacking curl, then Meson will use 216 # "subprojects/curl.wrap" to set up curl as a subproject and compile and link 217 # the dependency into Git itself. This is especially helpful on systems like 218 # Windows, where you typically don't have such dependencies installed. 219 # 220 # The use of subproject wrappers can be disabled by executing `meson setup` 221 # with the `--wrap-mode nofallback` option. 222 223 project('git', 'c', 224 meson_version: '>=0.61.0', 225 # The version is only of cosmetic nature, so if we cannot find a shell yet we 226 # simply don't set up a version at all. This may be the case for example on 227 # Windows systems, where we first have to bootstrap the host environment. 228 version: find_program('sh', native: true, required: false).found() ? run_command( 229 'GIT-VERSION-GEN', meson.current_source_dir(), '--format=@GIT_VERSION@', 230 capture: true, 231 check: true, 232 ).stdout().strip() : 'unknown', 233 # Git requires C99 with GNU extensions, which of course isn't supported by 234 # MSVC. Funny enough, C99 doesn't work with MSVC either, as it has only 235 # learned to define __STDC_VERSION__ with C11 and later. We thus require 236 # GNU C99 and fall back to C11. Meson only learned to handle the fallback 237 # with version 1.3.0, so on older versions we use GNU C99 unconditionally. 238 default_options: meson.version().version_compare('>=1.3.0') ? ['rust_std=2018', 'c_std=gnu99,c11'] : ['rust_std=2018', 'c_std=gnu99'], 239 ) 240 241 fs = import('fs') 242 243 program_path = [] 244 if get_option('sane_tool_path').length() != 0 245 program_path = get_option('sane_tool_path') 246 elif host_machine.system() == 'windows' 247 # Git for Windows provides all the tools we need to build Git. 248 program_path = [ 'C:/Program Files/Git/bin', 'C:/Program Files/Git/usr/bin' ] 249 endif 250 251 cygpath = find_program('cygpath', dirs: program_path, native: true, required: false) 252 diff = find_program('diff', dirs: program_path, native: true) 253 git = find_program('git', dirs: program_path, native: true, required: false) 254 sed = find_program('sed', dirs: program_path, native: true) 255 shell = find_program('sh', dirs: program_path, native: true) 256 tar = find_program('tar', dirs: program_path, native: true) 257 tclsh = find_program('tclsh', required: get_option('git_gui'), native: false) 258 time = find_program('time', dirs: program_path, required: get_option('benchmarks')) 259 wish = find_program('wish', required: get_option('git_gui').enabled() or get_option('gitk').enabled(), native: false) 260 261 # Detect the target shell that is used by Git at runtime. Note that we prefer 262 # "/bin/sh" over a PATH-based lookup, which provides a working shell on most 263 # supported systems. This path is also the default shell path used by our 264 # Makefile. This lookup can be overridden via `program_path`. 265 target_shell = find_program('/bin/sh', 'sh', dirs: program_path, native: false) 266 267 # Sanity-check that programs required for the build exist. 268 foreach tool : ['cat', 'cut', 'grep', 'sort', 'tr', 'uname'] 269 find_program(tool, dirs: program_path, native: true) 270 endforeach 271 272 script_environment = environment() 273 foreach path : program_path 274 script_environment.prepend('PATH', path) 275 endforeach 276 277 # The environment used by GIT-VERSION-GEN. Note that we explicitly override 278 # environment variables that might be set by the user. This is by design so 279 # that we always use whatever Meson has configured instead of what is present 280 # in the environment. 281 version_gen_environment = script_environment 282 version_gen_environment.set('GIT_BUILT_FROM_COMMIT', get_option('built_from_commit')) 283 version_gen_environment.set('GIT_DATE', get_option('build_date')) 284 version_gen_environment.set('GIT_USER_AGENT', get_option('user_agent')) 285 version_gen_environment.set('GIT_VERSION', get_option('version')) 286 287 compiler = meson.get_compiler('c') 288 289 compat_sources = [ 290 'compat/nonblock.c', 291 'compat/obstack.c', 292 'compat/open.c', 293 'compat/terminal.c', 294 ] 295 296 hook_list = custom_target( 297 input: 'Documentation/githooks.adoc', 298 output: 'hook-list.h', 299 command: [ 300 shell, 301 meson.current_source_dir() + '/tools/generate-hooklist.sh', 302 meson.current_source_dir(), 303 '@OUTPUT@', 304 ], 305 env: script_environment, 306 ) 307 308 libgit_sources = [ 309 hook_list, 310 'abspath.c', 311 'add-interactive.c', 312 'add-patch.c', 313 'advice.c', 314 'alias.c', 315 'alloc.c', 316 'apply.c', 317 'archive-tar.c', 318 'archive-zip.c', 319 'archive.c', 320 'attr.c', 321 'base85.c', 322 'bisect.c', 323 'blame.c', 324 'blob.c', 325 'bloom.c', 326 'branch.c', 327 'bundle-uri.c', 328 'bundle.c', 329 'cache-tree.c', 330 'cbtree.c', 331 'chdir-notify.c', 332 'checkout.c', 333 'chunk-format.c', 334 'color.c', 335 'column.c', 336 'combine-diff.c', 337 'commit-graph.c', 338 'commit-reach.c', 339 'commit.c', 340 'common-exit.c', 341 'common-init.c', 342 'compiler-tricks/not-constant.c', 343 'config.c', 344 'connect.c', 345 'connected.c', 346 'convert.c', 347 'copy.c', 348 'credential.c', 349 'csum-file.c', 350 'ctype.c', 351 'date.c', 352 'decorate.c', 353 'delta-islands.c', 354 'diagnose.c', 355 'diff-delta.c', 356 'diff-merges.c', 357 'diff-lib.c', 358 'diff-no-index.c', 359 'diff.c', 360 'diffcore-break.c', 361 'diffcore-delta.c', 362 'diffcore-order.c', 363 'diffcore-pickaxe.c', 364 'diffcore-rename.c', 365 'diffcore-rotate.c', 366 'dir-iterator.c', 367 'dir.c', 368 'editor.c', 369 'entry.c', 370 'environment.c', 371 'ewah/bitmap.c', 372 'ewah/ewah_bitmap.c', 373 'ewah/ewah_io.c', 374 'ewah/ewah_rlw.c', 375 'exec-cmd.c', 376 'fetch-negotiator.c', 377 'fetch-object-info.c', 378 'fetch-pack.c', 379 'fmt-merge-msg.c', 380 'fsck.c', 381 'fsmonitor.c', 382 'fsmonitor-ipc.c', 383 'fsmonitor-settings.c', 384 'gettext.c', 385 'git-zlib.c', 386 'gpg-interface.c', 387 'graph.c', 388 'grep.c', 389 'hash-lookup.c', 390 'hash.c', 391 'hashmap.c', 392 'help.c', 393 'hex.c', 394 'hex-ll.c', 395 'hook.c', 396 'ident.c', 397 'json-writer.c', 398 'kwset.c', 399 'levenshtein.c', 400 'line-log.c', 401 'line-range.c', 402 'linear-assignment.c', 403 'list-objects-filter-options.c', 404 'list-objects-filter.c', 405 'list-objects.c', 406 'lockfile.c', 407 'log-tree.c', 408 'loose.c', 409 'ls-refs.c', 410 'mailinfo.c', 411 'mailmap.c', 412 'match-trees.c', 413 'mem-pool.c', 414 'merge-blobs.c', 415 'merge-ll.c', 416 'merge-ort.c', 417 'merge-ort-wrappers.c', 418 'merge.c', 419 'midx.c', 420 'midx-write.c', 421 'name-hash.c', 422 'negotiator/default.c', 423 'negotiator/noop.c', 424 'negotiator/skipping.c', 425 'notes-cache.c', 426 'notes-merge.c', 427 'notes-utils.c', 428 'notes.c', 429 'object-file-convert.c', 430 'object-file.c', 431 'object-name.c', 432 'object.c', 433 'odb.c', 434 'odb/source.c', 435 'odb/source-files.c', 436 'odb/source-inmemory.c', 437 'odb/source-loose.c', 438 'odb/source-packed.c', 439 'odb/streaming.c', 440 'odb/transaction.c', 441 'oid-array.c', 442 'oidmap.c', 443 'oidset.c', 444 'oidtree.c', 445 'pack-bitmap-write.c', 446 'pack-bitmap.c', 447 'pack-check.c', 448 'pack-mtimes.c', 449 'pack-objects.c', 450 'pack-refs.c', 451 'pack-revindex.c', 452 'pack-write.c', 453 'packfile.c', 454 'packfile-list.c', 455 'pager.c', 456 'parallel-checkout.c', 457 'parse.c', 458 'parse-options-cb.c', 459 'parse-options.c', 460 'patch-delta.c', 461 'patch-ids.c', 462 'path.c', 463 'path-walk.c', 464 'pathspec.c', 465 'pkt-line.c', 466 'preload-index.c', 467 'pretty.c', 468 'prio-queue.c', 469 'progress.c', 470 'promisor-remote.c', 471 'prompt.c', 472 'protocol.c', 473 'protocol-caps.c', 474 'prune-packed.c', 475 'pseudo-merge.c', 476 'quote.c', 477 'range-diff.c', 478 'reachable.c', 479 'read-cache.c', 480 'rebase-interactive.c', 481 'rebase.c', 482 'ref-filter.c', 483 'reflog-walk.c', 484 'reflog.c', 485 'refs.c', 486 'refs/debug.c', 487 'refs/files-backend.c', 488 'refs/reftable-backend.c', 489 'refs/iterator.c', 490 'refs/packed-backend.c', 491 'refs/ref-cache.c', 492 'refspec.c', 493 'reftable/basics.c', 494 'reftable/error.c', 495 'reftable/block.c', 496 'reftable/blocksource.c', 497 'reftable/fsck.c', 498 'reftable/iter.c', 499 'reftable/merged.c', 500 'reftable/pq.c', 501 'reftable/record.c', 502 'reftable/stack.c', 503 'reftable/system.c', 504 'reftable/table.c', 505 'reftable/tree.c', 506 'reftable/writer.c', 507 'remote.c', 508 'repack.c', 509 'repack-cruft.c', 510 'repack-filtered.c', 511 'repack-geometry.c', 512 'repack-midx.c', 513 'repack-promisor.c', 514 'replace-object.c', 515 'replay.c', 516 'repo-settings.c', 517 'repository.c', 518 'rerere.c', 519 'reset.c', 520 'resolve-undo.c', 521 'revision.c', 522 'run-command.c', 523 'send-pack.c', 524 'sequencer.c', 525 'serve.c', 526 'server-info.c', 527 'setup.c', 528 'shallow.c', 529 'sideband.c', 530 'sigchain.c', 531 'sparse-index.c', 532 'split-index.c', 533 'stable-qsort.c', 534 'statinfo.c', 535 'strbuf.c', 536 'string-list.c', 537 'strmap.c', 538 'strvec.c', 539 'sub-process.c', 540 'submodule-config.c', 541 'submodule.c', 542 'symlinks.c', 543 'tag.c', 544 'tempfile.c', 545 'thread-utils.c', 546 'tmp-objdir.c', 547 'trace.c', 548 'trace2.c', 549 'trace2/tr2_cfg.c', 550 'trace2/tr2_cmd_name.c', 551 'trace2/tr2_ctr.c', 552 'trace2/tr2_dst.c', 553 'trace2/tr2_sid.c', 554 'trace2/tr2_sysenv.c', 555 'trace2/tr2_tbuf.c', 556 'trace2/tr2_tgt_event.c', 557 'trace2/tr2_tgt_normal.c', 558 'trace2/tr2_tgt_perf.c', 559 'trace2/tr2_tls.c', 560 'trace2/tr2_tmr.c', 561 'trailer.c', 562 'transport-helper.c', 563 'transport.c', 564 'tree-diff.c', 565 'tree-verify.c', 566 'tree-walk.c', 567 'tree.c', 568 'unpack-trees.c', 569 'upload-pack.c', 570 'url.c', 571 'urlmatch.c', 572 'usage.c', 573 'userdiff.c', 574 'utf8.c', 575 'version.c', 576 'versioncmp.c', 577 'walker.c', 578 'wildmatch.c', 579 'worktree.c', 580 'wrapper.c', 581 'write-or-die.c', 582 'ws.c', 583 'wt-status.c', 584 'xdiff-interface.c', 585 'xdiff/xdiffi.c', 586 'xdiff/xemit.c', 587 'xdiff/xhistogram.c', 588 'xdiff/xmerge.c', 589 'xdiff/xpatience.c', 590 'xdiff/xprepare.c', 591 'xdiff/xutils.c', 592 ] 593 594 libgit_sources += custom_target( 595 input: 'command-list.txt', 596 output: 'command-list.h', 597 command: [shell, meson.current_source_dir() + '/tools/generate-cmdlist.sh', meson.current_source_dir(), '@OUTPUT@'], 598 env: script_environment, 599 ) 600 601 builtin_sources = [ 602 hook_list, 603 'builtin/add.c', 604 'builtin/am.c', 605 'builtin/annotate.c', 606 'builtin/apply.c', 607 'builtin/archive.c', 608 'builtin/backfill.c', 609 'builtin/bisect.c', 610 'builtin/blame.c', 611 'builtin/branch.c', 612 'builtin/bugreport.c', 613 'builtin/bundle.c', 614 'builtin/cat-file.c', 615 'builtin/check-attr.c', 616 'builtin/check-ignore.c', 617 'builtin/check-mailmap.c', 618 'builtin/check-ref-format.c', 619 'builtin/checkout--worker.c', 620 'builtin/checkout-index.c', 621 'builtin/checkout.c', 622 'builtin/clean.c', 623 'builtin/clone.c', 624 'builtin/column.c', 625 'builtin/commit-graph.c', 626 'builtin/commit-tree.c', 627 'builtin/commit.c', 628 'builtin/config.c', 629 'builtin/count-objects.c', 630 'builtin/credential-cache--daemon.c', 631 'builtin/credential-cache.c', 632 'builtin/credential-store.c', 633 'builtin/credential.c', 634 'builtin/describe.c', 635 'builtin/diagnose.c', 636 'builtin/diff-files.c', 637 'builtin/diff-index.c', 638 'builtin/diff-pairs.c', 639 'builtin/diff-tree.c', 640 'builtin/diff.c', 641 'builtin/difftool.c', 642 'builtin/fast-export.c', 643 'builtin/fast-import.c', 644 'builtin/fetch-pack.c', 645 'builtin/fetch.c', 646 'builtin/fmt-merge-msg.c', 647 'builtin/for-each-ref.c', 648 'builtin/for-each-repo.c', 649 'builtin/fsck.c', 650 'builtin/fsmonitor--daemon.c', 651 'builtin/gc.c', 652 'builtin/get-tar-commit-id.c', 653 'builtin/grep.c', 654 'builtin/hash-object.c', 655 'builtin/help.c', 656 'builtin/history.c', 657 'builtin/hook.c', 658 'builtin/index-pack.c', 659 'builtin/init-db.c', 660 'builtin/interpret-trailers.c', 661 'builtin/last-modified.c', 662 'builtin/log.c', 663 'builtin/ls-files.c', 664 'builtin/ls-remote.c', 665 'builtin/ls-tree.c', 666 'builtin/mailinfo.c', 667 'builtin/mailsplit.c', 668 'builtin/merge-base.c', 669 'builtin/merge-file.c', 670 'builtin/merge-index.c', 671 'builtin/merge-ours.c', 672 'builtin/merge-recursive.c', 673 'builtin/merge-tree.c', 674 'builtin/merge.c', 675 'builtin/mktag.c', 676 'builtin/mktree.c', 677 'builtin/multi-pack-index.c', 678 'builtin/mv.c', 679 'builtin/name-rev.c', 680 'builtin/notes.c', 681 'builtin/pack-objects.c', 682 'builtin/pack-refs.c', 683 'builtin/patch-id.c', 684 'builtin/prune-packed.c', 685 'builtin/prune.c', 686 'builtin/pull.c', 687 'builtin/push.c', 688 'builtin/range-diff.c', 689 'builtin/read-tree.c', 690 'builtin/rebase.c', 691 'builtin/receive-pack.c', 692 'builtin/reflog.c', 693 'builtin/refs.c', 694 'builtin/remote-ext.c', 695 'builtin/remote-fd.c', 696 'builtin/remote.c', 697 'builtin/repack.c', 698 'builtin/replace.c', 699 'builtin/replay.c', 700 'builtin/repo.c', 701 'builtin/rerere.c', 702 'builtin/reset.c', 703 'builtin/rev-list.c', 704 'builtin/rev-parse.c', 705 'builtin/revert.c', 706 'builtin/rm.c', 707 'builtin/send-pack.c', 708 'builtin/shortlog.c', 709 'builtin/show-branch.c', 710 'builtin/show-index.c', 711 'builtin/show-ref.c', 712 'builtin/sparse-checkout.c', 713 'builtin/stash.c', 714 'builtin/stripspace.c', 715 'builtin/submodule--helper.c', 716 'builtin/symbolic-ref.c', 717 'builtin/tag.c', 718 'builtin/unpack-file.c', 719 'builtin/unpack-objects.c', 720 'builtin/update-index.c', 721 'builtin/update-ref.c', 722 'builtin/update-server-info.c', 723 'builtin/upload-archive.c', 724 'builtin/upload-pack.c', 725 'builtin/url-parse.c', 726 'builtin/var.c', 727 'builtin/verify-commit.c', 728 'builtin/verify-pack.c', 729 'builtin/verify-tag.c', 730 'builtin/worktree.c', 731 'builtin/write-tree.c', 732 ] 733 734 third_party_excludes = [ 735 ':!contrib', 736 ':!compat/inet_ntop.c', 737 ':!compat/inet_pton.c', 738 ':!compat/obstack.*', 739 ':!compat/poll', 740 ':!compat/regex', 741 ':!sha1collisiondetection', 742 ':!sha1dc', 743 ':!t/unit-tests/clar', 744 ':!t/t[0-9][0-9][0-9][0-9]*', 745 ':!xdiff', 746 ] 747 748 headers_to_check = [] 749 if git.found() and fs.exists(meson.project_source_root() / '.git') 750 ls_headers = run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_excludes, check: false) 751 if ls_headers.returncode() == 0 752 foreach header : ls_headers.stdout().split() 753 headers_to_check += header 754 endforeach 755 else 756 warning('could not list headers, disabling static analysis targets') 757 endif 758 endif 759 760 if not get_option('breaking_changes') 761 builtin_sources += 'builtin/pack-redundant.c' 762 endif 763 764 builtin_sources += custom_target( 765 output: 'config-list.h', 766 depfile: 'config-list.h.d', 767 depend_files: [ 'tools/generate-configlist.sh' ], 768 command: [ 769 shell, 770 meson.current_source_dir() / 'tools/generate-configlist.sh', 771 meson.current_source_dir(), 772 '@OUTPUT@', 773 '@DEPFILE@', 774 ], 775 env: script_environment, 776 ) 777 778 # This contains the variables for GIT-BUILD-OPTIONS, which we use to propagate 779 # build options to our tests. 780 build_options_config = configuration_data() 781 build_options_config.set('GIT_INTEROP_MAKE_OPTS', '') 782 build_options_config.set_quoted('GIT_PERF_LARGE_REPO', get_option('benchmark_large_repo')) 783 build_options_config.set('GIT_PERF_MAKE_COMMAND', '') 784 build_options_config.set('GIT_PERF_MAKE_OPTS', '') 785 build_options_config.set_quoted('GIT_PERF_REPEAT_COUNT', get_option('benchmark_repeat_count').to_string()) 786 build_options_config.set_quoted('GIT_PERF_REPO', get_option('benchmark_repo')) 787 build_options_config.set('GIT_TEST_CMP_USE_COPIED_CONTEXT', '') 788 build_options_config.set('GIT_TEST_INDEX_VERSION', '') 789 build_options_config.set('GIT_TEST_OPTS', '') 790 build_options_config.set('GIT_TEST_PERL_FATAL_WARNINGS', '') 791 build_options_config.set_quoted('GIT_TEST_UTF8_LOCALE', get_option('test_utf8_locale')) 792 build_options_config.set_quoted('LOCALEDIR', fs.as_posix(get_option('prefix') / get_option('localedir'))) 793 build_options_config.set_quoted('GITWEBDIR', fs.as_posix(get_option('prefix') / get_option('datadir') / 'gitweb')) 794 795 if get_option('sane_tool_path').length() != 0 796 sane_tool_path = (host_machine.system() == 'windows' ? ';' : ':').join(get_option('sane_tool_path')) 797 build_options_config.set_quoted('BROKEN_PATH_FIX', 's|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + sane_tool_path + '"|') 798 else 799 build_options_config.set_quoted('BROKEN_PATH_FIX', '/^\# @BROKEN_PATH_FIX@$/d') 800 endif 801 802 test_output_directory = get_option('test_output_directory') 803 if test_output_directory == '' 804 test_output_directory = meson.project_build_root() / 'test-output' 805 endif 806 807 htmldir = get_option('htmldir') 808 if htmldir == '' 809 htmldir = get_option('datadir') / 'doc/git-doc' 810 endif 811 812 # These variables are used for building libgit.a. 813 libgit_c_args = [ 814 '-DBINDIR="' + get_option('bindir') + '"', 815 '-DDEFAULT_GIT_TEMPLATE_DIR="' + get_option('datadir') / 'git-core/templates' + '"', 816 '-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"', 817 '-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"', 818 '-DGIT_HTML_PATH="' + htmldir + '"', 819 '-DGIT_INFO_PATH="' + get_option('infodir') + '"', 820 '-DGIT_LOCALE_PATH="' + get_option('localedir') + '"', 821 '-DGIT_MAN_PATH="' + get_option('mandir') + '"', 822 '-DPAGER_ENV="' + get_option('pager_environment') + '"', 823 '-DSHELL_PATH="' + fs.as_posix(target_shell.full_path()) + '"', 824 ] 825 826 system_attributes = get_option('gitattributes') 827 if system_attributes != '' 828 libgit_c_args += '-DETC_GITATTRIBUTES="' + system_attributes + '"' 829 else 830 libgit_c_args += '-DETC_GITATTRIBUTES="' + get_option('sysconfdir') / 'gitattributes"' 831 endif 832 833 system_config = get_option('gitconfig') 834 if system_config != '' 835 libgit_c_args += '-DETC_GITCONFIG="' + system_config + '"' 836 else 837 libgit_c_args += '-DETC_GITCONFIG="' + get_option('sysconfdir') / 'gitconfig"' 838 endif 839 840 editor_opt = get_option('default_editor') 841 if editor_opt != '' and editor_opt != 'vi' 842 libgit_c_args += '-DDEFAULT_EDITOR="' + editor_opt + '"' 843 endif 844 845 pager_opt = get_option('default_pager') 846 if pager_opt != '' and pager_opt != 'less' 847 libgit_c_args += '-DDEFAULT_PAGER="' + pager_opt + '"' 848 endif 849 850 help_format_opt = get_option('default_help_format') 851 if help_format_opt == 'platform' 852 if host_machine.system() == 'windows' 853 help_format_opt = 'html' 854 else 855 help_format_opt = 'man' 856 endif 857 endif 858 if help_format_opt != 'man' 859 libgit_c_args += '-DDEFAULT_HELP_FORMAT="' + help_format_opt + '"' 860 endif 861 862 libgit_include_directories = [ '.' ] 863 libgit_dependencies = [ ] 864 865 # Treat any warning level above 1 the same as we treat DEVELOPER=1 in our 866 # Makefile. 867 if get_option('warning_level') in ['2','3', 'everything'] and compiler.get_argument_syntax() == 'gcc' 868 foreach cflag : [ 869 '-Wcomma', 870 '-Wdeclaration-after-statement', 871 '-Wformat-security', 872 '-Wold-style-definition', 873 '-Woverflow', 874 '-Wpointer-arith', 875 '-Wstrict-prototypes', 876 '-Wunreachable-code', 877 '-Wunused', 878 '-Wvla', 879 '-Wwrite-strings', 880 '-fno-common', 881 '-Wtautological-constant-out-of-range-compare', 882 # If a function is public, there should be a prototype and the right 883 # header file should be included. If not, it should be static. 884 '-Wmissing-prototypes', 885 # These are disabled because we have these all over the place. 886 '-Wno-empty-body', 887 '-Wno-missing-field-initializers', 888 ] 889 if compiler.has_argument(cflag) 890 libgit_c_args += cflag 891 endif 892 endforeach 893 894 # Clang generates warnings when compiling glibc 2.43 because of the use of 895 # _Generic. 896 if compiler.get_id() == 'clang' 897 libgit_c_args += '-Wno-c11-extensions' 898 endif 899 endif 900 901 if get_option('breaking_changes') 902 build_options_config.set('WITH_BREAKING_CHANGES', 'YesPlease') 903 libgit_c_args += '-DWITH_BREAKING_CHANGES' 904 else 905 build_options_config.set('WITH_BREAKING_CHANGES', '') 906 endif 907 908 if get_option('b_sanitize').contains('address') 909 build_options_config.set('SANITIZE_ADDRESS', 'YesCompiledWithIt') 910 else 911 build_options_config.set('SANITIZE_ADDRESS', '') 912 endif 913 if get_option('b_sanitize').contains('leak') 914 build_options_config.set('SANITIZE_LEAK', 'YesCompiledWithIt') 915 else 916 build_options_config.set('SANITIZE_LEAK', '') 917 endif 918 if get_option('b_sanitize').contains('undefined') 919 libgit_c_args += '-DSHA1DC_FORCE_ALIGNED_ACCESS' 920 endif 921 922 executable_suffix = '' 923 if host_machine.system() == 'cygwin' or host_machine.system() == 'windows' 924 executable_suffix = '.exe' 925 libgit_c_args += '-DSTRIP_EXTENSION="' + executable_suffix + '"' 926 endif 927 build_options_config.set_quoted('X', executable_suffix) 928 929 # Python is not used for our build system, but exclusively for git-p4. 930 # Consequently we only need to determine whether Python is available for the 931 # build target. 932 target_python = find_program('python3', native: false, required: get_option('python')) 933 if target_python.found() 934 build_options_config.set('NO_PYTHON', '') 935 else 936 libgit_c_args += '-DNO_PYTHON' 937 build_options_config.set('NO_PYTHON', '1') 938 endif 939 940 # Perl is used for two different things: our test harness and to provide some 941 # features. It is optional if you want to neither execute tests nor use any of 942 # these optional features. 943 perl_required = get_option('perl') 944 if get_option('benchmarks').enabled() or get_option('gitweb').enabled() or 'netrc' in get_option('credential_helpers') 945 perl_required = true 946 endif 947 948 # Note that we only set NO_PERL if the Perl features were disabled by the user. 949 # It may not be set when we have found Perl, but only use it to run tests. 950 # 951 # At the time of writing, executing `perl --version` results in a string 952 # similar to the following output: 953 # 954 # This is perl 5, version 40, subversion 0 (v5.40.0) built for x86_64-linux-thread-multi 955 # 956 # Meson picks up the "40" as version number instead of using "v5.40.0" 957 # due to the regular expression it uses. This got fixed in Meson 1.7.0, 958 # but meanwhile we have to either use `-V:version` instead of `--version`, 959 # which we can do starting with Meson 1.5.0 and newer, or we have to 960 # match against the minor version. 961 if meson.version().version_compare('>=1.5.0') 962 perl = find_program('perl', dirs: program_path, native: true, required: perl_required, version: '>=5.26.0', version_argument: '-V:version') 963 target_perl = find_program('perl', dirs: program_path, native: false, required: perl.found(), version: '>=5.26.0', version_argument: '-V:version') 964 else 965 perl = find_program('perl', dirs: program_path, native: true, required: perl_required, version: '>=26') 966 target_perl = find_program('perl', dirs: program_path, native: false, required: perl.found(), version: '>=26') 967 endif 968 perl_features_enabled = perl.found() and get_option('perl').allowed() 969 if perl_features_enabled 970 build_options_config.set('NO_PERL', '') 971 972 if get_option('runtime_prefix') 973 build_options_config.set('PERL_LOCALEDIR', '') 974 else 975 build_options_config.set_quoted('PERL_LOCALEDIR', fs.as_posix(get_option('prefix') / get_option('localedir'))) 976 endif 977 978 if get_option('perl_cpan_fallback') 979 build_options_config.set('NO_PERL_CPAN_FALLBACKS', '') 980 else 981 build_options_config.set_quoted('NO_PERL_CPAN_FALLBACKS', 'YesPlease') 982 endif 983 else 984 libgit_c_args += '-DNO_PERL' 985 build_options_config.set('NO_PERL', '1') 986 build_options_config.set('PERL_LOCALEDIR', '') 987 build_options_config.set('NO_PERL_CPAN_FALLBACKS', '') 988 endif 989 990 zlib_backend = get_option('zlib_backend') 991 if zlib_backend in ['auto', 'zlib-ng'] 992 zlib_ng = dependency('zlib-ng', required: zlib_backend == 'zlib-ng') 993 if zlib_ng.found() 994 zlib_backend = 'zlib-ng' 995 libgit_c_args += '-DHAVE_ZLIB_NG' 996 libgit_dependencies += zlib_ng 997 endif 998 endif 999 if zlib_backend in ['auto', 'zlib'] 1000 zlib = dependency('zlib', default_options: ['default_library=static', 'tests=disabled']) 1001 if zlib.version().version_compare('<1.2.0') 1002 libgit_c_args += '-DNO_DEFLATE_BOUND' 1003 endif 1004 zlib_backend = 'zlib' 1005 libgit_dependencies += zlib 1006 endif 1007 1008 threads = dependency('threads', required: false) 1009 if threads.found() 1010 libgit_dependencies += threads 1011 build_options_config.set('NO_PTHREADS', '') 1012 else 1013 libgit_c_args += '-DNO_PTHREADS' 1014 build_options_config.set('NO_PTHREADS', '1') 1015 endif 1016 1017 msgfmt = find_program('msgfmt', dirs: program_path, native: true, required: false) 1018 gettext_option = get_option('gettext').disable_auto_if(not msgfmt.found()) 1019 if not msgfmt.found() and gettext_option.enabled() 1020 error('Internationalization via libintl requires msgfmt') 1021 endif 1022 1023 if gettext_option.allowed() and host_machine.system() == 'darwin' and get_option('macos_use_homebrew_gettext') 1024 if host_machine.cpu_family() == 'x86_64' 1025 libintl_prefix = '/usr/local' 1026 elif host_machine.cpu_family() == 'aarch64' 1027 libintl_prefix = '/opt/homebrew' 1028 else 1029 error('Homebrew workaround not supported on current architecture') 1030 endif 1031 1032 intl = compiler.find_library('intl', dirs: libintl_prefix / 'lib', required: gettext_option) 1033 if intl.found() 1034 intl = declare_dependency( 1035 dependencies: intl, 1036 include_directories: libintl_prefix / 'include', 1037 ) 1038 endif 1039 else 1040 intl = dependency('intl', required: gettext_option) 1041 endif 1042 if intl.found() 1043 libgit_dependencies += intl 1044 build_options_config.set('NO_GETTEXT', '') 1045 build_options_config.set('USE_GETTEXT_SCHEME', '') 1046 1047 # POSIX nowadays requires `nl_langinfo()`, but some systems still don't have 1048 # the function available. On such systems we instead fall back to libcharset. 1049 # On native Windows systems we use our own emulation. 1050 if host_machine.system() != 'windows' and not compiler.has_function('nl_langinfo') 1051 libcharset = compiler.find_library('charset', required: true) 1052 libgit_dependencies += libcharset 1053 libgit_c_args += '-DHAVE_LIBCHARSET_H' 1054 endif 1055 else 1056 libgit_c_args += '-DNO_GETTEXT' 1057 build_options_config.set('NO_GETTEXT', '1') 1058 build_options_config.set('USE_GETTEXT_SCHEME', 'fallthrough') 1059 endif 1060 1061 iconv = dependency('iconv', required: get_option('iconv')) 1062 if iconv.found() 1063 libgit_dependencies += iconv 1064 build_options_config.set('NO_ICONV', '') 1065 1066 have_old_iconv = false 1067 if not compiler.compiles(''' 1068 #include 1069 1070 extern size_t iconv(iconv_t cd, 1071 char **inbuf, size_t *inbytesleft, 1072 char **outbuf, size_t *outbytesleft); 1073 ''', name: 'old iconv interface', dependencies: [iconv]) 1074 libgit_c_args += '-DOLD_ICONV' 1075 have_old_iconv = true 1076 endif 1077 1078 if meson.can_run_host_binaries() 1079 if compiler.run(''' 1080 #include 1081 1082 int main(int argc, const char **argv) 1083 { 1084 char in[] = "a", *inpos = in; 1085 char out[20] = "", *outpos = out; 1086 size_t insz = sizeof(in), outsz = sizeof(out); 1087 iconv_t conv = iconv_open("UTF-16", "UTF-8"); 1088 iconv(conv, (void *) &inpos, &insz, &outpos, &outsz); 1089 iconv_close(conv); 1090 return (unsigned char)(out[0]) + (unsigned char)(out[1]) != 0xfe + 0xff; 1091 } 1092 ''', 1093 dependencies: iconv, 1094 name: 'iconv omits BOM', 1095 ).returncode() != 0 1096 libgit_c_args += '-DICONV_OMITS_BOM' 1097 endif 1098 1099 if compiler.run(''' 1100 #include 1101 #include 1102 1103 int main(int argc, const char *argv[]) 1104 { 1105 char in[] = "\x1b\x24\x42\x24\x22\x24\x22\x1b\x28\x42", *inpos = in; 1106 char out[7] = { 0 }, *outpos = out; 1107 size_t insz = sizeof(in) - 1, outsz = 4; 1108 iconv_t conv = iconv_open("UTF-8", "ISO-2022-JP"); 1109 if (!conv) 1110 return 1; 1111 if (iconv(conv, (void *) &inpos, &insz, &outpos, &outsz) != (size_t) -1) 1112 return 2; 1113 outsz = sizeof(out) - (outpos - out); 1114 if (iconv(conv, (void *) &inpos, &insz, &outpos, &outsz) == (size_t) -1) 1115 return 3; 1116 return strcmp("\343\201\202\343\201\202", out) ? 4 : 0; 1117 } 1118 ''', 1119 dependencies: iconv, 1120 name: 'iconv handles restarts properly', 1121 ).returncode() != 0 1122 libgit_c_args += '-DICONV_RESTART_RESET' 1123 endif 1124 endif 1125 else 1126 libgit_c_args += '-DNO_ICONV' 1127 build_options_config.set('NO_ICONV', '1') 1128 endif 1129 1130 # can't use enable_auto_if() because it is only available in meson 1.1 1131 if host_machine.system() == 'windows' and get_option('pcre2').allowed() 1132 pcre2_feature = true 1133 else 1134 pcre2_feature = get_option('pcre2') 1135 endif 1136 pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false']) 1137 if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin' 1138 # macOS installs a broken system package, double check 1139 if not compiler.has_header('pcre2.h', dependencies: pcre2) 1140 if pcre2_feature.enabled() 1141 pcre2_fallback = ['pcre2', 'libpcre2_8'] 1142 else 1143 pcre2_fallback = [] 1144 endif 1145 # Attempt to fallback or replace with not-found-dependency 1146 pcre2 = dependency('', required: false, fallback: pcre2_fallback, default_options: ['default_library=static', 'test=false']) 1147 if not pcre2.found() 1148 if pcre2_feature.enabled() 1149 error('only a broken pcre2 install found and pcre2 is required') 1150 else 1151 warning('broken pcre2 install found, disabling pcre2 feature') 1152 endif 1153 endif 1154 endif 1155 endif 1156 1157 if pcre2.found() 1158 libgit_dependencies += pcre2 1159 libgit_c_args += '-DUSE_LIBPCRE2' 1160 build_options_config.set('USE_LIBPCRE2', '1') 1161 else 1162 build_options_config.set('USE_LIBPCRE2', '') 1163 endif 1164 1165 curl = dependency('libcurl', version: '>=7.21.3', required: get_option('curl'), default_options: ['default_library=static', 'tests=disabled', 'tool=disabled']) 1166 use_curl_for_imap_send = false 1167 if curl.found() 1168 if curl.version().version_compare('>=7.34.0') 1169 libgit_c_args += '-DUSE_CURL_FOR_IMAP_SEND' 1170 use_curl_for_imap_send = true 1171 endif 1172 1173 # Most executables don't have to link against libcurl, but we still need its 1174 # include directories so that we can resolve LIBCURL_VERSION in "help.c". 1175 libgit_dependencies += curl.partial_dependency(includes: true) 1176 build_options_config.set('NO_CURL', '') 1177 else 1178 libgit_c_args += '-DNO_CURL' 1179 build_options_config.set('NO_CURL', '1') 1180 endif 1181 1182 expat = dependency('expat', required: get_option('expat'), default_options: ['default_library=static', 'build_tests=false']) 1183 if expat.found() 1184 libgit_dependencies += expat 1185 1186 if expat.version().version_compare('<=1.2') 1187 libgit_c_args += '-DEXPAT_NEEDS_XMLPARSE_H' 1188 endif 1189 build_options_config.set('NO_EXPAT', '') 1190 else 1191 libgit_c_args += '-DNO_EXPAT' 1192 build_options_config.set('NO_EXPAT', '1') 1193 endif 1194 1195 if not compiler.has_header('sys/select.h') 1196 libgit_c_args += '-DNO_SYS_SELECT_H' 1197 endif 1198 1199 has_poll_h = compiler.has_header('poll.h') 1200 if not has_poll_h 1201 libgit_c_args += '-DNO_POLL_H' 1202 endif 1203 1204 has_sys_poll_h = compiler.has_header('sys/poll.h') 1205 if not has_sys_poll_h 1206 libgit_c_args += '-DNO_SYS_POLL_H' 1207 endif 1208 1209 if not has_poll_h and not has_sys_poll_h 1210 libgit_c_args += '-DNO_POLL' 1211 compat_sources += 'compat/poll/poll.c' 1212 libgit_include_directories += 'compat/poll' 1213 endif 1214 1215 if not compiler.has_header('inttypes.h') 1216 libgit_c_args += '-DNO_INTTYPES_H' 1217 endif 1218 1219 if compiler.has_header('alloca.h') 1220 libgit_c_args += '-DHAVE_ALLOCA_H' 1221 endif 1222 1223 # Windows has libgen.h and a basename implementation, but we still need our own 1224 # implementation to threat things like drive prefixes specially. 1225 if host_machine.system() == 'windows' or not compiler.has_header('libgen.h') 1226 libgit_c_args += '-DNO_LIBGEN_H' 1227 compat_sources += 'compat/basename.c' 1228 endif 1229 1230 if compiler.has_header('paths.h') 1231 libgit_c_args += '-DHAVE_PATHS_H' 1232 endif 1233 1234 if compiler.has_header('strings.h') 1235 libgit_c_args += '-DHAVE_STRINGS_H' 1236 endif 1237 1238 networking_dependencies = [ ] 1239 if host_machine.system() == 'windows' 1240 winsock = compiler.find_library('ws2_32', required: false) 1241 if winsock.found() 1242 networking_dependencies += winsock 1243 endif 1244 else 1245 networking_dependencies += [ 1246 compiler.find_library('nsl', required: false), 1247 compiler.find_library('resolv', required: false), 1248 compiler.find_library('socket', required: false), 1249 ] 1250 endif 1251 libgit_dependencies += networking_dependencies 1252 1253 if host_machine.system() != 'windows' 1254 foreach symbol : ['inet_ntop', 'inet_pton', 'hstrerror'] 1255 if not compiler.has_function(symbol, dependencies: networking_dependencies) 1256 libgit_c_args += '-DNO_' + symbol.to_upper() 1257 compat_sources += 'compat/' + symbol + '.c' 1258 endif 1259 endforeach 1260 endif 1261 1262 has_ipv6 = compiler.has_function('getaddrinfo', dependencies: networking_dependencies) 1263 if not has_ipv6 1264 libgit_c_args += '-DNO_IPV6' 1265 endif 1266 1267 if not compiler.compiles(''' 1268 #ifdef _WIN32 1269 # include 1270 #else 1271 # include 1272 # include 1273 #endif 1274 1275 void func(void) 1276 { 1277 struct sockaddr_storage x; 1278 } 1279 ''', name: 'struct sockaddr_storage') 1280 if has_ipv6 1281 libgit_c_args += '-Dsockaddr_storage=sockaddr_in6' 1282 else 1283 libgit_c_args += '-Dsockaddr_storage=sockaddr_in' 1284 endif 1285 endif 1286 1287 if compiler.has_function('socket', dependencies: networking_dependencies) 1288 libgit_sources += [ 1289 'unix-socket.c', 1290 'unix-stream-server.c', 1291 ] 1292 build_options_config.set('NO_UNIX_SOCKETS', '') 1293 else 1294 libgit_c_args += '-DNO_UNIX_SOCKETS' 1295 build_options_config.set('NO_UNIX_SOCKETS', '1') 1296 endif 1297 1298 if host_machine.system() == 'darwin' 1299 compat_sources += 'compat/precompose_utf8.c' 1300 libgit_c_args += '-DPRECOMPOSE_UNICODE' 1301 libgit_c_args += '-DPROTECT_HFS_DEFAULT' 1302 endif 1303 1304 # Configure general compatibility wrappers. 1305 if host_machine.system() == 'cygwin' 1306 compat_sources += [ 1307 'compat/win32/path-utils.c', 1308 ] 1309 elif host_machine.system() == 'windows' 1310 compat_sources += [ 1311 'compat/winansi.c', 1312 'compat/win32/dirent.c', 1313 'compat/win32/flush.c', 1314 'compat/win32/path-utils.c', 1315 'compat/win32/pthread.c', 1316 'compat/win32/syslog.c', 1317 'compat/win32mmap.c', 1318 ] 1319 1320 libgit_c_args += [ 1321 '-DDETECT_MSYS_TTY', 1322 '-DNATIVE_CRLF', 1323 '-DNOGDI', 1324 '-DNO_POSIX_GOODIES', 1325 '-DWIN32', 1326 '-D_CONSOLE', 1327 '-D_CONSOLE_DETECT_MSYS_TTY', 1328 '-D__USE_MINGW_ANSI_STDIO=0', 1329 ] 1330 1331 msystem = get_option('msystem') 1332 if msystem != '' 1333 mingw_prefix = get_option('mingw_prefix') 1334 if mingw_prefix == '' 1335 mingw_prefix = msystem.to_lower() 1336 elif mingw_prefix.startswith('/') 1337 mingw_prefix = mingw_prefix.substring(1) 1338 endif 1339 libgit_c_args += [ 1340 '-DENSURE_MSYSTEM_IS_SET="' + msystem + '"', 1341 '-DMINGW_PREFIX="' + mingw_prefix + '"' 1342 ] 1343 endif 1344 1345 libgit_dependencies += compiler.find_library('ntdll') 1346 libgit_include_directories += 'compat/win32' 1347 if compiler.get_id() == 'msvc' 1348 libgit_include_directories += 'compat/vcbuild/include' 1349 compat_sources += 'compat/msvc.c' 1350 else 1351 compat_sources += 'compat/mingw.c' 1352 endif 1353 endif 1354 1355 if host_machine.system() == 'linux' 1356 compat_sources += 'compat/linux/procinfo.c' 1357 elif host_machine.system() == 'windows' 1358 compat_sources += 'compat/win32/trace2_win32_process_info.c' 1359 elif host_machine.system() == 'darwin' 1360 compat_sources += 'compat/darwin/procinfo.c' 1361 else 1362 compat_sources += 'compat/stub/procinfo.c' 1363 endif 1364 1365 if host_machine.system() == 'cygwin' or host_machine.system() == 'windows' 1366 libgit_c_args += [ 1367 '-DUNRELIABLE_FSTAT', 1368 '-DMMAP_PREVENTS_DELETE', 1369 '-DOBJECT_CREATION_MODE=1', 1370 ] 1371 endif 1372 1373 # Configure the simple-ipc subsystem required fro the fsmonitor. 1374 if host_machine.system() == 'windows' 1375 compat_sources += [ 1376 'compat/simple-ipc/ipc-shared.c', 1377 'compat/simple-ipc/ipc-win32.c', 1378 ] 1379 libgit_c_args += '-DSUPPORTS_SIMPLE_IPC' 1380 else 1381 compat_sources += [ 1382 'compat/simple-ipc/ipc-shared.c', 1383 'compat/simple-ipc/ipc-unix-socket.c', 1384 ] 1385 libgit_c_args += '-DSUPPORTS_SIMPLE_IPC' 1386 endif 1387 1388 fsmonitor_backend = '' 1389 fsmonitor_os = '' 1390 if host_machine.system() == 'windows' 1391 fsmonitor_backend = 'win32' 1392 fsmonitor_os = 'win32' 1393 elif host_machine.system() == 'linux' and threads.found() and compiler.has_header('linux/magic.h') 1394 fsmonitor_backend = 'linux' 1395 fsmonitor_os = 'unix' 1396 libgit_c_args += '-DHAVE_LINUX_MAGIC_H' 1397 elif host_machine.system() == 'darwin' 1398 fsmonitor_backend = 'darwin' 1399 fsmonitor_os = 'unix' 1400 libgit_dependencies += dependency('CoreServices') 1401 endif 1402 if fsmonitor_backend != '' 1403 libgit_c_args += '-DHAVE_FSMONITOR_DAEMON_BACKEND' 1404 libgit_c_args += '-DHAVE_FSMONITOR_OS_SETTINGS' 1405 1406 compat_sources += [ 1407 'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c', 1408 'compat/fsmonitor/fsm-ipc-' + fsmonitor_os + '.c', 1409 'compat/fsmonitor/fsm-listen-' + fsmonitor_backend + '.c', 1410 'compat/fsmonitor/fsm-path-utils-' + fsmonitor_backend + '.c', 1411 'compat/fsmonitor/fsm-settings-' + fsmonitor_os + '.c', 1412 ] 1413 endif 1414 build_options_config.set_quoted('FSMONITOR_DAEMON_BACKEND', fsmonitor_backend) 1415 build_options_config.set_quoted('FSMONITOR_OS_SETTINGS', fsmonitor_os) 1416 1417 if not get_option('b_sanitize').contains('address') and get_option('regex').allowed() and compiler.has_header('regex.h') and compiler.get_define('REG_STARTEND', prefix: '#include ') != '' 1418 build_options_config.set('NO_REGEX', '') 1419 1420 if compiler.get_define('REG_ENHANCED', prefix: '#include ') != '' 1421 libgit_c_args += '-DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS' 1422 compat_sources += 'compat/regcomp_enhanced.c' 1423 endif 1424 elif not get_option('regex').enabled() 1425 libgit_c_args += [ 1426 '-DNO_REGEX', 1427 '-DGAWK', 1428 '-DNO_MBSUPPORT', 1429 ] 1430 build_options_config.set('NO_REGEX', '1') 1431 compat_sources += 'compat/regex/regex.c' 1432 libgit_include_directories += 'compat/regex' 1433 else 1434 error('Native regex support requested but not found') 1435 endif 1436 1437 # setitimer and friends are provided by compat/mingw.c. 1438 if host_machine.system() != 'windows' 1439 if not compiler.compiles(''' 1440 #include 1441 void func(void) 1442 { 1443 struct itimerval value; 1444 } 1445 ''', name: 'struct itimerval') 1446 libgit_c_args += '-DNO_STRUCT_ITIMERVAL' 1447 libgit_c_args += '-DNO_SETITIMER' 1448 elif not compiler.has_function('setitimer') 1449 libgit_c_args += '-DNO_SETITIMER' 1450 endif 1451 endif 1452 1453 if compiler.has_member('struct stat', 'st_mtimespec.tv_nsec', prefix: '#include ') 1454 libgit_c_args += '-DUSE_ST_TIMESPEC' 1455 elif not compiler.has_member('struct stat', 'st_mtim.tv_nsec', prefix: '#include ') 1456 libgit_c_args += '-DNO_NSEC' 1457 endif 1458 1459 if not compiler.has_member('struct stat', 'st_blocks', prefix: '#include ') 1460 libgit_c_args += '-DNO_ST_BLOCKS_IN_STRUCT_STAT' 1461 endif 1462 1463 if not compiler.has_member('struct dirent', 'd_type', prefix: '#include ') 1464 libgit_c_args += '-DNO_D_TYPE_IN_DIRENT' 1465 endif 1466 1467 if not compiler.has_member('struct passwd', 'pw_gecos', prefix: '#include ') 1468 libgit_c_args += '-DNO_GECOS_IN_PWENT' 1469 endif 1470 1471 checkfuncs = { 1472 'strcasestr' : ['strcasestr.c'], 1473 'memmem' : ['memmem.c'], 1474 'strlcpy' : ['strlcpy.c'], 1475 'strtoull' : [], 1476 'setenv' : ['setenv.c'], 1477 'mkdtemp' : [], 1478 'initgroups' : [], 1479 'strtoumax' : ['strtoumax.c', 'strtoimax.c'], 1480 'pread' : ['pread.c'], 1481 'writev' : ['writev.c'], 1482 } 1483 1484 if host_machine.system() == 'windows' 1485 libgit_c_args += '-DUSE_WIN32_MMAP' 1486 else 1487 checkfuncs += { 1488 # provided by compat/mingw.c. 1489 'unsetenv' : ['unsetenv.c'], 1490 # provided by compat/mingw.c. 1491 'getpagesize' : [], 1492 } 1493 1494 if get_option('b_sanitize').contains('address') or get_option('b_sanitize').contains('leak') 1495 libgit_c_args += '-DNO_MMAP' 1496 compat_sources += 'compat/mmap.c' 1497 else 1498 checkfuncs += { 'mmap': ['mmap.c'] } 1499 endif 1500 endif 1501 1502 foreach func, impls : checkfuncs 1503 if not compiler.has_function(func) 1504 libgit_c_args += '-DNO_' + func.to_upper() 1505 foreach impl : impls 1506 compat_sources += 'compat/' + impl 1507 endforeach 1508 endif 1509 endforeach 1510 1511 if compiler.has_function('sync_file_range') 1512 libgit_c_args += '-DHAVE_SYNC_FILE_RANGE' 1513 endif 1514 1515 if not compiler.has_function('strdup') 1516 libgit_c_args += '-DOVERRIDE_STRDUP' 1517 compat_sources += 'compat/strdup.c' 1518 endif 1519 1520 if not compiler.has_function('qsort') 1521 libgit_c_args += '-DINTERNAL_QSORT' 1522 endif 1523 compat_sources += 'compat/qsort_s.c' 1524 1525 if compiler.has_function('getdelim') 1526 libgit_c_args += '-DHAVE_GETDELIM' 1527 endif 1528 1529 1530 if compiler.has_function('clock_gettime') 1531 libgit_c_args += '-DHAVE_CLOCK_GETTIME' 1532 endif 1533 1534 if compiler.compiles(''' 1535 #include 1536 1537 void func(void) 1538 { 1539 clockid_t id = CLOCK_MONOTONIC; 1540 } 1541 ''', name: 'monotonic clock') 1542 libgit_c_args += '-DHAVE_CLOCK_MONOTONIC' 1543 endif 1544 1545 has_bsd_sysctl = false 1546 if compiler.has_header('sys/sysctl.h') 1547 if compiler.compiles(''' 1548 #include 1549 #include 1550 1551 void func(void) 1552 { 1553 int val, mib[2] = { 0 }; 1554 size_t len = sizeof(val); 1555 sysctl(mib, 2, &val, &len, NULL, 0); 1556 } 1557 ''', name: 'BSD sysctl') 1558 libgit_c_args += '-DHAVE_BSD_SYSCTL' 1559 has_bsd_sysctl = true 1560 endif 1561 endif 1562 1563 if not has_bsd_sysctl 1564 if compiler.has_member('struct sysinfo', 'totalram', prefix: '#include ') 1565 libgit_c_args += '-DHAVE_SYSINFO' 1566 endif 1567 endif 1568 1569 if meson.can_run_host_binaries() and compiler.run(''' 1570 #include 1571 1572 int main(int argc, const char **argv) 1573 { 1574 FILE *f = fopen(".", "r"); 1575 return f ? 0 : 1; 1576 } 1577 ''', name: 'fread reads directories').returncode() == 0 1578 libgit_c_args += '-DFREAD_READS_DIRECTORIES' 1579 compat_sources += 'compat/fopen.c' 1580 endif 1581 1582 if not meson.is_cross_build() and fs.exists('/dev/tty') 1583 libgit_c_args += '-DHAVE_DEV_TTY' 1584 endif 1585 1586 csprng_backend = get_option('csprng_backend') 1587 https_backend = get_option('https_backend') 1588 sha1_backend = get_option('sha1_backend') 1589 sha1_unsafe_backend = get_option('sha1_unsafe_backend') 1590 sha256_backend = get_option('sha256_backend') 1591 1592 security_framework = dependency('Security', required: 'CommonCrypto' in [https_backend, sha1_backend, sha1_unsafe_backend]) 1593 core_foundation_framework = dependency('CoreFoundation', required: security_framework.found()) 1594 if https_backend == 'auto' and security_framework.found() 1595 https_backend = 'CommonCrypto' 1596 endif 1597 1598 openssl_required = 'openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend] 1599 openssl = dependency('openssl', 1600 required: openssl_required, 1601 allow_fallback: openssl_required or https_backend == 'auto', 1602 default_options: ['default_library=static'], 1603 ) 1604 if https_backend == 'auto' and openssl.found() 1605 https_backend = 'openssl' 1606 endif 1607 1608 if https_backend == 'CommonCrypto' 1609 libgit_dependencies += security_framework 1610 libgit_dependencies += core_foundation_framework 1611 libgit_c_args += '-DAPPLE_COMMON_CRYPTO' 1612 elif https_backend == 'openssl' 1613 libgit_dependencies += openssl 1614 else 1615 # We either couldn't find any dependencies with 'auto' or the user requested 1616 # 'none'. Both cases are benign. 1617 https_backend = 'none' 1618 endif 1619 1620 if https_backend != 'openssl' 1621 libgit_c_args += '-DNO_OPENSSL' 1622 endif 1623 1624 if sha1_backend == 'sha1dc' 1625 libgit_c_args += '-DSHA1_DC' 1626 libgit_c_args += '-DSHA1DC_NO_STANDARD_INCLUDES=1' 1627 libgit_c_args += '-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0' 1628 libgit_c_args += '-DSHA1DC_CUSTOM_INCLUDE_SHA1_C="git-compat-util.h"' 1629 libgit_c_args += '-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h"' 1630 1631 libgit_sources += [ 1632 'sha1dc_git.c', 1633 'sha1dc/sha1.c', 1634 'sha1dc/ubc_check.c', 1635 ] 1636 endif 1637 if sha1_backend == 'CommonCrypto' or sha1_unsafe_backend == 'CommonCrypto' 1638 if sha1_backend == 'CommonCrypto' 1639 libgit_c_args += '-DSHA1_APPLE' 1640 endif 1641 if sha1_unsafe_backend == 'CommonCrypto' 1642 libgit_c_args += '-DSHA1_APPLE_UNSAFE' 1643 endif 1644 1645 libgit_c_args += '-DCOMMON_DIGEST_FOR_OPENSSL' 1646 # Apple CommonCrypto requires chunking 1647 libgit_c_args += '-DSHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' 1648 endif 1649 if sha1_backend == 'openssl' or sha1_unsafe_backend == 'openssl' 1650 if sha1_backend == 'openssl' 1651 libgit_c_args += '-DSHA1_OPENSSL' 1652 endif 1653 if sha1_unsafe_backend == 'openssl' 1654 libgit_c_args += '-DSHA1_OPENSSL_UNSAFE' 1655 endif 1656 1657 libgit_dependencies += openssl 1658 endif 1659 if sha1_backend == 'block' or sha1_unsafe_backend == 'block' 1660 if sha1_backend == 'block' 1661 libgit_c_args += '-DSHA1_BLK' 1662 endif 1663 if sha1_unsafe_backend == 'block' 1664 libgit_c_args += '-DSHA1_BLK_UNSAFE' 1665 endif 1666 1667 libgit_sources += 'block-sha1/sha1.c' 1668 endif 1669 1670 if sha256_backend == 'openssl' 1671 libgit_c_args += '-DSHA256_OPENSSL' 1672 libgit_dependencies += openssl 1673 elif sha256_backend == 'nettle' 1674 nettle = dependency('nettle') 1675 libgit_dependencies += nettle 1676 libgit_c_args += '-DSHA256_NETTLE' 1677 elif sha256_backend == 'gcrypt' 1678 gcrypt = dependency('gcrypt') 1679 libgit_dependencies += gcrypt 1680 libgit_c_args += '-DSHA256_GCRYPT' 1681 elif sha256_backend == 'block' 1682 libgit_c_args += '-DSHA256_BLK' 1683 libgit_sources += 'sha256/block/sha256.c' 1684 else 1685 error('Unhandled SHA256 backend ' + sha256_backend) 1686 endif 1687 1688 # Backends are ordered to reflect our preference for more secure and faster 1689 # ones over the ones that are less so. 1690 if csprng_backend in ['auto', 'arc4random'] and compiler.has_header_symbol('stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random') 1691 libgit_c_args += '-DHAVE_ARC4RANDOM' 1692 csprng_backend = 'arc4random' 1693 elif csprng_backend in ['auto', 'arc4random_bsd'] and compiler.has_header_symbol('bsd/stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random_bsd') 1694 libgit_c_args += '-DHAVE_ARC4RANDOM_BSD' 1695 csprng_backend = 'arc4random_bsd' 1696 elif csprng_backend in ['auto', 'getrandom'] and compiler.has_header_symbol('sys/random.h', 'getrandom', required: csprng_backend == 'getrandom') 1697 libgit_c_args += '-DHAVE_GETRANDOM' 1698 csprng_backend = 'getrandom' 1699 elif csprng_backend in ['auto', 'getentropy'] and compiler.has_header_symbol('unistd.h', 'getentropy', required: csprng_backend == 'getentropy') 1700 libgit_c_args += '-DHAVE_GETENTROPY' 1701 csprng_backend = 'getentropy' 1702 elif csprng_backend in ['auto', 'rtlgenrandom'] and compiler.has_header_symbol('ntsecapi.h', 'RtlGenRandom', prefix: '#include ', required: csprng_backend == 'rtlgenrandom') 1703 libgit_c_args += '-DHAVE_RTLGENRANDOM' 1704 csprng_backend = 'rtlgenrandom' 1705 elif csprng_backend in ['auto', 'openssl'] and openssl.found() 1706 libgit_c_args += '-DHAVE_OPENSSL_CSPRNG' 1707 csprng_backend = 'openssl' 1708 elif csprng_backend in ['auto', 'urandom'] 1709 csprng_backend = 'urandom' 1710 else 1711 error('Unsupported CSPRNG backend: ' + csprng_backend) 1712 endif 1713 1714 git_exec_path = 'libexec/git-core' 1715 libexec = get_option('libexecdir') 1716 if libexec != 'libexec' and libexec != '.' 1717 git_exec_path = libexec 1718 endif 1719 1720 if get_option('runtime_prefix') 1721 libgit_c_args += '-DRUNTIME_PREFIX' 1722 build_options_config.set('RUNTIME_PREFIX', 'true') 1723 1724 if git_exec_path.startswith('/') 1725 error('runtime_prefix requires a relative libexecdir not:', libexec) 1726 endif 1727 1728 if compiler.has_header('mach-o/dyld.h') 1729 libgit_c_args += '-DHAVE_NS_GET_EXECUTABLE_PATH' 1730 endif 1731 1732 if has_bsd_sysctl and compiler.compiles(''' 1733 #include 1734 1735 void func(void) 1736 { 1737 KERN_PROC_PATHNAME; KERN_PROC; 1738 } 1739 ''', name: 'BSD KERN_PROC_PATHNAME') 1740 libgit_c_args += '-DHAVE_NS_GET_EXECUTABLE_PATH' 1741 endif 1742 1743 if host_machine.system() == 'linux' 1744 libgit_c_args += '-DPROCFS_EXECUTABLE_PATH="/proc/self/exe' + '"' 1745 elif host_machine.system() == 'openbsd' 1746 libgit_c_args += '-DPROCFS_EXECUTABLE_PATH="' + '/proc/curproc/file' + '"' 1747 elif host_machine.system() == 'netbsd' 1748 libgit_c_args += '-DPROCFS_EXECUTABLE_PATH="' + '/proc/curproc/exe' + '"' 1749 endif 1750 1751 if host_machine.system() == 'windows' and compiler.compiles(''' 1752 #include 1753 1754 void func(void) 1755 { 1756 _wpgmptr; 1757 } 1758 ''', name: 'Win32 _wpgmptr') 1759 libgit_c_args += '-DHAVE_WPGMPTR' 1760 endif 1761 else 1762 build_options_config.set('RUNTIME_PREFIX', 'false') 1763 endif 1764 libgit_c_args += '-DGIT_EXEC_PATH="' + git_exec_path + '"' 1765 1766 git_version_file = custom_target( 1767 command: [ 1768 shell, 1769 meson.current_source_dir() / 'GIT-VERSION-GEN', 1770 meson.current_source_dir(), 1771 '@INPUT@', 1772 '@OUTPUT@', 1773 ], 1774 input: meson.current_source_dir() / 'GIT-VERSION-FILE.in', 1775 output: 'GIT-VERSION-FILE', 1776 env: version_gen_environment, 1777 build_always_stale: true, 1778 ) 1779 1780 version_def_h = custom_target( 1781 command: [ 1782 shell, 1783 meson.current_source_dir() / 'GIT-VERSION-GEN', 1784 meson.current_source_dir(), 1785 '@INPUT@', 1786 '@OUTPUT@', 1787 ], 1788 input: meson.current_source_dir() / 'version-def.h.in', 1789 output: 'version-def.h', 1790 # Depend on GIT-VERSION-FILE so that we don't always try to rebuild this 1791 # target for the same commit. 1792 depends: [git_version_file], 1793 env: version_gen_environment, 1794 ) 1795 libgit_sources += version_def_h 1796 1797 rust_option = get_option('rust') 1798 if rust_option.allowed() 1799 subdir('src') 1800 libgit_c_args += '-DWITH_RUST' 1801 1802 if host_machine.system() == 'windows' 1803 libgit_dependencies += compiler.find_library('userenv') 1804 endif 1805 else 1806 libgit_sources += [ 1807 'varint.c', 1808 ] 1809 endif 1810 1811 libgit = declare_dependency( 1812 link_with: [ 1813 static_library('compat', 1814 sources: compat_sources, 1815 c_args: libgit_c_args, 1816 dependencies: libgit_dependencies, 1817 include_directories: libgit_include_directories, 1818 ), 1819 static_library('git', 1820 sources: libgit_sources, 1821 c_args: libgit_c_args + [ 1822 '-DGIT_VERSION_H="' + version_def_h.full_path() + '"', 1823 ], 1824 c_pch: 'tools/precompiled.h', 1825 dependencies: libgit_dependencies, 1826 include_directories: libgit_include_directories, 1827 ), 1828 ], 1829 compile_args: libgit_c_args, 1830 dependencies: libgit_dependencies, 1831 include_directories: libgit_include_directories, 1832 ) 1833 1834 common_main_sources = ['common-main.c'] 1835 common_main_link_args = [ ] 1836 if host_machine.system() == 'windows' 1837 git_rc = custom_target( 1838 command: [ 1839 shell, 1840 meson.current_source_dir() / 'GIT-VERSION-GEN', 1841 meson.current_source_dir(), 1842 '@INPUT@', 1843 '@OUTPUT@', 1844 ], 1845 input: meson.current_source_dir() / 'git.rc.in', 1846 output: 'git.rc', 1847 depends: [git_version_file], 1848 env: version_gen_environment, 1849 ) 1850 1851 common_main_sources += import('windows').compile_resources(git_rc, 1852 include_directories: [meson.current_source_dir()], 1853 ) 1854 if compiler.get_argument_syntax() == 'gcc' 1855 common_main_link_args += [ 1856 '-municode', 1857 '-Wl,-nxcompat', 1858 '-Wl,-dynamicbase', 1859 '-Wl,-pic-executable,-e,mainCRTStartup', 1860 ] 1861 elif compiler.get_argument_syntax() == 'msvc' 1862 common_main_link_args += [ 1863 '/ENTRY:wmainCRTStartup', 1864 'invalidcontinue.obj', 1865 ] 1866 else 1867 error('Unsupported compiler ' + compiler.get_id()) 1868 endif 1869 endif 1870 1871 libgit_commonmain = declare_dependency( 1872 link_with: static_library('common-main', 1873 sources: common_main_sources, 1874 dependencies: [ libgit ], 1875 ), 1876 link_args: common_main_link_args, 1877 dependencies: [ libgit ], 1878 ) 1879 1880 bin_wrappers = [ ] 1881 test_dependencies = [ ] 1882 1883 git_builtin = executable('git', 1884 sources: builtin_sources + 'git.c', 1885 c_pch: 'tools/precompiled.h', 1886 dependencies: [libgit_commonmain], 1887 install: true, 1888 install_dir: git_exec_path, 1889 ) 1890 bin_wrappers += git_builtin 1891 1892 test_dependencies += executable('git-daemon', 1893 sources: 'daemon.c', 1894 dependencies: [libgit_commonmain], 1895 install: true, 1896 install_dir: git_exec_path, 1897 ) 1898 1899 test_dependencies += executable('git-sh-i18n--envsubst', 1900 sources: 'sh-i18n--envsubst.c', 1901 dependencies: [libgit_commonmain], 1902 install: true, 1903 install_dir: git_exec_path, 1904 ) 1905 1906 bin_wrappers += executable('git-shell', 1907 sources: 'shell.c', 1908 dependencies: [libgit_commonmain], 1909 install: true, 1910 install_dir: git_exec_path, 1911 ) 1912 1913 test_dependencies += executable('git-http-backend', 1914 sources: 'http-backend.c', 1915 dependencies: [libgit_commonmain], 1916 install: true, 1917 install_dir: git_exec_path, 1918 ) 1919 1920 bin_wrappers += executable('scalar', 1921 sources: 'scalar.c', 1922 dependencies: [libgit_commonmain], 1923 install: true, 1924 install_dir: git_exec_path, 1925 ) 1926 1927 if curl.found() 1928 libgit_curl = declare_dependency( 1929 link_with: static_library('git-curl', 1930 sources: [ 1931 'http.c', 1932 'http-walker.c', 1933 ], 1934 dependencies: [libgit_commonmain, curl], 1935 ), 1936 dependencies: [libgit_commonmain, curl], 1937 ) 1938 1939 git_remote_http = executable('git-remote-http', 1940 sources: 'remote-curl.c', 1941 dependencies: [libgit_curl], 1942 install: true, 1943 install_dir: git_exec_path, 1944 ) 1945 test_dependencies += git_remote_http 1946 1947 test_dependencies += executable('git-http-fetch', 1948 sources: 'http-fetch.c', 1949 dependencies: [libgit_curl], 1950 install: true, 1951 install_dir: git_exec_path, 1952 ) 1953 1954 if expat.found() 1955 test_dependencies += executable('git-http-push', 1956 sources: 'http-push.c', 1957 dependencies: [libgit_curl], 1958 install: true, 1959 install_dir: git_exec_path, 1960 ) 1961 endif 1962 1963 foreach alias : [ 'git-remote-https', 'git-remote-ftp', 'git-remote-ftps' ] 1964 test_dependencies += executable(alias, 1965 objects: git_remote_http.extract_all_objects(recursive: false), 1966 dependencies: [libgit_curl], 1967 ) 1968 1969 install_symlink(alias + executable_suffix, 1970 install_dir: git_exec_path, 1971 pointing_to: 'git-remote-http', 1972 ) 1973 endforeach 1974 endif 1975 1976 test_dependencies += executable('git-imap-send', 1977 sources: 'imap-send.c', 1978 dependencies: [ use_curl_for_imap_send ? libgit_curl : libgit_commonmain ], 1979 install: true, 1980 install_dir: git_exec_path, 1981 ) 1982 1983 foreach alias : [ 'git-receive-pack', 'git-upload-archive', 'git-upload-pack' ] 1984 bin_wrappers += executable(alias, 1985 objects: git_builtin.extract_all_objects(recursive: false), 1986 dependencies: [libgit_commonmain], 1987 ) 1988 1989 install_symlink(alias + executable_suffix, 1990 install_dir: git_exec_path, 1991 pointing_to: 'git', 1992 ) 1993 endforeach 1994 1995 foreach symlink : [ 1996 'git', 1997 'git-receive-pack', 1998 'git-shell', 1999 'git-upload-archive', 2000 'git-upload-pack', 2001 'scalar', 2002 ] 2003 if meson.version().version_compare('>=1.3.0') 2004 pointing_to = fs.relative_to(git_exec_path / symlink, get_option('bindir')) 2005 else 2006 pointing_to = '..' / git_exec_path / symlink 2007 endif 2008 2009 install_symlink(symlink, 2010 install_dir: get_option('bindir'), 2011 pointing_to: pointing_to, 2012 ) 2013 endforeach 2014 2015 scripts_sh = [ 2016 'git-difftool--helper.sh', 2017 'git-filter-branch.sh', 2018 'git-merge-octopus.sh', 2019 'git-merge-one-file.sh', 2020 'git-merge-resolve.sh', 2021 'git-mergetool--lib.sh', 2022 'git-mergetool.sh', 2023 'git-quiltimport.sh', 2024 'git-request-pull.sh', 2025 'git-sh-i18n.sh', 2026 'git-sh-setup.sh', 2027 'git-submodule.sh', 2028 'git-web--browse.sh', 2029 ] 2030 if perl_features_enabled 2031 scripts_sh += 'git-instaweb.sh' 2032 endif 2033 2034 foreach script : scripts_sh 2035 test_dependencies += custom_target( 2036 input: script, 2037 output: fs.stem(script), 2038 command: [ 2039 shell, 2040 meson.project_source_root() / 'tools/generate-script.sh', 2041 '@INPUT@', 2042 '@OUTPUT@', 2043 meson.project_build_root() / 'GIT-BUILD-OPTIONS', 2044 ], 2045 install: true, 2046 install_dir: git_exec_path, 2047 ) 2048 endforeach 2049 2050 if perl_features_enabled 2051 scripts_perl = [ 2052 'git-archimport.perl', 2053 'git-cvsexportcommit.perl', 2054 'git-cvsimport.perl', 2055 'git-cvsserver.perl', 2056 'git-send-email.perl', 2057 'git-svn.perl', 2058 ] 2059 2060 pathsep = ':' 2061 if host_machine.system() == 'windows' 2062 pathsep = ';' 2063 endif 2064 2065 perl_header_template = 'perl/header_templates/fixed_prefix.template.pl' 2066 if get_option('runtime_prefix') 2067 perl_header_template = 'perl/header_templates/runtime_prefix.template.pl' 2068 endif 2069 2070 perllibdir = get_option('perllibdir') 2071 if perllibdir == '' 2072 perllibdir = get_option('datadir') / 'perl5' 2073 endif 2074 2075 perl_header = configure_file( 2076 input: perl_header_template, 2077 output: 'GIT-PERL-HEADER', 2078 configuration: { 2079 'GITEXECDIR_REL': git_exec_path, 2080 'PERLLIBDIR_REL': perllibdir, 2081 'LOCALEDIR_REL': get_option('datadir') / 'locale', 2082 'INSTLIBDIR': perllibdir, 2083 'PATHSEP': pathsep, 2084 }, 2085 ) 2086 2087 generate_perl_command = [ 2088 shell, 2089 meson.project_source_root() / 'tools/generate-perl.sh', 2090 meson.project_build_root() / 'GIT-BUILD-OPTIONS', 2091 git_version_file.full_path(), 2092 perl_header, 2093 '@INPUT@', 2094 '@OUTPUT@', 2095 ] 2096 2097 foreach script : scripts_perl 2098 generated_script = custom_target( 2099 input: script, 2100 output: fs.stem(script), 2101 command: generate_perl_command, 2102 install: true, 2103 install_dir: git_exec_path, 2104 depends: [git_version_file], 2105 ) 2106 test_dependencies += generated_script 2107 2108 if script == 'git-cvsserver.perl' 2109 bin_wrappers += generated_script 2110 2111 if meson.version().version_compare('>=1.3.0') 2112 pointing_to = fs.relative_to(git_exec_path / fs.stem(script), get_option('bindir')) 2113 else 2114 pointing_to = '..' / git_exec_path / fs.stem(script) 2115 endif 2116 2117 install_symlink(fs.stem(script), 2118 install_dir: get_option('bindir'), 2119 pointing_to: pointing_to, 2120 ) 2121 endif 2122 endforeach 2123 2124 subdir('perl') 2125 endif 2126 2127 if target_python.found() 2128 scripts_python = [ 2129 'git-p4.py' 2130 ] 2131 2132 foreach script : scripts_python 2133 generated_python = custom_target( 2134 input: script, 2135 output: fs.stem(script), 2136 command: [ 2137 shell, 2138 meson.project_source_root() / 'tools/generate-python.sh', 2139 meson.project_build_root() / 'GIT-BUILD-OPTIONS', 2140 '@INPUT@', 2141 '@OUTPUT@', 2142 ], 2143 install: true, 2144 install_dir: git_exec_path, 2145 ) 2146 test_dependencies += generated_python 2147 endforeach 2148 endif 2149 2150 mergetools = [ 2151 'mergetools/araxis', 2152 'mergetools/bc', 2153 'mergetools/codecompare', 2154 'mergetools/deltawalker', 2155 'mergetools/diffmerge', 2156 'mergetools/diffuse', 2157 'mergetools/ecmerge', 2158 'mergetools/emerge', 2159 'mergetools/examdiff', 2160 'mergetools/guiffy', 2161 'mergetools/gvimdiff', 2162 'mergetools/kdiff3', 2163 'mergetools/kompare', 2164 'mergetools/meld', 2165 'mergetools/nvimdiff', 2166 'mergetools/opendiff', 2167 'mergetools/p4merge', 2168 'mergetools/smerge', 2169 'mergetools/tkdiff', 2170 'mergetools/tortoisemerge', 2171 'mergetools/vimdiff', 2172 'mergetools/vscode', 2173 'mergetools/winmerge', 2174 'mergetools/xxdiff', 2175 ] 2176 2177 foreach mergetool : mergetools 2178 install_data(mergetool, install_dir: git_exec_path / 'mergetools') 2179 endforeach 2180 2181 if intl.found() 2182 subdir('po') 2183 endif 2184 2185 # Gitweb requires Perl, so we disable the auto-feature if Perl was not found. 2186 # We make sure further up that Perl is required in case the gitweb option is 2187 # enabled. 2188 gitweb_option = get_option('gitweb').disable_auto_if(not perl.found()) 2189 if gitweb_option.allowed() 2190 subdir('gitweb') 2191 build_options_config.set('NO_GITWEB', '') 2192 else 2193 build_options_config.set('NO_GITWEB', '1') 2194 endif 2195 2196 subdir('templates') 2197 2198 # Everything but the bin-wrappers need to come before this target such that we 2199 # can properly set up test dependencies. The bin-wrappers themselves are set up 2200 # at configuration time, so these are fine. 2201 if get_option('tests') 2202 test_kwargs = { 2203 'timeout': 0, 2204 } 2205 2206 # The TAP protocol was already understood by previous versions of Meson, but 2207 # it was incompatible with the `meson test --interactive` flag. 2208 if meson.version().version_compare('>=1.8.0') 2209 test_kwargs += { 2210 'protocol': 'tap', 2211 } 2212 endif 2213 2214 subdir('t') 2215 endif 2216 2217 if get_option('fuzzers') 2218 subdir('oss-fuzz') 2219 endif 2220 2221 subdir('bin-wrappers') 2222 if get_option('docs') != [] 2223 doc_targets = [] 2224 subdir('Documentation') 2225 else 2226 docs_backend = 'none' 2227 endif 2228 2229 subdir('contrib') 2230 subdir('tools') 2231 2232 # Note that the target is intentionally configured after including the 2233 # 'contrib' directory, as some tool there also have their own manpages. 2234 if get_option('docs') != [] 2235 alias_target('docs', doc_targets) 2236 endif 2237 2238 exclude_from_check_headers = [ 2239 'compat/', 2240 'unicode-width.h', 2241 ] 2242 2243 if sha1_backend != 'openssl' 2244 exclude_from_check_headers += 'sha1/openssl.h' 2245 endif 2246 if sha256_backend != 'openssl' 2247 exclude_from_check_headers += 'sha256/openssl.h' 2248 endif 2249 if sha256_backend != 'nettle' 2250 exclude_from_check_headers += 'sha256/nettle.h' 2251 endif 2252 if sha256_backend != 'gcrypt' 2253 exclude_from_check_headers += 'sha256/gcrypt.h' 2254 endif 2255 2256 if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc' 2257 hco_targets = [] 2258 foreach h : headers_to_check 2259 skip_header = false 2260 foreach exclude : exclude_from_check_headers 2261 if h.startswith(exclude) 2262 skip_header = true 2263 break 2264 endif 2265 endforeach 2266 2267 if skip_header 2268 continue 2269 endif 2270 2271 hcc = custom_target( 2272 input: h, 2273 output: h.underscorify() + 'cc', 2274 command: [ 2275 shell, 2276 '-c', 2277 'echo \'#include "git-compat-util.h"\' > @OUTPUT@ && echo \'#include "' + h + '"\' >> @OUTPUT@' 2278 ] 2279 ) 2280 2281 hco = custom_target( 2282 input: hcc, 2283 output: fs.replace_suffix(h.underscorify(), '.hco'), 2284 command: [ 2285 compiler.cmd_array(), 2286 libgit_c_args, 2287 '-I', meson.project_source_root(), 2288 '-I', meson.project_source_root() / 't/unit-tests', 2289 '-o', '/dev/null', 2290 '-c', '-xc', 2291 '@INPUT@' 2292 ] 2293 ) 2294 hco_targets += hco 2295 endforeach 2296 2297 # TODO: deprecate 'hdr-check' in lieu of 'check-headers' in Git 2.51+ 2298 hdr_check = alias_target('hdr-check', hco_targets) 2299 alias_target('check-headers', hdr_check) 2300 endif 2301 2302 git_clang_format = find_program('git-clang-format', required: false, native: true) 2303 if git_clang_format.found() 2304 run_target('style', 2305 command: [ 2306 git_clang_format, 2307 '--style', 'file', 2308 '--diff', 2309 '--extensions', 'c,h' 2310 ] 2311 ) 2312 endif 2313 2314 foreach key, value : { 2315 'DIFF': diff.full_path(), 2316 'GIT_SOURCE_DIR': meson.project_source_root(), 2317 'GIT_TEST_CMP': diff.full_path() + ' -u', 2318 'GIT_TEST_GITPERLLIB': meson.project_build_root() / 'perl', 2319 'GIT_TEST_TEMPLATE_DIR': meson.project_build_root() / 'templates', 2320 'GIT_TEST_TEXTDOMAINDIR': meson.project_build_root() / 'po', 2321 'PAGER_ENV': get_option('pager_environment'), 2322 'PERL_PATH': target_perl.found() ? target_perl.full_path() : '', 2323 'PYTHON_PATH': target_python.found () ? target_python.full_path() : '', 2324 'SHELL_PATH': target_shell.full_path(), 2325 'TAR': tar.full_path(), 2326 'TEST_OUTPUT_DIRECTORY': test_output_directory, 2327 'TEST_SHELL_PATH': shell.full_path(), 2328 } 2329 if value != '' and cygpath.found() 2330 value = run_command(cygpath, value, check: true).stdout().strip() 2331 endif 2332 build_options_config.set_quoted(key, value) 2333 endforeach 2334 2335 configure_file( 2336 input: 'GIT-BUILD-OPTIONS.in', 2337 output: 'GIT-BUILD-OPTIONS', 2338 configuration: build_options_config, 2339 ) 2340 2341 gitk_option = get_option('gitk').disable_auto_if(not wish.found()) 2342 if gitk_option.allowed() 2343 subproject('gitk') 2344 endif 2345 2346 git_gui_option = get_option('git_gui').disable_auto_if(not tclsh.found() or not wish.found()) 2347 if git_gui_option.allowed() 2348 subproject('git-gui') 2349 endif 2350 2351 # Development environments can be used via `meson devenv -C `. This 2352 # allows you to execute test scripts directly with the built Git version and 2353 # puts the built version of Git in your PATH. 2354 devenv = environment() 2355 devenv.set('GIT_BUILD_DIR', meson.current_build_dir()) 2356 devenv.prepend('PATH', meson.current_build_dir() / 'bin-wrappers') 2357 meson.add_devenv(devenv) 2358 2359 # Generate the 'version' file in the distribution tarball. This is used via 2360 # `meson dist -C ` to populate the source archive with the Git 2361 # version that the archive is being generated from. 2362 meson.add_dist_script( 2363 shell, 2364 '-c', 2365 '"$1" "$2" "$3" --format="@GIT_VERSION@" "$MESON_DIST_ROOT/version"', 2366 'GIT-VERSION-GEN', 2367 shell, 2368 meson.current_source_dir() / 'GIT-VERSION-GEN', 2369 meson.current_source_dir(), 2370 ) 2371 2372 summary({ 2373 'benchmarks': get_option('tests') and perl.found() and time.found(), 2374 'curl': curl, 2375 'expat': expat, 2376 'gettext': intl, 2377 'gitk': gitk_option.allowed(), 2378 'git-gui': git_gui_option.allowed(), 2379 'gitweb': gitweb_option.allowed(), 2380 'iconv': iconv, 2381 'pcre2': pcre2, 2382 'perl': perl_features_enabled, 2383 'python': target_python.found(), 2384 'rust': rust_option.allowed(), 2385 }, section: 'Auto-detected features', bool_yn: true) 2386 2387 summary({ 2388 'csprng': csprng_backend, 2389 'docs': docs_backend, 2390 'https': https_backend, 2391 'sha1': sha1_backend, 2392 'sha1_unsafe': sha1_unsafe_backend, 2393 'sha256': sha256_backend, 2394 'zlib': zlib_backend, 2395 }, section: 'Backends') 2396 2397 summary({ 2398 'perl': target_perl, 2399 'python': target_python, 2400 'shell': target_shell, 2401 }, section: 'Runtime executable paths')