@@ -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' ) + ' "' ,
@@ -949,7 +949,9 @@ if curl.found()
949949 use_curl_for_imap_send = true
950950 endif
951951
952- libgit_dependencies += curl
952+ # Most executables don't have to link against libcurl, but we still need its
953+ # include directories so that we can resolve LIBCURL_VERSION in "help.c".
954+ libgit_dependencies += curl.partial_dependency(includes : true )
953955 libgit_c_args += ' -DCURL_DISABLE_TYPECHECK'
954956 build_options_config.set(' NO_CURL' , '' )
955957else
@@ -1376,7 +1378,11 @@ if https_backend == 'auto' and security_framework.found()
13761378endif
13771379
13781380openssl_required = ' openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1379- openssl = dependency (' openssl' , required : openssl_required, default_options : [' default_library=static' ])
1381+ openssl = dependency (' openssl' ,
1382+ required : openssl_required,
1383+ allow_fallback : openssl_required or https_backend == ' auto' ,
1384+ default_options : [' default_library=static' ],
1385+ )
13801386if https_backend == ' auto' and openssl.found()
13811387 https_backend = ' openssl'
13821388endif
@@ -1390,6 +1396,7 @@ elif https_backend == 'openssl'
13901396else
13911397 # We either couldn't find any dependencies with 'auto' or the user requested
13921398 # 'none'. Both cases are benign.
1399+ https_backend = ' none'
13931400endif
13941401
13951402if https_backend != ' openssl'
@@ -1489,6 +1496,7 @@ endif
14891496if get_option (' runtime_prefix' )
14901497 libgit_c_args += ' -DRUNTIME_PREFIX'
14911498 build_options_config.set(' RUNTIME_PREFIX' , ' true' )
1499+ git_exec_path = get_option (' libexecdir' ) / ' git-core'
14921500
14931501 if compiler.has_header(' mach-o/dyld.h' )
14941502 libgit_c_args += ' -DHAVE_NS_GET_EXECUTABLE_PATH'
@@ -1525,7 +1533,9 @@ if get_option('runtime_prefix')
15251533 endif
15261534else
15271535 build_options_config.set(' RUNTIME_PREFIX' , ' false' )
1536+ git_exec_path = get_option (' prefix' ) / get_option (' libexecdir' ) / ' git-core'
15281537endif
1538+ libgit_c_args += ' -DGIT_EXEC_PATH="' + git_exec_path + ' "'
15291539
15301540git_version_file = custom_target (
15311541 command : [
@@ -1556,32 +1566,18 @@ version_def_h = custom_target(
15561566 depends : [git_version_file],
15571567 env : version_gen_environment,
15581568)
1559-
1560- # Build a separate library for "version.c" so that we do not have to rebuild
1561- # everything when the current Git commit changes.
1562- libgit_version_library = static_library (' git-version' ,
1563- sources : [
1564- ' version.c' ,
1565- version_def_h,
1566- ],
1567- c_args : libgit_c_args + [
1568- ' -DGIT_VERSION_H="' + version_def_h.full_path() + ' "' ,
1569- ],
1570- dependencies : libgit_dependencies,
1571- include_directories : libgit_include_directories,
1572- )
1573-
1574- libgit_library = static_library (' git' ,
1575- sources : libgit_sources,
1576- c_args : libgit_c_args,
1577- link_with : libgit_version_library,
1578- dependencies : libgit_dependencies,
1579- include_directories : libgit_include_directories,
1580- )
1569+ libgit_sources += version_def_h
15811570
15821571libgit = declare_dependency (
1572+ link_with : static_library (' git' ,
1573+ sources : libgit_sources,
1574+ c_args : libgit_c_args + [
1575+ ' -DGIT_VERSION_H="' + version_def_h.full_path() + ' "' ,
1576+ ],
1577+ dependencies : libgit_dependencies,
1578+ include_directories : libgit_include_directories,
1579+ ),
15831580 compile_args : libgit_c_args,
1584- link_with : libgit_library,
15851581 dependencies : libgit_dependencies,
15861582 include_directories : libgit_include_directories,
15871583)
@@ -1622,97 +1618,95 @@ if host_machine.system() == 'windows'
16221618 error (' Unsupported compiler ' + compiler.get_id())
16231619 endif
16241620endif
1625- common_main_library = static_library (' common-main' ,
1621+
1622+ libgit_commonmain = declare_dependency (
16261623 sources : common_main_sources,
1627- c_args : libgit_c_args,
1628- dependencies : libgit_dependencies,
1629- include_directories : libgit_include_directories,
1630- )
1631- common_main = declare_dependency (
1632- link_with : common_main_library,
16331624 link_args : common_main_link_args,
1625+ dependencies : [ libgit ],
16341626)
16351627
16361628bin_wrappers = [ ]
16371629test_dependencies = [ ]
16381630
1639- git = executable (' git' ,
1631+ git_builtin = executable (' git' ,
16401632 sources : builtin_sources + ' git.c' ,
1641- dependencies : [libgit, common_main ],
1633+ dependencies : [libgit_commonmain ],
16421634 install : true ,
16431635 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16441636)
1645- bin_wrappers += git
1637+ bin_wrappers += git_builtin
16461638
16471639test_dependencies += executable (' git-daemon' ,
16481640 sources : ' daemon.c' ,
1649- dependencies : [libgit, common_main ],
1641+ dependencies : [libgit_commonmain ],
16501642 install : true ,
16511643 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16521644)
16531645
16541646test_dependencies += executable (' git-sh-i18n--envsubst' ,
16551647 sources : ' sh-i18n--envsubst.c' ,
1656- dependencies : [libgit, common_main ],
1648+ dependencies : [libgit_commonmain ],
16571649 install : true ,
16581650 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16591651)
16601652
16611653bin_wrappers += executable (' git-shell' ,
16621654 sources : ' shell.c' ,
1663- dependencies : [libgit, common_main ],
1655+ dependencies : [libgit_commonmain ],
16641656 install : true ,
16651657 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16661658)
16671659
16681660test_dependencies += executable (' git-http-backend' ,
16691661 sources : ' http-backend.c' ,
1670- dependencies : [libgit, common_main ],
1662+ dependencies : [libgit_commonmain ],
16711663 install : true ,
16721664 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16731665)
16741666
16751667bin_wrappers += executable (' scalar' ,
16761668 sources : ' scalar.c' ,
1677- dependencies : [libgit, common_main ],
1669+ dependencies : [libgit_commonmain ],
16781670 install : true ,
16791671 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16801672)
16811673
16821674if get_option (' curl' ).enabled()
1683- curl_sources = [
1684- ' http.c' ,
1685- ' http-walker.c' ,
1686- ]
1675+ libgit_curl = declare_dependency (
1676+ sources : [
1677+ ' http.c' ,
1678+ ' http-walker.c' ,
1679+ ],
1680+ dependencies : [libgit_commonmain, curl],
1681+ )
16871682
1688- git_remote_http = executable (' git-remote-http' ,
1689- sources : curl_sources + ' remote-curl.c' ,
1690- dependencies : [libgit, common_main ],
1683+ test_dependencies + = executable (' git-remote-http' ,
1684+ sources : ' remote-curl.c' ,
1685+ dependencies : [libgit_curl ],
16911686 install : true ,
16921687 install_dir : get_option (' libexecdir' ) / ' git-core' ,
16931688 )
1694- test_dependencies += git_remote_http
16951689
16961690 test_dependencies += executable (' git-http-fetch' ,
1697- sources : curl_sources + ' http-fetch.c' ,
1698- dependencies : [libgit, common_main ],
1691+ sources : ' http-fetch.c' ,
1692+ dependencies : [libgit_curl ],
16991693 install : true ,
17001694 install_dir : get_option (' libexecdir' ) / ' git-core' ,
17011695 )
17021696
17031697 if expat.found()
17041698 test_dependencies += executable (' git-http-push' ,
1705- sources : curl_sources + ' http-push.c' ,
1706- dependencies : [libgit, common_main ],
1699+ sources : ' http-push.c' ,
1700+ dependencies : [libgit_curl ],
17071701 install : true ,
17081702 install_dir : get_option (' libexecdir' ) / ' git-core' ,
17091703 )
17101704 endif
17111705
17121706 foreach alias : [ ' git-remote-https' , ' git-remote-ftp' , ' git-remote-ftps' ]
17131707 test_dependencies += executable (alias,
1714- objects : git_remote_http.extract_all_objects( recursive : false ) ,
1715- dependencies : [libgit, common_main ],
1708+ sources : ' remote-curl.c ' ,
1709+ dependencies : [libgit_curl ],
17161710 )
17171711
17181712 install_symlink(alias + executable_suffix,
@@ -1722,22 +1716,17 @@ if get_option('curl').enabled()
17221716 endforeach
17231717endif
17241718
1725- imap_send_sources = [' imap-send.c' ]
1726- if use_curl_for_imap_send
1727- imap_send_sources += curl_sources
1728- endif
1729-
17301719test_dependencies += executable (' git-imap-send' ,
1731- sources : imap_send_sources ,
1732- dependencies : [libgit, common_main ],
1720+ sources : ' imap-send.c ' ,
1721+ dependencies : [ use_curl_for_imap_send ? libgit_curl : libgit_commonmain ],
17331722 install : true ,
17341723 install_dir : get_option (' libexecdir' ) / ' git-core' ,
17351724)
17361725
17371726foreach alias : [ ' git-receive-pack' , ' git-upload-archive' , ' git-upload-pack' ]
17381727 bin_wrappers += executable (alias,
1739- objects : git .extract_all_objects(recursive : false ),
1740- dependencies : [libgit, common_main ],
1728+ objects : git_builtin .extract_all_objects(recursive : false ),
1729+ dependencies : [libgit],
17411730 )
17421731
17431732 install_symlink(alias + executable_suffix,
0 commit comments