@@ -191,30 +191,29 @@ project('git', 'c',
191191fs = import (' fs' )
192192
193193program_path = []
194- # Git for Windows provides all the tools we need to build Git.
195- if host_machine .system() == ' windows'
196- program_path += [ ' C:/Program Files/Git/bin' , ' C:/Program Files/Git/usr/bin' ]
194+ if get_option (' sane_tool_path' ).length() != 0
195+ program_path = get_option (' sane_tool_path' )
196+ elif host_machine .system() == ' windows'
197+ # Git for Windows provides all the tools we need to build Git.
198+ program_path = [ ' C:/Program Files/Git/bin' , ' C:/Program Files/Git/usr/bin' ]
197199endif
198200
199201cygpath = find_program (' cygpath' , dirs : program_path, required : false )
200202diff = find_program (' diff' , dirs : program_path)
203+ git = find_program (' git' , dirs : program_path, required : false )
204+ sed = find_program (' sed' , dirs : program_path)
201205shell = find_program (' sh' , dirs : program_path)
202206tar = find_program (' tar' , dirs : program_path)
203207
204- script_environment = environment ()
205- foreach tool : [' cat' , ' cut' , ' grep' , ' sed' , ' sort' , ' tr' , ' uname' ]
206- program = find_program (tool, dirs : program_path)
207- script_environment.prepend(' PATH' , fs.parent(program.full_path()))
208+ # Sanity-check that programs required for the build exist.
209+ foreach tool : [' cat' , ' cut' , ' grep' , ' sort' , ' tr' , ' uname' ]
210+ find_program (tool, dirs : program_path)
208211endforeach
209212
210- git = find_program (' git' , dirs : program_path, required : false )
211- if git.found()
212- script_environment.prepend(' PATH' , fs.parent(git.full_path()))
213- endif
214-
215- if get_option (' sane_tool_path' ) != ''
216- script_environment.prepend(' PATH' , get_option (' sane_tool_path' ))
217- endif
213+ script_environment = environment ()
214+ foreach path : program_path
215+ script_environment.prepend(' PATH' , path)
216+ endforeach
218217
219218# The environment used by GIT-VERSION-GEN. Note that we explicitly override
220219# environment variables that might be set by the user. This is by design so
@@ -480,6 +479,7 @@ libgit_sources = [
480479 ' userdiff.c' ,
481480 ' utf8.c' ,
482481 ' varint.c' ,
482+ ' version.c' ,
483483 ' versioncmp.c' ,
484484 ' walker.c' ,
485485 ' wildmatch.c' ,
679679 build_options_config.set(' WITH_BREAKING_CHANGES' , '' )
680680endif
681681
682- if get_option (' sane_tool_path' ) != ''
683- build_options_config.set_quoted(' BROKEN_PATH_FIX' , ' s|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + get_option (' sane_tool_path' ) + ' "|' )
682+ if get_option (' sane_tool_path' ).length() != 0
683+ sane_tool_path = (host_machine .system() == ' windows' ? ' ;' : ' :' ).join(get_option (' sane_tool_path' ))
684+ build_options_config.set_quoted(' BROKEN_PATH_FIX' , ' s|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + sane_tool_path + ' "|' )
684685else
685686 build_options_config.set_quoted(' BROKEN_PATH_FIX' , ' /^\# @BROKEN_PATH_FIX@$/d' )
686687endif
@@ -700,7 +701,6 @@ libgit_c_args = [
700701 ' -DETC_GITATTRIBUTES="' + get_option (' gitattributes' ) + ' "' ,
701702 ' -DETC_GITCONFIG="' + get_option (' gitconfig' ) + ' "' ,
702703 ' -DFALLBACK_RUNTIME_PREFIX="' + get_option (' prefix' ) + ' "' ,
703- ' -DGIT_EXEC_PATH="' + get_option (' prefix' ) / get_option (' libexecdir' ) / ' git-core"' ,
704704 ' -DGIT_HOST_CPU="' + host_machine .cpu_family() + ' "' ,
705705 ' -DGIT_HTML_PATH="' + get_option (' datadir' ) / ' doc/git-doc"' ,
706706 ' -DGIT_INFO_PATH="' + get_option (' infodir' ) + ' "' ,
@@ -964,7 +964,9 @@ if curl.found()
964964 use_curl_for_imap_send = true
965965 endif
966966
967- libgit_dependencies += curl
967+ # Most executables don't have to link against libcurl, but we still need its
968+ # include directories so that we can resolve LIBCURL_VERSION in "help.c".
969+ libgit_dependencies += curl.partial_dependency(includes : true )
968970 libgit_c_args += ' -DCURL_DISABLE_TYPECHECK'
969971 build_options_config.set(' NO_CURL' , '' )
970972else
@@ -1389,7 +1391,11 @@ if https_backend == 'auto' and security_framework.found()
13891391endif
13901392
13911393openssl_required = ' openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1392- openssl = dependency (' openssl' , required : openssl_required, default_options : [' default_library=static' ])
1394+ openssl = dependency (' openssl' ,
1395+ required : openssl_required,
1396+ allow_fallback : openssl_required or https_backend == ' auto' ,
1397+ default_options : [' default_library=static' ],
1398+ )
13931399if https_backend == ' auto' and openssl.found()
13941400 https_backend = ' openssl'
13951401endif
@@ -1403,6 +1409,7 @@ elif https_backend == 'openssl'
14031409else
14041410 # We either couldn't find any dependencies with 'auto' or the user requested
14051411 # 'none'. Both cases are benign.
1412+ https_backend = ' none'
14061413endif
14071414
14081415if https_backend != ' openssl'
@@ -1502,6 +1509,7 @@ endif
15021509if get_option (' runtime_prefix' )
15031510 libgit_c_args += ' -DRUNTIME_PREFIX'
15041511 build_options_config.set(' RUNTIME_PREFIX' , ' true' )
1512+ git_exec_path = get_option (' libexecdir' ) / ' git-core'
15051513
15061514 if compiler.has_header(' mach-o/dyld.h' )
15071515 libgit_c_args += ' -DHAVE_NS_GET_EXECUTABLE_PATH'
@@ -1538,7 +1546,9 @@ if get_option('runtime_prefix')
15381546 endif
15391547else
15401548 build_options_config.set(' RUNTIME_PREFIX' , ' false' )
1549+ git_exec_path = get_option (' prefix' ) / get_option (' libexecdir' ) / ' git-core'
15411550endif
1551+ libgit_c_args += ' -DGIT_EXEC_PATH="' + git_exec_path + ' "'
15421552
15431553git_version_file = custom_target (
15441554 command : [
@@ -1569,32 +1579,18 @@ version_def_h = custom_target(
15691579 depends : [git_version_file],
15701580 env : version_gen_environment,
15711581)
1572-
1573- # Build a separate library for "version.c" so that we do not have to rebuild
1574- # everything when the current Git commit changes.
1575- libgit_version_library = static_library (' git-version' ,
1576- sources : [
1577- ' version.c' ,
1578- version_def_h,
1579- ],
1580- c_args : libgit_c_args + [
1581- ' -DGIT_VERSION_H="' + version_def_h.full_path() + ' "' ,
1582- ],
1583- dependencies : libgit_dependencies,
1584- include_directories : libgit_include_directories,
1585- )
1586-
1587- libgit_library = static_library (' git' ,
1588- sources : libgit_sources,
1589- c_args : libgit_c_args,
1590- link_with : libgit_version_library,
1591- dependencies : libgit_dependencies,
1592- include_directories : libgit_include_directories,
1593- )
1582+ libgit_sources += version_def_h
15941583
15951584libgit = declare_dependency (
1585+ link_with : static_library (' git' ,
1586+ sources : libgit_sources,
1587+ c_args : libgit_c_args + [
1588+ ' -DGIT_VERSION_H="' + version_def_h.full_path() + ' "' ,
1589+ ],
1590+ dependencies : libgit_dependencies,
1591+ include_directories : libgit_include_directories,
1592+ ),
15961593 compile_args : libgit_c_args,
1597- link_with : libgit_library,
15981594 dependencies : libgit_dependencies,
15991595 include_directories : libgit_include_directories,
16001596)
@@ -1635,97 +1631,98 @@ if host_machine.system() == 'windows'
16351631 error (' Unsupported compiler ' + compiler.get_id())
16361632 endif
16371633endif
1638- common_main_library = static_library (' common-main' ,
1639- sources : common_main_sources,
1640- c_args : libgit_c_args,
1641- dependencies : libgit_dependencies,
1642- include_directories : libgit_include_directories,
1643- )
1644- common_main = declare_dependency (
1645- link_with : common_main_library,
1634+
1635+ libgit_commonmain = declare_dependency (
1636+ link_with : static_library (' common-main' ,
1637+ sources : common_main_sources,
1638+ dependencies : [ libgit ],
1639+ ),
16461640 link_args : common_main_link_args,
1641+ dependencies : [ libgit ],
16471642)
16481643
16491644bin_wrappers = [ ]
16501645test_dependencies = [ ]
16511646
1652- git = executable (' git' ,
1647+ git_builtin = executable (' git' ,
16531648 sources : builtin_sources + ' git.c' ,
1654- dependencies : [libgit, common_main ],
1649+ dependencies : [libgit_commonmain ],
16551650 install : true ,
16561651 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16571652)
1658- bin_wrappers += git
1653+ bin_wrappers += git_builtin
16591654
16601655test_dependencies += executable (' git-daemon' ,
16611656 sources : ' daemon.c' ,
1662- dependencies : [libgit, common_main ],
1657+ dependencies : [libgit_commonmain ],
16631658 install : true ,
16641659 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16651660)
16661661
16671662test_dependencies += executable (' git-sh-i18n--envsubst' ,
16681663 sources : ' sh-i18n--envsubst.c' ,
1669- dependencies : [libgit, common_main ],
1664+ dependencies : [libgit_commonmain ],
16701665 install : true ,
16711666 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16721667)
16731668
16741669bin_wrappers += executable (' git-shell' ,
16751670 sources : ' shell.c' ,
1676- dependencies : [libgit, common_main ],
1671+ dependencies : [libgit_commonmain ],
16771672 install : true ,
16781673 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16791674)
16801675
16811676test_dependencies += executable (' git-http-backend' ,
16821677 sources : ' http-backend.c' ,
1683- dependencies : [libgit, common_main ],
1678+ dependencies : [libgit_commonmain ],
16841679 install : true ,
16851680 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16861681)
16871682
16881683bin_wrappers += executable (' scalar' ,
16891684 sources : ' scalar.c' ,
1690- dependencies : [libgit, common_main ],
1685+ dependencies : [libgit_commonmain ],
16911686 install : true ,
16921687 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16931688)
16941689
16951690if get_option (' curl' ).enabled()
1696- curl_sources = [
1697- ' http.c' ,
1698- ' http-walker.c' ,
1699- ]
1691+ libgit_curl = declare_dependency (
1692+ sources : [
1693+ ' http.c' ,
1694+ ' http-walker.c' ,
1695+ ],
1696+ dependencies : [libgit_commonmain, curl],
1697+ )
17001698
1701- git_remote_http = executable (' git-remote-http' ,
1702- sources : curl_sources + ' remote-curl.c' ,
1703- dependencies : [libgit, common_main ],
1699+ test_dependencies + = executable (' git-remote-http' ,
1700+ sources : ' remote-curl.c' ,
1701+ dependencies : [libgit_curl ],
17041702 install : true ,
17051703 install_dir : get_option (' libexecdir' ) / ' git-core' ,
17061704 )
1707- test_dependencies += git_remote_http
17081705
17091706 test_dependencies += executable (' git-http-fetch' ,
1710- sources : curl_sources + ' http-fetch.c' ,
1711- dependencies : [libgit, common_main ],
1707+ sources : ' http-fetch.c' ,
1708+ dependencies : [libgit_curl ],
17121709 install : true ,
17131710 install_dir : get_option (' libexecdir' ) / ' git-core' ,
17141711 )
17151712
17161713 if expat.found()
17171714 test_dependencies += executable (' git-http-push' ,
1718- sources : curl_sources + ' http-push.c' ,
1719- dependencies : [libgit, common_main ],
1715+ sources : ' http-push.c' ,
1716+ dependencies : [libgit_curl ],
17201717 install : true ,
17211718 install_dir : get_option (' libexecdir' ) / ' git-core' ,
17221719 )
17231720 endif
17241721
17251722 foreach alias : [ ' git-remote-https' , ' git-remote-ftp' , ' git-remote-ftps' ]
17261723 test_dependencies += executable (alias,
1727- objects : git_remote_http.extract_all_objects( recursive : false ) ,
1728- dependencies : [libgit, common_main ],
1724+ sources : ' remote-curl.c ' ,
1725+ dependencies : [libgit_curl ],
17291726 )
17301727
17311728 install_symlink(alias + executable_suffix,
@@ -1735,22 +1732,17 @@ if get_option('curl').enabled()
17351732 endforeach
17361733endif
17371734
1738- imap_send_sources = [' imap-send.c' ]
1739- if use_curl_for_imap_send
1740- imap_send_sources += curl_sources
1741- endif
1742-
17431735test_dependencies += executable (' git-imap-send' ,
1744- sources : imap_send_sources ,
1745- dependencies : [libgit, common_main ],
1736+ sources : ' imap-send.c ' ,
1737+ dependencies : [ use_curl_for_imap_send ? libgit_curl : libgit_commonmain ],
17461738 install : true ,
17471739 install_dir : get_option (' libexecdir' ) / ' git-core' ,
17481740)
17491741
17501742foreach alias : [ ' git-receive-pack' , ' git-upload-archive' , ' git-upload-pack' ]
17511743 bin_wrappers += executable (alias,
1752- objects : git .extract_all_objects(recursive : false ),
1753- dependencies : [libgit, common_main ],
1744+ objects : git_builtin .extract_all_objects(recursive : false ),
1745+ dependencies : [libgit_commonmain ],
17541746 )
17551747
17561748 install_symlink(alias + executable_suffix,
0 commit comments