Makefileon commit Makefile: detect compiler and enable more warnings in DEVELOPER=1 (1da1580)
   1# The default target of this Makefile is...
   2all::
   3
   4# Define V=1 to have a more verbose compile.
   5#
   6# Define SHELL_PATH to a POSIX shell if your /bin/sh is broken.
   7#
   8# Define SANE_TOOL_PATH to a colon-separated list of paths to prepend
   9# to PATH if your tools in /usr/bin are broken.
  10#
  11# Define SOCKLEN_T to a suitable type (such as 'size_t') if your
  12# system headers do not define a socklen_t type.
  13#
  14# Define INLINE to a suitable substitute (such as '__inline' or '') if git
  15# fails to compile with errors about undefined inline functions or similar.
  16#
  17# Define SNPRINTF_RETURNS_BOGUS if you are on a system which snprintf()
  18# or vsnprintf() return -1 instead of number of characters which would
  19# have been written to the final string if enough space had been available.
  20#
  21# Define FREAD_READS_DIRECTORIES if you are on a system which succeeds
  22# when attempting to read from an fopen'ed directory (or even to fopen
  23# it at all).
  24#
  25# Define NO_OPENSSL environment variable if you do not have OpenSSL.
  26#
  27# Define USE_LIBPCRE if you have and want to use libpcre. Various
  28# commands such as log and grep offer runtime options to use
  29# Perl-compatible regular expressions instead of standard or extended
  30# POSIX regular expressions.
  31#
  32# Currently USE_LIBPCRE is a synonym for USE_LIBPCRE1, define
  33# USE_LIBPCRE2 instead if you'd like to use version 2 of the PCRE
  34# library. The USE_LIBPCRE flag will likely be changed to mean v2 by
  35# default in future releases.
  36#
  37# When using USE_LIBPCRE1, define NO_LIBPCRE1_JIT if the PCRE v1
  38# library is compiled without --enable-jit. We will auto-detect
  39# whether the version of the PCRE v1 library in use has JIT support at
  40# all, but we unfortunately can't auto-detect whether JIT support
  41# hasn't been compiled in in an otherwise JIT-supporting version. If
  42# you have link-time errors about a missing `pcre_jit_exec` define
  43# this, or recompile PCRE v1 with --enable-jit.
  44#
  45# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
  46# in /foo/bar/include and /foo/bar/lib directories. Which version of
  47# PCRE this points to determined by the USE_LIBPCRE1 and USE_LIBPCRE2
  48# variables.
  49#
  50# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
  51#
  52# Define NO_CURL if you do not have libcurl installed.  git-http-fetch and
  53# git-http-push are not built, and you cannot use http:// and https://
  54# transports (neither smart nor dumb).
  55#
  56# Define CURLDIR=/foo/bar if your curl header and library files are in
  57# /foo/bar/include and /foo/bar/lib directories.
  58#
  59# Define CURL_CONFIG to curl's configuration program that prints information
  60# about the library (e.g., its version number).  The default is 'curl-config'.
  61#
  62# Define NO_EXPAT if you do not have expat installed.  git-http-push is
  63# not built, and you cannot push using http:// and https:// transports (dumb).
  64#
  65# Define EXPATDIR=/foo/bar if your expat header and library files are in
  66# /foo/bar/include and /foo/bar/lib directories.
  67#
  68# Define EXPAT_NEEDS_XMLPARSE_H if you have an old version of expat (e.g.,
  69# 1.1 or 1.2) that provides xmlparse.h instead of expat.h.
  70#
  71# Define NO_GETTEXT if you don't want Git output to be translated.
  72# A translated Git requires GNU libintl or another gettext implementation,
  73# plus libintl-perl at runtime.
  74#
  75# Define USE_GETTEXT_SCHEME and set it to 'fallthrough', if you don't trust
  76# the installed gettext translation of the shell scripts output.
  77#
  78# Define HAVE_LIBCHARSET_H if you haven't set NO_GETTEXT and you can't
  79# trust the langinfo.h's nl_langinfo(CODESET) function to return the
  80# current character set. GNU and Solaris have a nl_langinfo(CODESET),
  81# FreeBSD can use either, but MinGW and some others need to use
  82# libcharset.h's locale_charset() instead.
  83#
  84# Define CHARSET_LIB to the library you need to link with in order to
  85# use locale_charset() function.  On some platforms this needs to set to
  86# -lcharset, on others to -liconv .
  87#
  88# Define LIBC_CONTAINS_LIBINTL if your gettext implementation doesn't
  89# need -lintl when linking.
  90#
  91# Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
  92# doesn't support GNU extensions like --check and --statistics
  93#
  94# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
  95# it specifies.
  96#
  97# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
  98# d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
  99#
 100# Define HAVE_STRINGS_H if you have strings.h and need it for strcasecmp.
 101#
 102# Define NO_STRCASESTR if you don't have strcasestr.
 103#
 104# Define NO_MEMMEM if you don't have memmem.
 105#
 106# Define NO_GETPAGESIZE if you don't have getpagesize.
 107#
 108# Define NO_STRLCPY if you don't have strlcpy.
 109#
 110# Define NO_STRTOUMAX if you don't have both strtoimax and strtoumax in the
 111# C library. If your compiler also does not support long long or does not have
 112# strtoull, define NO_STRTOULL.
 113#
 114# Define NO_SETENV if you don't have setenv in the C library.
 115#
 116# Define NO_UNSETENV if you don't have unsetenv in the C library.
 117#
 118# Define NO_MKDTEMP if you don't have mkdtemp in the C library.
 119#
 120# Define MKDIR_WO_TRAILING_SLASH if your mkdir() can't deal with trailing slash.
 121#
 122# Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
 123# in the C library.
 124#
 125# Define NO_LIBGEN_H if you don't have libgen.h.
 126#
 127# Define NEEDS_LIBGEN if your libgen needs -lgen when linking
 128#
 129# Define NO_SYS_SELECT_H if you don't have sys/select.h.
 130#
 131# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
 132# Enable it on Windows.  By default, symrefs are still used.
 133#
 134# Define NO_SVN_TESTS if you want to skip time-consuming SVN interoperability
 135# tests.  These tests take up a significant amount of the total test time
 136# but are not needed unless you plan to talk to SVN repos.
 137#
 138# Define NO_FINK if you are building on Darwin/Mac OS X, have Fink
 139# installed in /sw, but don't want GIT to link against any libraries
 140# installed there.  If defined you may specify your own (or Fink's)
 141# include directories and library directories by defining CFLAGS
 142# and LDFLAGS appropriately.
 143#
 144# Define NO_DARWIN_PORTS if you are building on Darwin/Mac OS X,
 145# have DarwinPorts installed in /opt/local, but don't want GIT to
 146# link against any libraries installed there.  If defined you may
 147# specify your own (or DarwinPort's) include directories and
 148# library directories by defining CFLAGS and LDFLAGS appropriately.
 149#
 150# Define NO_APPLE_COMMON_CRYPTO if you are building on Darwin/Mac OS X
 151# and do not want to use Apple's CommonCrypto library.  This allows you
 152# to provide your own OpenSSL library, for example from MacPorts.
 153#
 154# Define BLK_SHA1 environment variable to make use of the bundled
 155# optimized C SHA1 routine.
 156#
 157# Define PPC_SHA1 environment variable when running make to make use of
 158# a bundled SHA1 routine optimized for PowerPC.
 159#
 160# Define DC_SHA1 to unconditionally enable the collision-detecting sha1
 161# algorithm. This is slower, but may detect attempted collision attacks.
 162# Takes priority over other *_SHA1 knobs.
 163#
 164# Define DC_SHA1_EXTERNAL in addition to DC_SHA1 if you want to build / link
 165# git with the external SHA1 collision-detect library.
 166# Without this option, i.e. the default behavior is to build git with its
 167# own built-in code (or submodule).
 168#
 169# Define DC_SHA1_SUBMODULE in addition to DC_SHA1 to use the
 170# sha1collisiondetection shipped as a submodule instead of the
 171# non-submodule copy in sha1dc/. This is an experimental option used
 172# by the git project to migrate to using sha1collisiondetection as a
 173# submodule.
 174#
 175# Define OPENSSL_SHA1 environment variable when running make to link
 176# with the SHA1 routine from openssl library.
 177#
 178# Define SHA1_MAX_BLOCK_SIZE to limit the amount of data that will be hashed
 179# in one call to the platform's SHA1_Update(). e.g. APPLE_COMMON_CRYPTO
 180# wants 'SHA1_MAX_BLOCK_SIZE=1024L*1024L*1024L' defined.
 181#
 182# Define NEEDS_CRYPTO_WITH_SSL if you need -lcrypto when using -lssl (Darwin).
 183#
 184# Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
 185#
 186# Define NEEDS_SSL_WITH_CURL if you need -lssl with -lcurl (Minix).
 187#
 188# Define NEEDS_IDN_WITH_CURL if you need -lidn when using -lcurl (Minix).
 189#
 190# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
 191#
 192# Define NEEDS_LIBINTL_BEFORE_LIBICONV if you need libintl before libiconv.
 193#
 194# Define NO_INTPTR_T if you don't have intptr_t or uintptr_t.
 195#
 196# Define NO_UINTMAX_T if you don't have uintmax_t.
 197#
 198# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
 199# Patrick Mauritz).
 200#
 201# Define NEEDS_RESOLV if linking with -lnsl and/or -lsocket is not enough.
 202# Notably on Solaris hstrerror resides in libresolv and on Solaris 7
 203# inet_ntop and inet_pton additionally reside there.
 204#
 205# Define NO_MMAP if you want to avoid mmap.
 206#
 207# Define MMAP_PREVENTS_DELETE if a file that is currently mmapped cannot be
 208# deleted or cannot be replaced using rename().
 209#
 210# Define NO_SYS_POLL_H if you don't have sys/poll.h.
 211#
 212# Define NO_POLL if you do not have or don't want to use poll().
 213# This also implies NO_SYS_POLL_H.
 214#
 215# Define NEEDS_SYS_PARAM_H if you need to include sys/param.h to compile,
 216# *PLEASE* REPORT to git@vger.kernel.org if your platform needs this;
 217# we want to know more about the issue.
 218#
 219# Define NO_PTHREADS if you do not have or do not want to use Pthreads.
 220#
 221# Define NO_PREAD if you have a problem with pread() system call (e.g.
 222# cygwin1.dll before v1.5.22).
 223#
 224# Define NO_SETITIMER if you don't have setitimer()
 225#
 226# Define NO_STRUCT_ITIMERVAL if you don't have struct itimerval
 227# This also implies NO_SETITIMER
 228#
 229# Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is
 230# generally faster on your platform than accessing the working directory.
 231#
 232# Define NO_TRUSTABLE_FILEMODE if your filesystem may claim to support
 233# the executable mode bit, but doesn't really do so.
 234#
 235# Define NEEDS_MODE_TRANSLATION if your OS strays from the typical file type
 236# bits in mode values (e.g. z/OS defines I_SFMT to 0xFF000000 as opposed to the
 237# usual 0xF000).
 238#
 239# Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
 240#
 241# Define NO_UNIX_SOCKETS if your system does not offer unix sockets.
 242#
 243# Define NO_SOCKADDR_STORAGE if your platform does not have struct
 244# sockaddr_storage.
 245#
 246# Define NO_ICONV if your libc does not properly support iconv.
 247#
 248# Define OLD_ICONV if your library has an old iconv(), where the second
 249# (input buffer pointer) parameter is declared with type (const char **).
 250#
 251# Define NO_DEFLATE_BOUND if your zlib does not have deflateBound.
 252#
 253# Define NO_R_TO_GCC_LINKER if your gcc does not like "-R/path/lib"
 254# that tells runtime paths to dynamic libraries;
 255# "-Wl,-rpath=/path/lib" is used instead.
 256#
 257# Define NO_NORETURN if using buggy versions of gcc 4.6+ and profile feedback,
 258# as the compiler can crash (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49299)
 259#
 260# Define USE_NSEC below if you want git to care about sub-second file mtimes
 261# and ctimes. Note that you need recent glibc (at least 2.2.4) for this. On
 262# Linux, kernel 2.6.11 or newer is required for reliable sub-second file times
 263# on file systems with exactly 1 ns or 1 s resolution. If you intend to use Git
 264# on other file systems (e.g. CEPH, CIFS, NTFS, UDF), don't enable USE_NSEC. See
 265# Documentation/technical/racy-git.txt for details.
 266#
 267# Define USE_ST_TIMESPEC if your "struct stat" uses "st_ctimespec" instead of
 268# "st_ctim"
 269#
 270# Define NO_NSEC if your "struct stat" does not have "st_ctim.tv_nsec"
 271# available.  This automatically turns USE_NSEC off.
 272#
 273# Define USE_STDEV below if you want git to care about the underlying device
 274# change being considered an inode change from the update-index perspective.
 275#
 276# Define NO_ST_BLOCKS_IN_STRUCT_STAT if your platform does not have st_blocks
 277# field that counts the on-disk footprint in 512-byte blocks.
 278#
 279# Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72
 280# (not v1.73 or v1.71).
 281#
 282# Define ASCIIDOC_ROFF if your DocBook XSL does not escape raw roff directives
 283# (versions 1.68.1 through v1.72).
 284#
 285# Define GNU_ROFF if your target system uses GNU groff.  This forces
 286# apostrophes to be ASCII so that cut&pasting examples to the shell
 287# will work.
 288#
 289# Define USE_ASCIIDOCTOR to use Asciidoctor instead of AsciiDoc to build the
 290# documentation.
 291#
 292# Define ASCIIDOCTOR_EXTENSIONS_LAB to point to the location of the Asciidoctor
 293# Extensions Lab if you have it available.
 294#
 295# Define PERL_PATH to the path of your Perl binary (usually /usr/bin/perl).
 296#
 297# Define NO_PERL_MAKEMAKER if you cannot use Makefiles generated by perl's
 298# MakeMaker (e.g. using ActiveState under Cygwin).
 299#
 300# Define NO_PERL if you do not want Perl scripts or libraries at all.
 301#
 302# Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
 303# but /usr/bin/python2.7 on some platforms).
 304#
 305# Define NO_PYTHON if you do not want Python scripts or libraries at all.
 306#
 307# Define NO_TCLTK if you do not want Tcl/Tk GUI.
 308#
 309# Define SANE_TEXT_GREP to "-a" if you use recent versions of GNU grep
 310# and egrep that are pickier when their input contains non-ASCII data.
 311#
 312# The TCL_PATH variable governs the location of the Tcl interpreter
 313# used to optimize git-gui for your system.  Only used if NO_TCLTK
 314# is not set.  Defaults to the bare 'tclsh'.
 315#
 316# The TCLTK_PATH variable governs the location of the Tcl/Tk interpreter.
 317# If not set it defaults to the bare 'wish'. If it is set to the empty
 318# string then NO_TCLTK will be forced (this is used by configure script).
 319#
 320# Define INTERNAL_QSORT to use Git's implementation of qsort(), which
 321# is a simplified version of the merge sort used in glibc. This is
 322# recommended if Git triggers O(n^2) behavior in your platform's qsort().
 323#
 324# Define HAVE_ISO_QSORT_S if your platform provides a qsort_s() that's
 325# compatible with the one described in C11 Annex K.
 326#
 327# Define UNRELIABLE_FSTAT if your system's fstat does not return the same
 328# information on a not yet closed file that lstat would return for the same
 329# file after it was closed.
 330#
 331# Define OBJECT_CREATION_USES_RENAMES if your operating systems has problems
 332# when hardlinking a file to another name and unlinking the original file right
 333# away (some NTFS drivers seem to zero the contents in that scenario).
 334#
 335# Define NO_CROSS_DIRECTORY_HARDLINKS if you plan to distribute the installed
 336# programs as a tar, where bin/ and libexec/ might be on different file systems.
 337#
 338# Define NO_INSTALL_HARDLINKS if you prefer to use either symbolic links or
 339# copies to install built-in git commands e.g. git-cat-file.
 340#
 341# Define USE_NED_ALLOCATOR if you want to replace the platforms default
 342# memory allocators with the nedmalloc allocator written by Niall Douglas.
 343#
 344# Define OVERRIDE_STRDUP to override the libc version of strdup(3).
 345# This is necessary when using a custom allocator in order to avoid
 346# crashes due to allocation and free working on different 'heaps'.
 347# It's defined automatically if USE_NED_ALLOCATOR is set.
 348#
 349# Define NO_REGEX if your C library lacks regex support with REG_STARTEND
 350# feature.
 351#
 352# Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
 353# user.
 354#
 355# Define GETTEXT_POISON if you are debugging the choice of strings marked
 356# for translation.  In a GETTEXT_POISON build, you can turn all strings marked
 357# for translation into gibberish by setting the GIT_GETTEXT_POISON variable
 358# (to any value) in your environment.
 359#
 360# Define JSMIN to point to JavaScript minifier that functions as
 361# a filter to have gitweb.js minified.
 362#
 363# Define CSSMIN to point to a CSS minifier in order to generate a minified
 364# version of gitweb.css
 365#
 366# Define DEFAULT_PAGER to a sensible pager command (defaults to "less") if
 367# you want to use something different.  The value will be interpreted by the
 368# shell at runtime when it is used.
 369#
 370# Define DEFAULT_EDITOR to a sensible editor command (defaults to "vi") if you
 371# want to use something different.  The value will be interpreted by the shell
 372# if necessary when it is used.  Examples:
 373#
 374#   DEFAULT_EDITOR='~/bin/vi',
 375#   DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',
 376#   DEFAULT_EDITOR='"C:\Program Files\Vim\gvim.exe" --nofork'
 377#
 378# Define COMPUTE_HEADER_DEPENDENCIES to "yes" if you want dependencies on
 379# header files to be automatically computed, to avoid rebuilding objects when
 380# an unrelated header file changes.  Define it to "no" to use the hard-coded
 381# dependency rules.  The default is "auto", which means to use computed header
 382# dependencies if your compiler is detected to support it.
 383#
 384# Define NATIVE_CRLF if your platform uses CRLF for line endings.
 385#
 386# Define GIT_USER_AGENT if you want to change how git identifies itself during
 387# network interactions.  The default is "git/$(GIT_VERSION)".
 388#
 389# Define DEFAULT_HELP_FORMAT to "man", "info" or "html"
 390# (defaults to "man") if you want to have a different default when
 391# "git help" is called without a parameter specifying the format.
 392#
 393# Define TEST_GIT_INDEX_VERSION to 2, 3 or 4 to run the test suite
 394# with a different indexfile format version.  If it isn't set the index
 395# file format used is index-v[23].
 396#
 397# Define GMTIME_UNRELIABLE_ERRORS if your gmtime() function does not
 398# return NULL when it receives a bogus time_t.
 399#
 400# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime.
 401#
 402# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC.
 403#
 404# Define NEEDS_LIBRT if your platform requires linking with librt (glibc version
 405# before 2.17) for clock_gettime and CLOCK_MONOTONIC.
 406#
 407# Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily
 408# compiles the following initialization:
 409#
 410#   static const char s[] = ("FOO");
 411#
 412# and define it to "no" if you need to remove the parentheses () around the
 413# constant.  The default is "auto", which means to use parentheses if your
 414# compiler is detected to support it.
 415#
 416# Define HAVE_BSD_SYSCTL if your platform has a BSD-compatible sysctl function.
 417#
 418# Define HAVE_GETDELIM if your system has the getdelim() function.
 419#
 420# Define PAGER_ENV to a SP separated VAR=VAL pairs to define
 421# default environment variables to be passed when a pager is spawned, e.g.
 422#
 423#    PAGER_ENV = LESS=FRX LV=-c
 424#
 425# to say "export LESS=FRX (and LV=-c) if the environment variable
 426# LESS (and LV) is not set, respectively".
 427#
 428# Define TEST_SHELL_PATH if you want to use a shell besides SHELL_PATH for
 429# running the test scripts (e.g., bash has better support for "set -x"
 430# tracing).
 431#
 432# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
 433# which the built Git will run (for instance "x86_64").
 434#
 435# Define DEVELOPER to enable more compiler warnings. Compiler version
 436# and family are auto detected, but could be overridden by defining
 437# COMPILER_FEATURES (see config.mak.dev)
 438
 439GIT-VERSION-FILE: FORCE
 440        @$(SHELL_PATH) ./GIT-VERSION-GEN
 441-include GIT-VERSION-FILE
 442
 443# CFLAGS and LDFLAGS are for the users to override from the command line.
 444
 445CFLAGS = -g -O2 -Wall
 446LDFLAGS =
 447ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
 448ALL_LDFLAGS = $(LDFLAGS)
 449STRIP ?= strip
 450
 451# Create as necessary, replace existing, make ranlib unneeded.
 452ARFLAGS = rcs
 453
 454# Among the variables below, these:
 455#   gitexecdir
 456#   template_dir
 457#   sysconfdir
 458# can be specified as a relative path some/where/else;
 459# this is interpreted as relative to $(prefix) and "git" at
 460# runtime figures out where they are based on the path to the executable.
 461# Additionally, the following will be treated as relative by "git" if they
 462# begin with "$(prefix)/":
 463#   mandir
 464#   infodir
 465#   htmldir
 466# This can help installing the suite in a relocatable way.
 467
 468prefix = $(HOME)
 469bindir_relative = bin
 470bindir = $(prefix)/$(bindir_relative)
 471mandir = $(prefix)/share/man
 472infodir = $(prefix)/share/info
 473gitexecdir = libexec/git-core
 474mergetoolsdir = $(gitexecdir)/mergetools
 475sharedir = $(prefix)/share
 476gitwebdir = $(sharedir)/gitweb
 477localedir = $(sharedir)/locale
 478template_dir = share/git-core/templates
 479htmldir = $(prefix)/share/doc/git-doc
 480ETC_GITCONFIG = $(sysconfdir)/gitconfig
 481ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
 482lib = lib
 483# DESTDIR =
 484pathsep = :
 485
 486mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
 487infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
 488htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
 489
 490export prefix bindir sharedir sysconfdir gitwebdir localedir
 491
 492CC = cc
 493AR = ar
 494RM = rm -f
 495DIFF = diff
 496TAR = tar
 497FIND = find
 498INSTALL = install
 499TCL_PATH = tclsh
 500TCLTK_PATH = wish
 501XGETTEXT = xgettext
 502MSGFMT = msgfmt
 503CURL_CONFIG = curl-config
 504PTHREAD_LIBS = -lpthread
 505PTHREAD_CFLAGS =
 506GCOV = gcov
 507SPATCH = spatch
 508
 509export TCL_PATH TCLTK_PATH
 510
 511SPARSE_FLAGS =
 512SPATCH_FLAGS = --all-includes
 513
 514
 515
 516### --- END CONFIGURATION SECTION ---
 517
 518# Those must not be GNU-specific; they are shared with perl/ which may
 519# be built by a different compiler. (Note that this is an artifact now
 520# but it still might be nice to keep that distinction.)
 521BASIC_CFLAGS = -I.
 522BASIC_LDFLAGS =
 523
 524# Guard against environment variables
 525BUILTIN_OBJS =
 526BUILT_INS =
 527COMPAT_CFLAGS =
 528COMPAT_OBJS =
 529XDIFF_OBJS =
 530VCSSVN_OBJS =
 531GENERATED_H =
 532EXTRA_CPPFLAGS =
 533LIB_OBJS =
 534PROGRAM_OBJS =
 535PROGRAMS =
 536SCRIPT_PERL =
 537SCRIPT_PYTHON =
 538SCRIPT_SH =
 539SCRIPT_LIB =
 540TEST_PROGRAMS_NEED_X =
 541
 542# Having this variable in your environment would break pipelines because
 543# you cause "cd" to echo its destination to stdout.  It can also take
 544# scripts to unexpected places.  If you like CDPATH, define it for your
 545# interactive shell sessions without exporting it.
 546unexport CDPATH
 547
 548SCRIPT_SH += git-bisect.sh
 549SCRIPT_SH += git-difftool--helper.sh
 550SCRIPT_SH += git-filter-branch.sh
 551SCRIPT_SH += git-merge-octopus.sh
 552SCRIPT_SH += git-merge-one-file.sh
 553SCRIPT_SH += git-merge-resolve.sh
 554SCRIPT_SH += git-mergetool.sh
 555SCRIPT_SH += git-quiltimport.sh
 556SCRIPT_SH += git-rebase.sh
 557SCRIPT_SH += git-remote-testgit.sh
 558SCRIPT_SH += git-request-pull.sh
 559SCRIPT_SH += git-stash.sh
 560SCRIPT_SH += git-submodule.sh
 561SCRIPT_SH += git-web--browse.sh
 562
 563SCRIPT_LIB += git-mergetool--lib
 564SCRIPT_LIB += git-parse-remote
 565SCRIPT_LIB += git-rebase--am
 566SCRIPT_LIB += git-rebase--interactive
 567SCRIPT_LIB += git-rebase--merge
 568SCRIPT_LIB += git-sh-setup
 569SCRIPT_LIB += git-sh-i18n
 570
 571SCRIPT_PERL += git-add--interactive.perl
 572SCRIPT_PERL += git-archimport.perl
 573SCRIPT_PERL += git-cvsexportcommit.perl
 574SCRIPT_PERL += git-cvsimport.perl
 575SCRIPT_PERL += git-cvsserver.perl
 576SCRIPT_PERL += git-send-email.perl
 577SCRIPT_PERL += git-svn.perl
 578
 579SCRIPT_PYTHON += git-p4.py
 580
 581NO_INSTALL += git-remote-testgit
 582
 583# Generated files for scripts
 584SCRIPT_SH_GEN = $(patsubst %.sh,%,$(SCRIPT_SH))
 585SCRIPT_PERL_GEN = $(patsubst %.perl,%,$(SCRIPT_PERL))
 586SCRIPT_PYTHON_GEN = $(patsubst %.py,%,$(SCRIPT_PYTHON))
 587
 588SCRIPT_SH_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_SH_GEN))
 589SCRIPT_PERL_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PERL_GEN))
 590SCRIPT_PYTHON_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PYTHON_GEN))
 591
 592# Individual rules to allow e.g.
 593# "make -C ../.. SCRIPT_PERL=contrib/foo/bar.perl build-perl-script"
 594# from subdirectories like contrib/*/
 595.PHONY: build-perl-script build-sh-script build-python-script
 596build-perl-script: $(SCRIPT_PERL_GEN)
 597build-sh-script: $(SCRIPT_SH_GEN)
 598build-python-script: $(SCRIPT_PYTHON_GEN)
 599
 600.PHONY: install-perl-script install-sh-script install-python-script
 601install-sh-script: $(SCRIPT_SH_INS)
 602        $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 603install-perl-script: $(SCRIPT_PERL_INS)
 604        $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 605install-python-script: $(SCRIPT_PYTHON_INS)
 606        $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 607
 608.PHONY: clean-perl-script clean-sh-script clean-python-script
 609clean-sh-script:
 610        $(RM) $(SCRIPT_SH_GEN)
 611clean-perl-script:
 612        $(RM) $(SCRIPT_PERL_GEN)
 613clean-python-script:
 614        $(RM) $(SCRIPT_PYTHON_GEN)
 615
 616SCRIPTS = $(SCRIPT_SH_INS) \
 617          $(SCRIPT_PERL_INS) \
 618          $(SCRIPT_PYTHON_INS) \
 619          git-instaweb
 620
 621ETAGS_TARGET = TAGS
 622
 623# Empty...
 624EXTRA_PROGRAMS =
 625
 626# ... and all the rest that could be moved out of bindir to gitexecdir
 627PROGRAMS += $(EXTRA_PROGRAMS)
 628
 629PROGRAM_OBJS += credential-store.o
 630PROGRAM_OBJS += daemon.o
 631PROGRAM_OBJS += fast-import.o
 632PROGRAM_OBJS += http-backend.o
 633PROGRAM_OBJS += imap-send.o
 634PROGRAM_OBJS += sh-i18n--envsubst.o
 635PROGRAM_OBJS += shell.o
 636PROGRAM_OBJS += show-index.o
 637PROGRAM_OBJS += upload-pack.o
 638PROGRAM_OBJS += remote-testsvn.o
 639
 640# Binary suffix, set to .exe for Windows builds
 641X =
 642
 643PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 644
 645TEST_PROGRAMS_NEED_X += test-chmtime
 646TEST_PROGRAMS_NEED_X += test-ctype
 647TEST_PROGRAMS_NEED_X += test-config
 648TEST_PROGRAMS_NEED_X += test-date
 649TEST_PROGRAMS_NEED_X += test-delta
 650TEST_PROGRAMS_NEED_X += test-drop-caches
 651TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 652TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
 653TEST_PROGRAMS_NEED_X += test-dump-split-index
 654TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
 655TEST_PROGRAMS_NEED_X += test-example-decorate
 656TEST_PROGRAMS_NEED_X += test-fake-ssh
 657TEST_PROGRAMS_NEED_X += test-genrandom
 658TEST_PROGRAMS_NEED_X += test-hashmap
 659TEST_PROGRAMS_NEED_X += test-index-version
 660TEST_PROGRAMS_NEED_X += test-lazy-init-name-hash
 661TEST_PROGRAMS_NEED_X += test-line-buffer
 662TEST_PROGRAMS_NEED_X += test-match-trees
 663TEST_PROGRAMS_NEED_X += test-mergesort
 664TEST_PROGRAMS_NEED_X += test-mktemp
 665TEST_PROGRAMS_NEED_X += test-online-cpus
 666TEST_PROGRAMS_NEED_X += test-parse-options
 667TEST_PROGRAMS_NEED_X += test-path-utils
 668TEST_PROGRAMS_NEED_X += test-prio-queue
 669TEST_PROGRAMS_NEED_X += test-read-cache
 670TEST_PROGRAMS_NEED_X += test-write-cache
 671TEST_PROGRAMS_NEED_X += test-ref-store
 672TEST_PROGRAMS_NEED_X += test-regex
 673TEST_PROGRAMS_NEED_X += test-revision-walking
 674TEST_PROGRAMS_NEED_X += test-run-command
 675TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
 676TEST_PROGRAMS_NEED_X += test-sha1
 677TEST_PROGRAMS_NEED_X += test-sha1-array
 678TEST_PROGRAMS_NEED_X += test-sigchain
 679TEST_PROGRAMS_NEED_X += test-strcmp-offset
 680TEST_PROGRAMS_NEED_X += test-string-list
 681TEST_PROGRAMS_NEED_X += test-submodule-config
 682TEST_PROGRAMS_NEED_X += test-subprocess
 683TEST_PROGRAMS_NEED_X += test-svn-fe
 684TEST_PROGRAMS_NEED_X += test-urlmatch-normalization
 685TEST_PROGRAMS_NEED_X += test-wildmatch
 686
 687TEST_PROGRAMS = $(patsubst %,t/helper/%$X,$(TEST_PROGRAMS_NEED_X))
 688
 689# List built-in command $C whose implementation cmd_$C() is not in
 690# builtin/$C.o but is linked in as part of some other command.
 691BUILT_INS += $(patsubst builtin/%.o,git-%$X,$(BUILTIN_OBJS))
 692
 693BUILT_INS += git-cherry$X
 694BUILT_INS += git-cherry-pick$X
 695BUILT_INS += git-format-patch$X
 696BUILT_INS += git-fsck-objects$X
 697BUILT_INS += git-init$X
 698BUILT_INS += git-merge-subtree$X
 699BUILT_INS += git-show$X
 700BUILT_INS += git-stage$X
 701BUILT_INS += git-status$X
 702BUILT_INS += git-whatchanged$X
 703
 704# what 'all' will build and 'install' will install in gitexecdir,
 705# excluding programs for built-in commands
 706ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
 707
 708# what 'all' will build but not install in gitexecdir
 709OTHER_PROGRAMS = git$X
 710
 711# what test wrappers are needed and 'install' will install, in bindir
 712BINDIR_PROGRAMS_NEED_X += git
 713BINDIR_PROGRAMS_NEED_X += git-upload-pack
 714BINDIR_PROGRAMS_NEED_X += git-receive-pack
 715BINDIR_PROGRAMS_NEED_X += git-upload-archive
 716BINDIR_PROGRAMS_NEED_X += git-shell
 717
 718BINDIR_PROGRAMS_NO_X += git-cvsserver
 719
 720# Set paths to tools early so that they can be used for version tests.
 721ifndef SHELL_PATH
 722        SHELL_PATH = /bin/sh
 723endif
 724ifndef PERL_PATH
 725        PERL_PATH = /usr/bin/perl
 726endif
 727ifndef PYTHON_PATH
 728        PYTHON_PATH = /usr/bin/python
 729endif
 730
 731export PERL_PATH
 732export PYTHON_PATH
 733
 734TEST_SHELL_PATH = $(SHELL_PATH)
 735
 736LIB_FILE = libgit.a
 737XDIFF_LIB = xdiff/lib.a
 738VCSSVN_LIB = vcs-svn/lib.a
 739
 740GENERATED_H += common-cmds.h
 741
 742LIB_H = $(shell $(FIND) . \
 743        -name .git -prune -o \
 744        -name t -prune -o \
 745        -name Documentation -prune -o \
 746        -name '*.h' -print)
 747
 748LIB_OBJS += abspath.o
 749LIB_OBJS += advice.o
 750LIB_OBJS += alias.o
 751LIB_OBJS += alloc.o
 752LIB_OBJS += apply.o
 753LIB_OBJS += archive.o
 754LIB_OBJS += archive-tar.o
 755LIB_OBJS += archive-zip.o
 756LIB_OBJS += argv-array.o
 757LIB_OBJS += attr.o
 758LIB_OBJS += base85.o
 759LIB_OBJS += bisect.o
 760LIB_OBJS += blame.o
 761LIB_OBJS += blob.o
 762LIB_OBJS += branch.o
 763LIB_OBJS += bulk-checkin.o
 764LIB_OBJS += bundle.o
 765LIB_OBJS += cache-tree.o
 766LIB_OBJS += checkout.o
 767LIB_OBJS += color.o
 768LIB_OBJS += column.o
 769LIB_OBJS += combine-diff.o
 770LIB_OBJS += commit.o
 771LIB_OBJS += compat/obstack.o
 772LIB_OBJS += compat/terminal.o
 773LIB_OBJS += config.o
 774LIB_OBJS += connect.o
 775LIB_OBJS += connected.o
 776LIB_OBJS += convert.o
 777LIB_OBJS += copy.o
 778LIB_OBJS += credential.o
 779LIB_OBJS += csum-file.o
 780LIB_OBJS += ctype.o
 781LIB_OBJS += date.o
 782LIB_OBJS += decorate.o
 783LIB_OBJS += diffcore-break.o
 784LIB_OBJS += diffcore-delta.o
 785LIB_OBJS += diffcore-order.o
 786LIB_OBJS += diffcore-pickaxe.o
 787LIB_OBJS += diffcore-rename.o
 788LIB_OBJS += diff-delta.o
 789LIB_OBJS += diff-lib.o
 790LIB_OBJS += diff-no-index.o
 791LIB_OBJS += diff.o
 792LIB_OBJS += dir.o
 793LIB_OBJS += dir-iterator.o
 794LIB_OBJS += editor.o
 795LIB_OBJS += entry.o
 796LIB_OBJS += environment.o
 797LIB_OBJS += ewah/bitmap.o
 798LIB_OBJS += ewah/ewah_bitmap.o
 799LIB_OBJS += ewah/ewah_io.o
 800LIB_OBJS += ewah/ewah_rlw.o
 801LIB_OBJS += exec_cmd.o
 802LIB_OBJS += fetch-pack.o
 803LIB_OBJS += fsck.o
 804LIB_OBJS += fsmonitor.o
 805LIB_OBJS += gettext.o
 806LIB_OBJS += gpg-interface.o
 807LIB_OBJS += graph.o
 808LIB_OBJS += grep.o
 809LIB_OBJS += hashmap.o
 810LIB_OBJS += help.o
 811LIB_OBJS += hex.o
 812LIB_OBJS += ident.o
 813LIB_OBJS += kwset.o
 814LIB_OBJS += levenshtein.o
 815LIB_OBJS += line-log.o
 816LIB_OBJS += line-range.o
 817LIB_OBJS += list-objects.o
 818LIB_OBJS += list-objects-filter.o
 819LIB_OBJS += list-objects-filter-options.o
 820LIB_OBJS += ll-merge.o
 821LIB_OBJS += lockfile.o
 822LIB_OBJS += log-tree.o
 823LIB_OBJS += mailinfo.o
 824LIB_OBJS += mailmap.o
 825LIB_OBJS += match-trees.o
 826LIB_OBJS += merge.o
 827LIB_OBJS += merge-blobs.o
 828LIB_OBJS += merge-recursive.o
 829LIB_OBJS += mergesort.o
 830LIB_OBJS += mru.o
 831LIB_OBJS += name-hash.o
 832LIB_OBJS += notes.o
 833LIB_OBJS += notes-cache.o
 834LIB_OBJS += notes-merge.o
 835LIB_OBJS += notes-utils.o
 836LIB_OBJS += object.o
 837LIB_OBJS += oidmap.o
 838LIB_OBJS += oidset.o
 839LIB_OBJS += packfile.o
 840LIB_OBJS += pack-bitmap.o
 841LIB_OBJS += pack-bitmap-write.o
 842LIB_OBJS += pack-check.o
 843LIB_OBJS += pack-objects.o
 844LIB_OBJS += pack-revindex.o
 845LIB_OBJS += pack-write.o
 846LIB_OBJS += pager.o
 847LIB_OBJS += parse-options.o
 848LIB_OBJS += parse-options-cb.o
 849LIB_OBJS += patch-delta.o
 850LIB_OBJS += patch-ids.o
 851LIB_OBJS += path.o
 852LIB_OBJS += pathspec.o
 853LIB_OBJS += pkt-line.o
 854LIB_OBJS += preload-index.o
 855LIB_OBJS += pretty.o
 856LIB_OBJS += prio-queue.o
 857LIB_OBJS += progress.o
 858LIB_OBJS += prompt.o
 859LIB_OBJS += protocol.o
 860LIB_OBJS += quote.o
 861LIB_OBJS += reachable.o
 862LIB_OBJS += read-cache.o
 863LIB_OBJS += reflog-walk.o
 864LIB_OBJS += refs.o
 865LIB_OBJS += refs/files-backend.o
 866LIB_OBJS += refs/iterator.o
 867LIB_OBJS += refs/packed-backend.o
 868LIB_OBJS += refs/ref-cache.o
 869LIB_OBJS += ref-filter.o
 870LIB_OBJS += remote.o
 871LIB_OBJS += replace_object.o
 872LIB_OBJS += repository.o
 873LIB_OBJS += rerere.o
 874LIB_OBJS += resolve-undo.o
 875LIB_OBJS += revision.o
 876LIB_OBJS += run-command.o
 877LIB_OBJS += send-pack.o
 878LIB_OBJS += sequencer.o
 879LIB_OBJS += server-info.o
 880LIB_OBJS += setup.o
 881LIB_OBJS += sha1-array.o
 882LIB_OBJS += sha1-lookup.o
 883LIB_OBJS += sha1_file.o
 884LIB_OBJS += sha1_name.o
 885LIB_OBJS += shallow.o
 886LIB_OBJS += sideband.o
 887LIB_OBJS += sigchain.o
 888LIB_OBJS += split-index.o
 889LIB_OBJS += strbuf.o
 890LIB_OBJS += streaming.o
 891LIB_OBJS += string-list.o
 892LIB_OBJS += submodule.o
 893LIB_OBJS += submodule-config.o
 894LIB_OBJS += sub-process.o
 895LIB_OBJS += symlinks.o
 896LIB_OBJS += tag.o
 897LIB_OBJS += tempfile.o
 898LIB_OBJS += tmp-objdir.o
 899LIB_OBJS += trace.o
 900LIB_OBJS += trailer.o
 901LIB_OBJS += transport.o
 902LIB_OBJS += transport-helper.o
 903LIB_OBJS += tree-diff.o
 904LIB_OBJS += tree.o
 905LIB_OBJS += tree-walk.o
 906LIB_OBJS += unpack-trees.o
 907LIB_OBJS += url.o
 908LIB_OBJS += urlmatch.o
 909LIB_OBJS += usage.o
 910LIB_OBJS += userdiff.o
 911LIB_OBJS += utf8.o
 912LIB_OBJS += varint.o
 913LIB_OBJS += version.o
 914LIB_OBJS += versioncmp.o
 915LIB_OBJS += walker.o
 916LIB_OBJS += wildmatch.o
 917LIB_OBJS += worktree.o
 918LIB_OBJS += wrapper.o
 919LIB_OBJS += write_or_die.o
 920LIB_OBJS += ws.o
 921LIB_OBJS += wt-status.o
 922LIB_OBJS += xdiff-interface.o
 923LIB_OBJS += zlib.o
 924
 925BUILTIN_OBJS += builtin/add.o
 926BUILTIN_OBJS += builtin/am.o
 927BUILTIN_OBJS += builtin/annotate.o
 928BUILTIN_OBJS += builtin/apply.o
 929BUILTIN_OBJS += builtin/archive.o
 930BUILTIN_OBJS += builtin/bisect--helper.o
 931BUILTIN_OBJS += builtin/blame.o
 932BUILTIN_OBJS += builtin/branch.o
 933BUILTIN_OBJS += builtin/bundle.o
 934BUILTIN_OBJS += builtin/cat-file.o
 935BUILTIN_OBJS += builtin/check-attr.o
 936BUILTIN_OBJS += builtin/check-ignore.o
 937BUILTIN_OBJS += builtin/check-mailmap.o
 938BUILTIN_OBJS += builtin/check-ref-format.o
 939BUILTIN_OBJS += builtin/checkout-index.o
 940BUILTIN_OBJS += builtin/checkout.o
 941BUILTIN_OBJS += builtin/clean.o
 942BUILTIN_OBJS += builtin/clone.o
 943BUILTIN_OBJS += builtin/column.o
 944BUILTIN_OBJS += builtin/commit-tree.o
 945BUILTIN_OBJS += builtin/commit.o
 946BUILTIN_OBJS += builtin/config.o
 947BUILTIN_OBJS += builtin/count-objects.o
 948BUILTIN_OBJS += builtin/credential.o
 949BUILTIN_OBJS += builtin/describe.o
 950BUILTIN_OBJS += builtin/diff-files.o
 951BUILTIN_OBJS += builtin/diff-index.o
 952BUILTIN_OBJS += builtin/diff-tree.o
 953BUILTIN_OBJS += builtin/diff.o
 954BUILTIN_OBJS += builtin/difftool.o
 955BUILTIN_OBJS += builtin/fast-export.o
 956BUILTIN_OBJS += builtin/fetch-pack.o
 957BUILTIN_OBJS += builtin/fetch.o
 958BUILTIN_OBJS += builtin/fmt-merge-msg.o
 959BUILTIN_OBJS += builtin/for-each-ref.o
 960BUILTIN_OBJS += builtin/fsck.o
 961BUILTIN_OBJS += builtin/gc.o
 962BUILTIN_OBJS += builtin/get-tar-commit-id.o
 963BUILTIN_OBJS += builtin/grep.o
 964BUILTIN_OBJS += builtin/hash-object.o
 965BUILTIN_OBJS += builtin/help.o
 966BUILTIN_OBJS += builtin/index-pack.o
 967BUILTIN_OBJS += builtin/init-db.o
 968BUILTIN_OBJS += builtin/interpret-trailers.o
 969BUILTIN_OBJS += builtin/log.o
 970BUILTIN_OBJS += builtin/ls-files.o
 971BUILTIN_OBJS += builtin/ls-remote.o
 972BUILTIN_OBJS += builtin/ls-tree.o
 973BUILTIN_OBJS += builtin/mailinfo.o
 974BUILTIN_OBJS += builtin/mailsplit.o
 975BUILTIN_OBJS += builtin/merge.o
 976BUILTIN_OBJS += builtin/merge-base.o
 977BUILTIN_OBJS += builtin/merge-file.o
 978BUILTIN_OBJS += builtin/merge-index.o
 979BUILTIN_OBJS += builtin/merge-ours.o
 980BUILTIN_OBJS += builtin/merge-recursive.o
 981BUILTIN_OBJS += builtin/merge-tree.o
 982BUILTIN_OBJS += builtin/mktag.o
 983BUILTIN_OBJS += builtin/mktree.o
 984BUILTIN_OBJS += builtin/mv.o
 985BUILTIN_OBJS += builtin/name-rev.o
 986BUILTIN_OBJS += builtin/notes.o
 987BUILTIN_OBJS += builtin/pack-objects.o
 988BUILTIN_OBJS += builtin/pack-redundant.o
 989BUILTIN_OBJS += builtin/pack-refs.o
 990BUILTIN_OBJS += builtin/patch-id.o
 991BUILTIN_OBJS += builtin/prune-packed.o
 992BUILTIN_OBJS += builtin/prune.o
 993BUILTIN_OBJS += builtin/pull.o
 994BUILTIN_OBJS += builtin/push.o
 995BUILTIN_OBJS += builtin/read-tree.o
 996BUILTIN_OBJS += builtin/rebase--helper.o
 997BUILTIN_OBJS += builtin/receive-pack.o
 998BUILTIN_OBJS += builtin/reflog.o
 999BUILTIN_OBJS += builtin/remote.o
1000BUILTIN_OBJS += builtin/remote-ext.o
1001BUILTIN_OBJS += builtin/remote-fd.o
1002BUILTIN_OBJS += builtin/repack.o
1003BUILTIN_OBJS += builtin/replace.o
1004BUILTIN_OBJS += builtin/rerere.o
1005BUILTIN_OBJS += builtin/reset.o
1006BUILTIN_OBJS += builtin/rev-list.o
1007BUILTIN_OBJS += builtin/rev-parse.o
1008BUILTIN_OBJS += builtin/revert.o
1009BUILTIN_OBJS += builtin/rm.o
1010BUILTIN_OBJS += builtin/send-pack.o
1011BUILTIN_OBJS += builtin/shortlog.o
1012BUILTIN_OBJS += builtin/show-branch.o
1013BUILTIN_OBJS += builtin/show-ref.o
1014BUILTIN_OBJS += builtin/stripspace.o
1015BUILTIN_OBJS += builtin/submodule--helper.o
1016BUILTIN_OBJS += builtin/symbolic-ref.o
1017BUILTIN_OBJS += builtin/tag.o
1018BUILTIN_OBJS += builtin/unpack-file.o
1019BUILTIN_OBJS += builtin/unpack-objects.o
1020BUILTIN_OBJS += builtin/update-index.o
1021BUILTIN_OBJS += builtin/update-ref.o
1022BUILTIN_OBJS += builtin/update-server-info.o
1023BUILTIN_OBJS += builtin/upload-archive.o
1024BUILTIN_OBJS += builtin/var.o
1025BUILTIN_OBJS += builtin/verify-commit.o
1026BUILTIN_OBJS += builtin/verify-pack.o
1027BUILTIN_OBJS += builtin/verify-tag.o
1028BUILTIN_OBJS += builtin/worktree.o
1029BUILTIN_OBJS += builtin/write-tree.o
1030
1031GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB)
1032EXTLIBS =
1033
1034GIT_USER_AGENT = git/$(GIT_VERSION)
1035
1036ifeq ($(wildcard sha1collisiondetection/lib/sha1.h),sha1collisiondetection/lib/sha1.h)
1037DC_SHA1_SUBMODULE = auto
1038endif
1039
1040include config.mak.uname
1041-include config.mak.autogen
1042-include config.mak
1043
1044ifdef DEVELOPER
1045include config.mak.dev
1046endif
1047
1048comma := ,
1049empty :=
1050space := $(empty) $(empty)
1051
1052ifdef SANITIZE
1053SANITIZERS := $(foreach flag,$(subst $(comma),$(space),$(SANITIZE)),$(flag))
1054BASIC_CFLAGS += -fsanitize=$(SANITIZE) -fno-sanitize-recover=$(SANITIZE)
1055BASIC_CFLAGS += -fno-omit-frame-pointer
1056ifneq ($(filter undefined,$(SANITIZERS)),)
1057BASIC_CFLAGS += -DNO_UNALIGNED_LOADS
1058endif
1059ifneq ($(filter leak,$(SANITIZERS)),)
1060BASIC_CFLAGS += -DSUPPRESS_ANNOTATED_LEAKS
1061endif
1062endif
1063
1064ifndef sysconfdir
1065ifeq ($(prefix),/usr)
1066sysconfdir = /etc
1067else
1068sysconfdir = etc
1069endif
1070endif
1071
1072ifndef COMPUTE_HEADER_DEPENDENCIES
1073COMPUTE_HEADER_DEPENDENCIES = auto
1074endif
1075
1076ifeq ($(COMPUTE_HEADER_DEPENDENCIES),auto)
1077dep_check = $(shell $(CC) $(ALL_CFLAGS) \
1078        -c -MF /dev/null -MQ /dev/null -MMD -MP \
1079        -x c /dev/null -o /dev/null 2>&1; \
1080        echo $$?)
1081ifeq ($(dep_check),0)
1082override COMPUTE_HEADER_DEPENDENCIES = yes
1083else
1084override COMPUTE_HEADER_DEPENDENCIES = no
1085endif
1086endif
1087
1088ifeq ($(COMPUTE_HEADER_DEPENDENCIES),yes)
1089USE_COMPUTED_HEADER_DEPENDENCIES = YesPlease
1090else
1091ifneq ($(COMPUTE_HEADER_DEPENDENCIES),no)
1092$(error please set COMPUTE_HEADER_DEPENDENCIES to yes, no, or auto \
1093(not "$(COMPUTE_HEADER_DEPENDENCIES)"))
1094endif
1095endif
1096
1097ifdef SANE_TOOL_PATH
1098SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
1099BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
1100PATH := $(SANE_TOOL_PATH):${PATH}
1101else
1102BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
1103endif
1104
1105ifeq (,$(HOST_CPU))
1106        BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(firstword $(subst -, ,$(uname_M)))\""
1107else
1108        BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(HOST_CPU)\""
1109endif
1110
1111ifneq (,$(INLINE))
1112        BASIC_CFLAGS += -Dinline=$(INLINE)
1113endif
1114
1115ifneq (,$(SOCKLEN_T))
1116        BASIC_CFLAGS += -Dsocklen_t=$(SOCKLEN_T)
1117endif
1118
1119ifeq (yes,$(USE_PARENS_AROUND_GETTEXT_N))
1120        BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=1
1121else
1122ifeq (no,$(USE_PARENS_AROUND_GETTEXT_N))
1123        BASIC_CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
1124endif
1125endif
1126
1127ifeq ($(uname_S),Darwin)
1128        ifndef NO_FINK
1129                ifeq ($(shell test -d /sw/lib && echo y),y)
1130                        BASIC_CFLAGS += -I/sw/include
1131                        BASIC_LDFLAGS += -L/sw/lib
1132                endif
1133        endif
1134        ifndef NO_DARWIN_PORTS
1135                ifeq ($(shell test -d /opt/local/lib && echo y),y)
1136                        BASIC_CFLAGS += -I/opt/local/include
1137                        BASIC_LDFLAGS += -L/opt/local/lib
1138                endif
1139        endif
1140        ifndef NO_APPLE_COMMON_CRYPTO
1141                NO_OPENSSL = YesPlease
1142                APPLE_COMMON_CRYPTO = YesPlease
1143                COMPAT_CFLAGS += -DAPPLE_COMMON_CRYPTO
1144        endif
1145        NO_REGEX = YesPlease
1146        PTHREAD_LIBS =
1147endif
1148
1149ifndef CC_LD_DYNPATH
1150        ifdef NO_R_TO_GCC_LINKER
1151                # Some gcc does not accept and pass -R to the linker to specify
1152                # the runtime dynamic library path.
1153                CC_LD_DYNPATH = -Wl,-rpath,
1154        else
1155                CC_LD_DYNPATH = -R
1156        endif
1157endif
1158
1159ifdef NO_LIBGEN_H
1160        COMPAT_CFLAGS += -DNO_LIBGEN_H
1161        COMPAT_OBJS += compat/basename.o
1162endif
1163
1164USE_LIBPCRE1 ?= $(USE_LIBPCRE)
1165
1166ifneq (,$(USE_LIBPCRE1))
1167        ifdef USE_LIBPCRE2
1168$(error Only set USE_LIBPCRE1 (or its alias USE_LIBPCRE) or USE_LIBPCRE2, not both!)
1169        endif
1170
1171        BASIC_CFLAGS += -DUSE_LIBPCRE1
1172        EXTLIBS += -lpcre
1173
1174ifdef NO_LIBPCRE1_JIT
1175        BASIC_CFLAGS += -DNO_LIBPCRE1_JIT
1176endif
1177endif
1178
1179ifdef USE_LIBPCRE2
1180        BASIC_CFLAGS += -DUSE_LIBPCRE2
1181        EXTLIBS += -lpcre2-8
1182endif
1183
1184ifdef LIBPCREDIR
1185        BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1186        EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
1187endif
1188
1189ifdef HAVE_ALLOCA_H
1190        BASIC_CFLAGS += -DHAVE_ALLOCA_H
1191endif
1192
1193IMAP_SEND_BUILDDEPS =
1194IMAP_SEND_LDFLAGS =
1195
1196ifdef NO_CURL
1197        BASIC_CFLAGS += -DNO_CURL
1198        REMOTE_CURL_PRIMARY =
1199        REMOTE_CURL_ALIASES =
1200        REMOTE_CURL_NAMES =
1201else
1202        ifdef CURLDIR
1203                # Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
1204                BASIC_CFLAGS += -I$(CURLDIR)/include
1205                CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib) -lcurl
1206        else
1207                CURL_LIBCURL = -lcurl
1208        endif
1209        ifdef NEEDS_SSL_WITH_CURL
1210                CURL_LIBCURL += -lssl
1211                ifdef NEEDS_CRYPTO_WITH_SSL
1212                        CURL_LIBCURL += -lcrypto
1213                endif
1214        endif
1215        ifdef NEEDS_IDN_WITH_CURL
1216                CURL_LIBCURL += -lidn
1217        endif
1218
1219        REMOTE_CURL_PRIMARY = git-remote-http$X
1220        REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
1221        REMOTE_CURL_NAMES = $(REMOTE_CURL_PRIMARY) $(REMOTE_CURL_ALIASES)
1222        PROGRAM_OBJS += http-fetch.o
1223        PROGRAMS += $(REMOTE_CURL_NAMES)
1224        curl_check := $(shell (echo 070908; $(CURL_CONFIG) --vernum | sed -e '/^70[BC]/s/^/0/') 2>/dev/null | sort -r | sed -ne 2p)
1225        ifeq "$(curl_check)" "070908"
1226                ifndef NO_EXPAT
1227                        PROGRAM_OBJS += http-push.o
1228                endif
1229        endif
1230        curl_check := $(shell (echo 072200; $(CURL_CONFIG) --vernum | sed -e '/^70[BC]/s/^/0/') 2>/dev/null | sort -r | sed -ne 2p)
1231        ifeq "$(curl_check)" "072200"
1232                USE_CURL_FOR_IMAP_SEND = YesPlease
1233        endif
1234        ifdef USE_CURL_FOR_IMAP_SEND
1235                BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1236                IMAP_SEND_BUILDDEPS = http.o
1237                IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
1238        endif
1239        ifndef NO_EXPAT
1240                ifdef EXPATDIR
1241                        BASIC_CFLAGS += -I$(EXPATDIR)/include
1242                        EXPAT_LIBEXPAT = -L$(EXPATDIR)/$(lib) $(CC_LD_DYNPATH)$(EXPATDIR)/$(lib) -lexpat
1243                else
1244                        EXPAT_LIBEXPAT = -lexpat
1245                endif
1246                ifdef EXPAT_NEEDS_XMLPARSE_H
1247                        BASIC_CFLAGS += -DEXPAT_NEEDS_XMLPARSE_H
1248                endif
1249        endif
1250endif
1251IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
1252
1253ifdef ZLIB_PATH
1254        BASIC_CFLAGS += -I$(ZLIB_PATH)/include
1255        EXTLIBS += -L$(ZLIB_PATH)/$(lib) $(CC_LD_DYNPATH)$(ZLIB_PATH)/$(lib)
1256endif
1257EXTLIBS += -lz
1258
1259ifndef NO_OPENSSL
1260        OPENSSL_LIBSSL = -lssl
1261        ifdef OPENSSLDIR
1262                BASIC_CFLAGS += -I$(OPENSSLDIR)/include
1263                OPENSSL_LINK = -L$(OPENSSLDIR)/$(lib) $(CC_LD_DYNPATH)$(OPENSSLDIR)/$(lib)
1264        else
1265                OPENSSL_LINK =
1266        endif
1267        ifdef NEEDS_CRYPTO_WITH_SSL
1268                OPENSSL_LIBSSL += -lcrypto
1269        endif
1270else
1271        BASIC_CFLAGS += -DNO_OPENSSL
1272        OPENSSL_LIBSSL =
1273endif
1274ifdef NO_OPENSSL
1275        LIB_4_CRYPTO =
1276else
1277ifdef NEEDS_SSL_WITH_CRYPTO
1278        LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto -lssl
1279else
1280        LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto
1281endif
1282ifdef APPLE_COMMON_CRYPTO
1283        LIB_4_CRYPTO += -framework Security -framework CoreFoundation
1284endif
1285endif
1286ifdef NEEDS_LIBICONV
1287        ifdef ICONVDIR
1288                BASIC_CFLAGS += -I$(ICONVDIR)/include
1289                ICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib)
1290        else
1291                ICONV_LINK =
1292        endif
1293        ifdef NEEDS_LIBINTL_BEFORE_LIBICONV
1294                ICONV_LINK += -lintl
1295        endif
1296        EXTLIBS += $(ICONV_LINK) -liconv
1297endif
1298ifdef NEEDS_LIBGEN
1299        EXTLIBS += -lgen
1300endif
1301ifndef NO_GETTEXT
1302ifndef LIBC_CONTAINS_LIBINTL
1303        EXTLIBS += -lintl
1304endif
1305endif
1306ifdef NEEDS_SOCKET
1307        EXTLIBS += -lsocket
1308endif
1309ifdef NEEDS_NSL
1310        EXTLIBS += -lnsl
1311endif
1312ifdef NEEDS_RESOLV
1313        EXTLIBS += -lresolv
1314endif
1315ifdef NO_D_TYPE_IN_DIRENT
1316        BASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT
1317endif
1318ifdef NO_GECOS_IN_PWENT
1319        BASIC_CFLAGS += -DNO_GECOS_IN_PWENT
1320endif
1321ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
1322        BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
1323endif
1324ifdef USE_NSEC
1325        BASIC_CFLAGS += -DUSE_NSEC
1326endif
1327ifdef USE_ST_TIMESPEC
1328        BASIC_CFLAGS += -DUSE_ST_TIMESPEC
1329endif
1330ifdef NO_NORETURN
1331        BASIC_CFLAGS += -DNO_NORETURN
1332endif
1333ifdef NO_NSEC
1334        BASIC_CFLAGS += -DNO_NSEC
1335endif
1336ifdef SNPRINTF_RETURNS_BOGUS
1337        COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS
1338        COMPAT_OBJS += compat/snprintf.o
1339endif
1340ifdef FREAD_READS_DIRECTORIES
1341        COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES
1342        COMPAT_OBJS += compat/fopen.o
1343endif
1344ifdef NO_SYMLINK_HEAD
1345        BASIC_CFLAGS += -DNO_SYMLINK_HEAD
1346endif
1347ifdef GETTEXT_POISON
1348        BASIC_CFLAGS += -DGETTEXT_POISON
1349endif
1350ifdef NO_GETTEXT
1351        BASIC_CFLAGS += -DNO_GETTEXT
1352        USE_GETTEXT_SCHEME ?= fallthrough
1353endif
1354ifdef NO_POLL
1355        NO_SYS_POLL_H = YesPlease
1356        COMPAT_CFLAGS += -DNO_POLL -Icompat/poll
1357        COMPAT_OBJS += compat/poll/poll.o
1358endif
1359ifdef NO_STRCASESTR
1360        COMPAT_CFLAGS += -DNO_STRCASESTR
1361        COMPAT_OBJS += compat/strcasestr.o
1362endif
1363ifdef NO_STRLCPY
1364        COMPAT_CFLAGS += -DNO_STRLCPY
1365        COMPAT_OBJS += compat/strlcpy.o
1366endif
1367ifdef NO_STRTOUMAX
1368        COMPAT_CFLAGS += -DNO_STRTOUMAX
1369        COMPAT_OBJS += compat/strtoumax.o compat/strtoimax.o
1370endif
1371ifdef NO_STRTOULL
1372        COMPAT_CFLAGS += -DNO_STRTOULL
1373endif
1374ifdef NO_SETENV
1375        COMPAT_CFLAGS += -DNO_SETENV
1376        COMPAT_OBJS += compat/setenv.o
1377endif
1378ifdef NO_MKDTEMP
1379        COMPAT_CFLAGS += -DNO_MKDTEMP
1380        COMPAT_OBJS += compat/mkdtemp.o
1381endif
1382ifdef MKDIR_WO_TRAILING_SLASH
1383        COMPAT_CFLAGS += -DMKDIR_WO_TRAILING_SLASH
1384        COMPAT_OBJS += compat/mkdir.o
1385endif
1386ifdef NO_UNSETENV
1387        COMPAT_CFLAGS += -DNO_UNSETENV
1388        COMPAT_OBJS += compat/unsetenv.o
1389endif
1390ifdef NO_SYS_SELECT_H
1391        BASIC_CFLAGS += -DNO_SYS_SELECT_H
1392endif
1393ifdef NO_SYS_POLL_H
1394        BASIC_CFLAGS += -DNO_SYS_POLL_H
1395endif
1396ifdef NEEDS_SYS_PARAM_H
1397        BASIC_CFLAGS += -DNEEDS_SYS_PARAM_H
1398endif
1399ifdef NO_INTTYPES_H
1400        BASIC_CFLAGS += -DNO_INTTYPES_H
1401endif
1402ifdef NO_INITGROUPS
1403        BASIC_CFLAGS += -DNO_INITGROUPS
1404endif
1405ifdef NO_MMAP
1406        COMPAT_CFLAGS += -DNO_MMAP
1407        COMPAT_OBJS += compat/mmap.o
1408else
1409        ifdef USE_WIN32_MMAP
1410                COMPAT_CFLAGS += -DUSE_WIN32_MMAP
1411                COMPAT_OBJS += compat/win32mmap.o
1412        endif
1413endif
1414ifdef MMAP_PREVENTS_DELETE
1415        BASIC_CFLAGS += -DMMAP_PREVENTS_DELETE
1416endif
1417ifdef OBJECT_CREATION_USES_RENAMES
1418        COMPAT_CFLAGS += -DOBJECT_CREATION_MODE=1
1419endif
1420ifdef NO_STRUCT_ITIMERVAL
1421        COMPAT_CFLAGS += -DNO_STRUCT_ITIMERVAL
1422        NO_SETITIMER = YesPlease
1423endif
1424ifdef NO_SETITIMER
1425        COMPAT_CFLAGS += -DNO_SETITIMER
1426endif
1427ifdef NO_PREAD
1428        COMPAT_CFLAGS += -DNO_PREAD
1429        COMPAT_OBJS += compat/pread.o
1430endif
1431ifdef NO_FAST_WORKING_DIRECTORY
1432        BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY
1433endif
1434ifdef NO_TRUSTABLE_FILEMODE
1435        BASIC_CFLAGS += -DNO_TRUSTABLE_FILEMODE
1436endif
1437ifdef NEEDS_MODE_TRANSLATION
1438        COMPAT_CFLAGS += -DNEEDS_MODE_TRANSLATION
1439        COMPAT_OBJS += compat/stat.o
1440endif
1441ifdef NO_IPV6
1442        BASIC_CFLAGS += -DNO_IPV6
1443endif
1444ifdef NO_INTPTR_T
1445        COMPAT_CFLAGS += -DNO_INTPTR_T
1446endif
1447ifdef NO_UINTMAX_T
1448        BASIC_CFLAGS += -Duintmax_t=uint32_t
1449endif
1450ifdef NO_SOCKADDR_STORAGE
1451ifdef NO_IPV6
1452        BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in
1453else
1454        BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in6
1455endif
1456endif
1457ifdef NO_INET_NTOP
1458        LIB_OBJS += compat/inet_ntop.o
1459        BASIC_CFLAGS += -DNO_INET_NTOP
1460endif
1461ifdef NO_INET_PTON
1462        LIB_OBJS += compat/inet_pton.o
1463        BASIC_CFLAGS += -DNO_INET_PTON
1464endif
1465ifndef NO_UNIX_SOCKETS
1466        LIB_OBJS += unix-socket.o
1467        PROGRAM_OBJS += credential-cache.o
1468        PROGRAM_OBJS += credential-cache--daemon.o
1469endif
1470
1471ifdef NO_ICONV
1472        BASIC_CFLAGS += -DNO_ICONV
1473endif
1474
1475ifdef OLD_ICONV
1476        BASIC_CFLAGS += -DOLD_ICONV
1477endif
1478
1479ifdef NO_DEFLATE_BOUND
1480        BASIC_CFLAGS += -DNO_DEFLATE_BOUND
1481endif
1482
1483ifdef NO_POSIX_GOODIES
1484        BASIC_CFLAGS += -DNO_POSIX_GOODIES
1485endif
1486
1487ifdef APPLE_COMMON_CRYPTO
1488        # Apple CommonCrypto requires chunking
1489        SHA1_MAX_BLOCK_SIZE = 1024L*1024L*1024L
1490endif
1491
1492ifdef OPENSSL_SHA1
1493        EXTLIBS += $(LIB_4_CRYPTO)
1494        BASIC_CFLAGS += -DSHA1_OPENSSL
1495else
1496ifdef BLK_SHA1
1497        LIB_OBJS += block-sha1/sha1.o
1498        BASIC_CFLAGS += -DSHA1_BLK
1499else
1500ifdef PPC_SHA1
1501        LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
1502        BASIC_CFLAGS += -DSHA1_PPC
1503else
1504ifdef APPLE_COMMON_CRYPTO
1505        COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL
1506        BASIC_CFLAGS += -DSHA1_APPLE
1507else
1508        DC_SHA1 := YesPlease
1509        BASIC_CFLAGS += -DSHA1_DC
1510        LIB_OBJS += sha1dc_git.o
1511ifdef DC_SHA1_EXTERNAL
1512        ifdef DC_SHA1_SUBMODULE
1513$(error Only set DC_SHA1_EXTERNAL or DC_SHA1_SUBMODULE, not both)
1514        endif
1515        BASIC_CFLAGS += -DDC_SHA1_EXTERNAL
1516        EXTLIBS += -lsha1detectcoll
1517else
1518ifdef DC_SHA1_SUBMODULE
1519        LIB_OBJS += sha1collisiondetection/lib/sha1.o
1520        LIB_OBJS += sha1collisiondetection/lib/ubc_check.o
1521        BASIC_CFLAGS += -DDC_SHA1_SUBMODULE
1522else
1523        LIB_OBJS += sha1dc/sha1.o
1524        LIB_OBJS += sha1dc/ubc_check.o
1525endif
1526        BASIC_CFLAGS += \
1527                -DSHA1DC_NO_STANDARD_INCLUDES \
1528                -DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
1529                -DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
1530                -DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
1531endif
1532endif
1533endif
1534endif
1535endif
1536
1537ifdef SHA1_MAX_BLOCK_SIZE
1538        LIB_OBJS += compat/sha1-chunked.o
1539        BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)"
1540endif
1541ifdef NO_PERL_MAKEMAKER
1542        export NO_PERL_MAKEMAKER
1543endif
1544ifdef NO_HSTRERROR
1545        COMPAT_CFLAGS += -DNO_HSTRERROR
1546        COMPAT_OBJS += compat/hstrerror.o
1547endif
1548ifdef NO_MEMMEM
1549        COMPAT_CFLAGS += -DNO_MEMMEM
1550        COMPAT_OBJS += compat/memmem.o
1551endif
1552ifdef NO_GETPAGESIZE
1553        COMPAT_CFLAGS += -DNO_GETPAGESIZE
1554endif
1555ifdef INTERNAL_QSORT
1556        COMPAT_CFLAGS += -DINTERNAL_QSORT
1557        COMPAT_OBJS += compat/qsort.o
1558endif
1559ifdef HAVE_ISO_QSORT_S
1560        COMPAT_CFLAGS += -DHAVE_ISO_QSORT_S
1561else
1562        COMPAT_OBJS += compat/qsort_s.o
1563endif
1564ifdef RUNTIME_PREFIX
1565        COMPAT_CFLAGS += -DRUNTIME_PREFIX
1566endif
1567
1568ifdef NO_PTHREADS
1569        BASIC_CFLAGS += -DNO_PTHREADS
1570else
1571        BASIC_CFLAGS += $(PTHREAD_CFLAGS)
1572        EXTLIBS += $(PTHREAD_LIBS)
1573        LIB_OBJS += thread-utils.o
1574endif
1575
1576ifdef HAVE_PATHS_H
1577        BASIC_CFLAGS += -DHAVE_PATHS_H
1578endif
1579
1580ifdef HAVE_LIBCHARSET_H
1581        BASIC_CFLAGS += -DHAVE_LIBCHARSET_H
1582        EXTLIBS += $(CHARSET_LIB)
1583endif
1584
1585ifdef HAVE_STRINGS_H
1586        BASIC_CFLAGS += -DHAVE_STRINGS_H
1587endif
1588
1589ifdef HAVE_DEV_TTY
1590        BASIC_CFLAGS += -DHAVE_DEV_TTY
1591endif
1592
1593ifdef DIR_HAS_BSD_GROUP_SEMANTICS
1594        COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
1595endif
1596ifdef UNRELIABLE_FSTAT
1597        BASIC_CFLAGS += -DUNRELIABLE_FSTAT
1598endif
1599ifdef NO_REGEX
1600        COMPAT_CFLAGS += -Icompat/regex
1601        COMPAT_OBJS += compat/regex/regex.o
1602endif
1603ifdef NATIVE_CRLF
1604        BASIC_CFLAGS += -DNATIVE_CRLF
1605endif
1606
1607ifdef USE_NED_ALLOCATOR
1608        COMPAT_CFLAGS += -Icompat/nedmalloc
1609        COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
1610        OVERRIDE_STRDUP = YesPlease
1611endif
1612
1613ifdef OVERRIDE_STRDUP
1614        COMPAT_CFLAGS += -DOVERRIDE_STRDUP
1615        COMPAT_OBJS += compat/strdup.o
1616endif
1617
1618ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
1619        export GIT_TEST_CMP_USE_COPIED_CONTEXT
1620endif
1621
1622ifndef NO_MSGFMT_EXTENDED_OPTIONS
1623        MSGFMT += --check --statistics
1624endif
1625
1626ifdef GMTIME_UNRELIABLE_ERRORS
1627        COMPAT_OBJS += compat/gmtime.o
1628        BASIC_CFLAGS += -DGMTIME_UNRELIABLE_ERRORS
1629endif
1630
1631ifdef HAVE_CLOCK_GETTIME
1632        BASIC_CFLAGS += -DHAVE_CLOCK_GETTIME
1633endif
1634
1635ifdef HAVE_CLOCK_MONOTONIC
1636        BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
1637endif
1638
1639ifdef NEEDS_LIBRT
1640        EXTLIBS += -lrt
1641endif
1642
1643ifdef HAVE_BSD_SYSCTL
1644        BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
1645endif
1646
1647ifdef HAVE_GETDELIM
1648        BASIC_CFLAGS += -DHAVE_GETDELIM
1649endif
1650
1651ifeq ($(TCLTK_PATH),)
1652NO_TCLTK = NoThanks
1653endif
1654
1655ifeq ($(PERL_PATH),)
1656NO_PERL = NoThanks
1657endif
1658
1659ifeq ($(PYTHON_PATH),)
1660NO_PYTHON = NoThanks
1661endif
1662
1663ifndef PAGER_ENV
1664PAGER_ENV = LESS=FRX LV=-c
1665endif
1666
1667QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
1668QUIET_SUBDIR1  =
1669
1670ifneq ($(findstring w,$(MAKEFLAGS)),w)
1671PRINT_DIR = --no-print-directory
1672else # "make -w"
1673NO_SUBDIR = :
1674endif
1675
1676ifneq ($(findstring s,$(MAKEFLAGS)),s)
1677ifndef V
1678        QUIET_CC       = @echo '   ' CC $@;
1679        QUIET_AR       = @echo '   ' AR $@;
1680        QUIET_LINK     = @echo '   ' LINK $@;
1681        QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
1682        QUIET_GEN      = @echo '   ' GEN $@;
1683        QUIET_LNCP     = @echo '   ' LN/CP $@;
1684        QUIET_XGETTEXT = @echo '   ' XGETTEXT $@;
1685        QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
1686        QUIET_GCOV     = @echo '   ' GCOV $@;
1687        QUIET_SP       = @echo '   ' SP $<;
1688        QUIET_RC       = @echo '   ' RC $@;
1689        QUIET_SUBDIR0  = +@subdir=
1690        QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
1691                         $(MAKE) $(PRINT_DIR) -C $$subdir
1692        export V
1693        export QUIET_GEN
1694        export QUIET_BUILT_IN
1695endif
1696endif
1697
1698ifdef NO_INSTALL_HARDLINKS
1699        export NO_INSTALL_HARDLINKS
1700endif
1701
1702### profile feedback build
1703#
1704
1705# Can adjust this to be a global directory if you want to do extended
1706# data gathering
1707PROFILE_DIR := $(CURDIR)
1708
1709ifeq ("$(PROFILE)","GEN")
1710        BASIC_CFLAGS += -fprofile-generate=$(PROFILE_DIR) -DNO_NORETURN=1
1711        EXTLIBS += -lgcov
1712        export CCACHE_DISABLE = t
1713        V = 1
1714else
1715ifneq ("$(PROFILE)","")
1716        BASIC_CFLAGS += -fprofile-use=$(PROFILE_DIR) -fprofile-correction -DNO_NORETURN=1
1717        export CCACHE_DISABLE = t
1718        V = 1
1719endif
1720endif
1721
1722# Shell quote (do not use $(call) to accommodate ancient setups);
1723
1724ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
1725ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
1726
1727DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1728bindir_SQ = $(subst ','\'',$(bindir))
1729bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
1730mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
1731infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
1732localedir_SQ = $(subst ','\'',$(localedir))
1733gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
1734template_dir_SQ = $(subst ','\'',$(template_dir))
1735htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
1736prefix_SQ = $(subst ','\'',$(prefix))
1737gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
1738
1739SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
1740TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
1741PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
1742PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
1743TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
1744DIFF_SQ = $(subst ','\'',$(DIFF))
1745PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
1746
1747# We must filter out any object files from $(GITLIBS),
1748# as it is typically used like:
1749#
1750#   foo: foo.o $(GITLIBS)
1751#       $(CC) $(filter %.o,$^) $(LIBS)
1752#
1753# where we use it as a dependency. Since we also pull object files
1754# from the dependency list, that would make each entry appear twice.
1755LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
1756
1757BASIC_CFLAGS += $(COMPAT_CFLAGS)
1758LIB_OBJS += $(COMPAT_OBJS)
1759
1760# Quote for C
1761
1762ifdef DEFAULT_EDITOR
1763DEFAULT_EDITOR_CQ = "$(subst ",\",$(subst \,\\,$(DEFAULT_EDITOR)))"
1764DEFAULT_EDITOR_CQ_SQ = $(subst ','\'',$(DEFAULT_EDITOR_CQ))
1765
1766BASIC_CFLAGS += -DDEFAULT_EDITOR='$(DEFAULT_EDITOR_CQ_SQ)'
1767endif
1768
1769ifdef DEFAULT_PAGER
1770DEFAULT_PAGER_CQ = "$(subst ",\",$(subst \,\\,$(DEFAULT_PAGER)))"
1771DEFAULT_PAGER_CQ_SQ = $(subst ','\'',$(DEFAULT_PAGER_CQ))
1772
1773BASIC_CFLAGS += -DDEFAULT_PAGER='$(DEFAULT_PAGER_CQ_SQ)'
1774endif
1775
1776ifdef SHELL_PATH
1777SHELL_PATH_CQ = "$(subst ",\",$(subst \,\\,$(SHELL_PATH)))"
1778SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ))
1779
1780BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
1781endif
1782
1783GIT_USER_AGENT_SQ = $(subst ','\'',$(GIT_USER_AGENT))
1784GIT_USER_AGENT_CQ = "$(subst ",\",$(subst \,\\,$(GIT_USER_AGENT)))"
1785GIT_USER_AGENT_CQ_SQ = $(subst ','\'',$(GIT_USER_AGENT_CQ))
1786GIT-USER-AGENT: FORCE
1787        @if test x'$(GIT_USER_AGENT_SQ)' != x"`cat GIT-USER-AGENT 2>/dev/null`"; then \
1788                echo '$(GIT_USER_AGENT_SQ)' >GIT-USER-AGENT; \
1789        fi
1790
1791ifdef DEFAULT_HELP_FORMAT
1792BASIC_CFLAGS += -DDEFAULT_HELP_FORMAT='"$(DEFAULT_HELP_FORMAT)"'
1793endif
1794
1795PAGER_ENV_SQ = $(subst ','\'',$(PAGER_ENV))
1796PAGER_ENV_CQ = "$(subst ",\",$(subst \,\\,$(PAGER_ENV)))"
1797PAGER_ENV_CQ_SQ = $(subst ','\'',$(PAGER_ENV_CQ))
1798BASIC_CFLAGS += -DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'
1799
1800ALL_CFLAGS += $(BASIC_CFLAGS)
1801ALL_LDFLAGS += $(BASIC_LDFLAGS)
1802
1803export DIFF TAR INSTALL DESTDIR SHELL_PATH
1804
1805
1806### Build rules
1807
1808SHELL = $(SHELL_PATH)
1809
1810all:: shell_compatibility_test
1811
1812ifeq "$(PROFILE)" "BUILD"
1813all:: profile
1814endif
1815
1816profile:: profile-clean
1817        $(MAKE) PROFILE=GEN all
1818        $(MAKE) PROFILE=GEN -j1 test
1819        @if test -n "$$GIT_PERF_REPO" || test -d .git; then \
1820                $(MAKE) PROFILE=GEN -j1 perf; \
1821        else \
1822                echo "Skipping profile of perf tests..."; \
1823        fi
1824        $(MAKE) PROFILE=USE all
1825
1826profile-fast: profile-clean
1827        $(MAKE) PROFILE=GEN all
1828        $(MAKE) PROFILE=GEN -j1 perf
1829        $(MAKE) PROFILE=USE all
1830
1831
1832all:: $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
1833ifneq (,$X)
1834        $(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';)
1835endif
1836
1837all::
1838ifndef NO_TCLTK
1839        $(QUIET_SUBDIR0)git-gui $(QUIET_SUBDIR1) gitexecdir='$(gitexec_instdir_SQ)' all
1840        $(QUIET_SUBDIR0)gitk-git $(QUIET_SUBDIR1) all
1841endif
1842ifndef NO_PERL
1843        $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' localedir='$(localedir_SQ)' all
1844endif
1845        $(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1) SHELL_PATH='$(SHELL_PATH_SQ)' PERL_PATH='$(PERL_PATH_SQ)'
1846
1847please_set_SHELL_PATH_to_a_more_modern_shell:
1848        @$$(:)
1849
1850shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
1851
1852strip: $(PROGRAMS) git$X
1853        $(STRIP) $(STRIP_OPTS) $^
1854
1855### Target-specific flags and dependencies
1856
1857# The generic compilation pattern rule and automatically
1858# computed header dependencies (falling back to a dependency on
1859# LIB_H) are enough to describe how most targets should be built,
1860# but some targets are special enough to need something a little
1861# different.
1862#
1863# - When a source file "foo.c" #includes a generated header file,
1864#   we need to list that dependency for the "foo.o" target.
1865#
1866#   We also list it from other targets that are built from foo.c
1867#   like "foo.sp" and "foo.s", even though that is easy to forget
1868#   to do because the generated header is already present around
1869#   after a regular build attempt.
1870#
1871# - Some code depends on configuration kept in makefile
1872#   variables. The target-specific variable EXTRA_CPPFLAGS can
1873#   be used to convey that information to the C preprocessor
1874#   using -D options.
1875#
1876#   The "foo.o" target should have a corresponding dependency on
1877#   a file that changes when the value of the makefile variable
1878#   changes.  For example, targets making use of the
1879#   $(GIT_VERSION) variable depend on GIT-VERSION-FILE.
1880#
1881#   Technically the ".sp" and ".s" targets do not need this
1882#   dependency because they are force-built, but they get the
1883#   same dependency for consistency. This way, you do not have to
1884#   know how each target is implemented. And it means the
1885#   dependencies here will not need to change if the force-build
1886#   details change some day.
1887
1888git.sp git.s git.o: GIT-PREFIX
1889git.sp git.s git.o: EXTRA_CPPFLAGS = \
1890        '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
1891        '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
1892        '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
1893
1894git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
1895        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
1896                $(filter %.o,$^) $(LIBS)
1897
1898help.sp help.s help.o: common-cmds.h
1899
1900builtin/help.sp builtin/help.s builtin/help.o: common-cmds.h GIT-PREFIX
1901builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
1902        '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
1903        '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
1904        '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
1905
1906version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
1907version.sp version.s version.o: EXTRA_CPPFLAGS = \
1908        '-DGIT_VERSION="$(GIT_VERSION)"' \
1909        '-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
1910        '-DGIT_BUILT_FROM_COMMIT="$(shell GIT_CEILING_DIRECTORIES=\"$(CURDIR)/..\" \
1911                git rev-parse -q --verify HEAD || :)"'
1912
1913$(BUILT_INS): git$X
1914        $(QUIET_BUILT_IN)$(RM) $@ && \
1915        ln $< $@ 2>/dev/null || \
1916        ln -s $< $@ 2>/dev/null || \
1917        cp $< $@
1918
1919common-cmds.h: generate-cmdlist.sh command-list.txt
1920
1921common-cmds.h: $(wildcard Documentation/git-*.txt)
1922        $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
1923
1924SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
1925        $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
1926        $(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV)
1927define cmd_munge_script
1928$(RM) $@ $@+ && \
1929sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
1930    -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
1931    -e 's|@@DIFF@@|$(DIFF_SQ)|' \
1932    -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
1933    -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
1934    -e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
1935    -e $(BROKEN_PATH_FIX) \
1936    -e 's|@@GITWEBDIR@@|$(gitwebdir_SQ)|g' \
1937    -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
1938    -e 's|@@SANE_TEXT_GREP@@|$(SANE_TEXT_GREP)|g' \
1939    -e 's|@@PAGER_ENV@@|$(PAGER_ENV_SQ)|g' \
1940    $@.sh >$@+
1941endef
1942
1943GIT-SCRIPT-DEFINES: FORCE
1944        @FLAGS='$(SCRIPT_DEFINES)'; \
1945            if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
1946                echo >&2 "    * new script parameters"; \
1947                echo "$$FLAGS" >$@; \
1948            fi
1949
1950
1951$(SCRIPT_SH_GEN) : % : %.sh GIT-SCRIPT-DEFINES
1952        $(QUIET_GEN)$(cmd_munge_script) && \
1953        chmod +x $@+ && \
1954        mv $@+ $@
1955
1956$(SCRIPT_LIB) : % : %.sh GIT-SCRIPT-DEFINES
1957        $(QUIET_GEN)$(cmd_munge_script) && \
1958        mv $@+ $@
1959
1960git.res: git.rc GIT-VERSION-FILE
1961        $(QUIET_RC)$(RC) \
1962          $(join -DMAJOR= -DMINOR= -DMICRO= -DPATCHLEVEL=, $(wordlist 1, 4, \
1963            $(shell echo $(GIT_VERSION) 0 0 0 0 | tr '.a-zA-Z-' ' '))) \
1964          -DGIT_VERSION="\\\"$(GIT_VERSION)\\\"" -i $< -o $@
1965
1966# This makes sure we depend on the NO_PERL setting itself.
1967$(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS
1968
1969ifndef NO_PERL
1970$(SCRIPT_PERL_GEN): perl/perl.mak
1971
1972perl/perl.mak: perl/PM.stamp
1973
1974perl/PM.stamp: FORCE
1975        @$(FIND) perl -type f -name '*.pm' | sort >$@+ && \
1976        $(PERL_PATH) -V >>$@+ && \
1977        { cmp $@+ $@ >/dev/null 2>/dev/null || mv $@+ $@; } && \
1978        $(RM) $@+
1979
1980perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL
1981        $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F)
1982
1983PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ)
1984$(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-VERSION-FILE
1985        $(QUIET_GEN)$(RM) $@ $@+ && \
1986        INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \
1987        INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
1988        INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
1989        sed -e '1{' \
1990            -e '        s|#!.*perl|#!$(PERL_PATH_SQ)|' \
1991            -e '        h' \
1992            -e '        s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \
1993            -e '        H' \
1994            -e '        x' \
1995            -e '}' \
1996            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
1997            $< >$@+ && \
1998        chmod +x $@+ && \
1999        mv $@+ $@
2000
2001GIT-PERL-DEFINES: FORCE
2002        @FLAGS='$(PERL_DEFINES)'; \
2003            if test x"$$FLAGS" != x"`cat $@ 2>/dev/null`" ; then \
2004                echo >&2 "    * new perl-specific parameters"; \
2005                echo "$$FLAGS" >$@; \
2006            fi
2007
2008
2009.PHONY: gitweb
2010gitweb:
2011        $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all
2012
2013git-instaweb: git-instaweb.sh GIT-SCRIPT-DEFINES
2014        $(QUIET_GEN)$(cmd_munge_script) && \
2015        chmod +x $@+ && \
2016        mv $@+ $@
2017else # NO_PERL
2018$(SCRIPT_PERL_GEN) git-instaweb: % : unimplemented.sh
2019        $(QUIET_GEN)$(RM) $@ $@+ && \
2020        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
2021            -e 's|@@REASON@@|NO_PERL=$(NO_PERL)|g' \
2022            unimplemented.sh >$@+ && \
2023        chmod +x $@+ && \
2024        mv $@+ $@
2025endif # NO_PERL
2026
2027# This makes sure we depend on the NO_PYTHON setting itself.
2028$(SCRIPT_PYTHON_GEN): GIT-BUILD-OPTIONS
2029
2030ifndef NO_PYTHON
2031$(SCRIPT_PYTHON_GEN): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS
2032$(SCRIPT_PYTHON_GEN): % : %.py
2033        $(QUIET_GEN)$(RM) $@ $@+ && \
2034        sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
2035            $< >$@+ && \
2036        chmod +x $@+ && \
2037        mv $@+ $@
2038else # NO_PYTHON
2039$(SCRIPT_PYTHON_GEN): % : unimplemented.sh
2040        $(QUIET_GEN)$(RM) $@ $@+ && \
2041        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
2042            -e 's|@@REASON@@|NO_PYTHON=$(NO_PYTHON)|g' \
2043            unimplemented.sh >$@+ && \
2044        chmod +x $@+ && \
2045        mv $@+ $@
2046endif # NO_PYTHON
2047
2048CONFIGURE_RECIPE = $(RM) configure configure.ac+ && \
2049                   sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
2050                        configure.ac >configure.ac+ && \
2051                   autoconf -o configure configure.ac+ && \
2052                   $(RM) configure.ac+
2053
2054configure: configure.ac GIT-VERSION-FILE
2055        $(QUIET_GEN)$(CONFIGURE_RECIPE)
2056
2057ifdef AUTOCONFIGURED
2058# We avoid depending on 'configure' here, because it gets rebuilt
2059# every time GIT-VERSION-FILE is modified, only to update the embedded
2060# version number string, which config.status does not care about.  We
2061# do want to recheck when the platform/environment detection logic
2062# changes, hence this depends on configure.ac.
2063config.status: configure.ac
2064        $(QUIET_GEN)$(CONFIGURE_RECIPE) && \
2065        if test -f config.status; then \
2066          ./config.status --recheck; \
2067        else \
2068          ./configure; \
2069        fi
2070reconfigure config.mak.autogen: config.status
2071        $(QUIET_GEN)./config.status
2072.PHONY: reconfigure # This is a convenience target.
2073endif
2074
2075XDIFF_OBJS += xdiff/xdiffi.o
2076XDIFF_OBJS += xdiff/xprepare.o
2077XDIFF_OBJS += xdiff/xutils.o
2078XDIFF_OBJS += xdiff/xemit.o
2079XDIFF_OBJS += xdiff/xmerge.o
2080XDIFF_OBJS += xdiff/xpatience.o
2081XDIFF_OBJS += xdiff/xhistogram.o
2082
2083VCSSVN_OBJS += vcs-svn/line_buffer.o
2084VCSSVN_OBJS += vcs-svn/sliding_window.o
2085VCSSVN_OBJS += vcs-svn/fast_export.o
2086VCSSVN_OBJS += vcs-svn/svndiff.o
2087VCSSVN_OBJS += vcs-svn/svndump.o
2088
2089TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS))
2090OBJECTS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
2091        $(XDIFF_OBJS) \
2092        $(VCSSVN_OBJS) \
2093        common-main.o \
2094        git.o
2095ifndef NO_CURL
2096        OBJECTS += http.o http-walker.o remote-curl.o
2097endif
2098
2099dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
2100dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))
2101
2102ifeq ($(COMPUTE_HEADER_DEPENDENCIES),yes)
2103$(dep_dirs):
2104        @mkdir -p $@
2105
2106missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs))
2107dep_file = $(dir $@).depend/$(notdir $@).d
2108dep_args = -MF $(dep_file) -MQ $@ -MMD -MP
2109endif
2110
2111ifneq ($(COMPUTE_HEADER_DEPENDENCIES),yes)
2112dep_dirs =
2113missing_dep_dirs =
2114dep_args =
2115endif
2116
2117ASM_SRC := $(wildcard $(OBJECTS:o=S))
2118ASM_OBJ := $(ASM_SRC:S=o)
2119C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS))
2120
2121.SUFFIXES:
2122
2123$(C_OBJ): %.o: %.c GIT-CFLAGS $(missing_dep_dirs)
2124        $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
2125$(ASM_OBJ): %.o: %.S GIT-CFLAGS $(missing_dep_dirs)
2126        $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
2127
2128%.s: %.c GIT-CFLAGS FORCE
2129        $(QUIET_CC)$(CC) -o $@ -S $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
2130
2131ifdef USE_COMPUTED_HEADER_DEPENDENCIES
2132# Take advantage of gcc's on-the-fly dependency generation
2133# See <http://gcc.gnu.org/gcc-3.0/features.html>.
2134dep_files_present := $(wildcard $(dep_files))
2135ifneq ($(dep_files_present),)
2136include $(dep_files_present)
2137endif
2138else
2139# Dependencies on header files, for platforms that do not support
2140# the gcc -MMD option.
2141#
2142# Dependencies on automatically generated headers such as common-cmds.h
2143# should _not_ be included here, since they are necessary even when
2144# building an object for the first time.
2145
2146$(OBJECTS): $(LIB_H)
2147endif
2148
2149exec_cmd.sp exec_cmd.s exec_cmd.o: GIT-PREFIX
2150exec_cmd.sp exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
2151        '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
2152        '-DBINDIR="$(bindir_relative_SQ)"' \
2153        '-DPREFIX="$(prefix_SQ)"'
2154
2155builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX
2156builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
2157        -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
2158
2159config.sp config.s config.o: GIT-PREFIX
2160config.sp config.s config.o: EXTRA_CPPFLAGS = \
2161        -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
2162
2163attr.sp attr.s attr.o: GIT-PREFIX
2164attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
2165        -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'
2166
2167gettext.sp gettext.s gettext.o: GIT-PREFIX
2168gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2169        -DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2170
2171http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \
2172        -DCURL_DISABLE_TYPECHECK
2173
2174pack-revindex.sp: SPARSE_FLAGS += -Wno-memcpy-max-count
2175
2176ifdef NO_EXPAT
2177http-walker.sp http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
2178endif
2179
2180ifdef NO_REGEX
2181compat/regex/regex.sp compat/regex/regex.o: EXTRA_CPPFLAGS = \
2182        -DGAWK -DNO_MBSUPPORT
2183endif
2184
2185ifdef USE_NED_ALLOCATOR
2186compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
2187        -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR
2188compat/nedmalloc/nedmalloc.sp: SPARSE_FLAGS += -Wno-non-pointer-null
2189endif
2190
2191git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
2192        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
2193
2194git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
2195        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2196                $(IMAP_SEND_LDFLAGS) $(LIBS)
2197
2198git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2199        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2200                $(CURL_LIBCURL) $(LIBS)
2201git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2202        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2203                $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
2204
2205git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB)
2206        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \
2207        $(VCSSVN_LIB)
2208
2209$(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
2210        $(QUIET_LNCP)$(RM) $@ && \
2211        ln $< $@ 2>/dev/null || \
2212        ln -s $< $@ 2>/dev/null || \
2213        cp $< $@
2214
2215$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2216        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
2217                $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
2218
2219$(LIB_FILE): $(LIB_OBJS)
2220        $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2221
2222$(XDIFF_LIB): $(XDIFF_OBJS)
2223        $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2224
2225$(VCSSVN_LIB): $(VCSSVN_OBJS)
2226        $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2227
2228export DEFAULT_EDITOR DEFAULT_PAGER
2229
2230.PHONY: doc man html info pdf
2231doc:
2232        $(MAKE) -C Documentation all
2233
2234man:
2235        $(MAKE) -C Documentation man
2236
2237html:
2238        $(MAKE) -C Documentation html
2239
2240info:
2241        $(MAKE) -C Documentation info
2242
2243pdf:
2244        $(MAKE) -C Documentation pdf
2245
2246XGETTEXT_FLAGS = \
2247        --force-po \
2248        --add-comments=TRANSLATORS: \
2249        --msgid-bugs-address="Git Mailing List <git@vger.kernel.org>" \
2250        --from-code=UTF-8
2251XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
2252        --keyword=_ --keyword=N_ --keyword="Q_:1,2"
2253XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
2254        --keyword=gettextln --keyword=eval_gettextln
2255XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --language=Perl \
2256        --keyword=__ --keyword=N__ --keyword="__n:1,2"
2257LOCALIZED_C = $(C_OBJ:o=c) $(LIB_H) $(GENERATED_H)
2258LOCALIZED_SH = $(SCRIPT_SH)
2259LOCALIZED_SH += git-parse-remote.sh
2260LOCALIZED_SH += git-rebase--interactive.sh
2261LOCALIZED_SH += git-sh-setup.sh
2262LOCALIZED_PERL = $(SCRIPT_PERL)
2263
2264ifdef XGETTEXT_INCLUDE_TESTS
2265LOCALIZED_C += t/t0200/test.c
2266LOCALIZED_SH += t/t0200/test.sh
2267LOCALIZED_PERL += t/t0200/test.perl
2268endif
2269
2270## Note that this is meant to be run only by the localization coordinator
2271## under a very controlled condition, i.e. (1) it is to be run in a
2272## Git repository (not a tarball extract), (2) any local modifications
2273## will be lost.
2274## Gettext tools cannot work with our own custom PRItime type, so
2275## we replace PRItime with PRIuMAX.  We need to update this to
2276## PRIdMAX if we switch to a signed type later.
2277
2278po/git.pot: $(GENERATED_H) FORCE
2279        # All modifications will be reverted at the end, so we do not
2280        # want to have any local change.
2281        git diff --quiet HEAD && git diff --quiet --cached
2282
2283        @for s in $(LOCALIZED_C) $(LOCALIZED_SH) $(LOCALIZED_PERL); \
2284        do \
2285                sed -e 's|PRItime|PRIuMAX|g' <"$$s" >"$$s+" && \
2286                cat "$$s+" >"$$s" && rm "$$s+"; \
2287        done
2288
2289        $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
2290        $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
2291                $(LOCALIZED_SH)
2292        $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
2293                $(LOCALIZED_PERL)
2294
2295        # Reverting the munged source, leaving only the updated $@
2296        git reset --hard
2297        mv $@+ $@
2298
2299.PHONY: pot
2300pot: po/git.pot
2301
2302POFILES := $(wildcard po/*.po)
2303MOFILES := $(patsubst po/%.po,po/build/locale/%/LC_MESSAGES/git.mo,$(POFILES))
2304
2305ifndef NO_GETTEXT
2306all:: $(MOFILES)
2307endif
2308
2309po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
2310        $(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
2311
2312FIND_SOURCE_FILES = ( \
2313        git ls-files \
2314                '*.[hcS]' \
2315                '*.sh' \
2316                ':!*[tp][0-9][0-9][0-9][0-9]*' \
2317                ':!contrib' \
2318                2>/dev/null || \
2319        $(FIND) . \
2320                \( -name .git -type d -prune \) \
2321                -o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \
2322                -o \( -name contrib -type d -prune \) \
2323                -o \( -name build -type d -prune \) \
2324                -o \( -name 'trash*' -type d -prune \) \
2325                -o \( -name '*.[hcS]' -type f -print \) \
2326                -o \( -name '*.sh' -type f -print \) \
2327        )
2328
2329$(ETAGS_TARGET): FORCE
2330        $(RM) $(ETAGS_TARGET)
2331        $(FIND_SOURCE_FILES) | xargs etags -a -o $(ETAGS_TARGET)
2332
2333tags: FORCE
2334        $(RM) tags
2335        $(FIND_SOURCE_FILES) | xargs ctags -a
2336
2337cscope:
2338        $(RM) cscope*
2339        $(FIND_SOURCE_FILES) | xargs cscope -b
2340
2341### Detect prefix changes
2342TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
2343                $(localedir_SQ)
2344
2345GIT-PREFIX: FORCE
2346        @FLAGS='$(TRACK_PREFIX)'; \
2347        if test x"$$FLAGS" != x"`cat GIT-PREFIX 2>/dev/null`" ; then \
2348                echo >&2 "    * new prefix flags"; \
2349                echo "$$FLAGS" >GIT-PREFIX; \
2350        fi
2351
2352TRACK_CFLAGS = $(CC):$(subst ','\'',$(ALL_CFLAGS)):$(USE_GETTEXT_SCHEME)
2353
2354GIT-CFLAGS: FORCE
2355        @FLAGS='$(TRACK_CFLAGS)'; \
2356            if test x"$$FLAGS" != x"`cat GIT-CFLAGS 2>/dev/null`" ; then \
2357                echo >&2 "    * new build flags"; \
2358                echo "$$FLAGS" >GIT-CFLAGS; \
2359            fi
2360
2361TRACK_LDFLAGS = $(subst ','\'',$(ALL_LDFLAGS))
2362
2363GIT-LDFLAGS: FORCE
2364        @FLAGS='$(TRACK_LDFLAGS)'; \
2365            if test x"$$FLAGS" != x"`cat GIT-LDFLAGS 2>/dev/null`" ; then \
2366                echo >&2 "    * new link flags"; \
2367                echo "$$FLAGS" >GIT-LDFLAGS; \
2368            fi
2369
2370# We need to apply sq twice, once to protect from the shell
2371# that runs GIT-BUILD-OPTIONS, and then again to protect it
2372# and the first level quoting from the shell that runs "echo".
2373GIT-BUILD-OPTIONS: FORCE
2374        @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@+
2375        @echo TEST_SHELL_PATH=\''$(subst ','\'',$(TEST_SHELL_PATH_SQ))'\' >>$@+
2376        @echo PERL_PATH=\''$(subst ','\'',$(PERL_PATH_SQ))'\' >>$@+
2377        @echo DIFF=\''$(subst ','\'',$(subst ','\'',$(DIFF)))'\' >>$@+
2378        @echo PYTHON_PATH=\''$(subst ','\'',$(PYTHON_PATH_SQ))'\' >>$@+
2379        @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@+
2380        @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@+
2381        @echo NO_EXPAT=\''$(subst ','\'',$(subst ','\'',$(NO_EXPAT)))'\' >>$@+
2382        @echo USE_LIBPCRE1=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE1)))'\' >>$@+
2383        @echo USE_LIBPCRE2=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE2)))'\' >>$@+
2384        @echo NO_LIBPCRE1_JIT=\''$(subst ','\'',$(subst ','\'',$(NO_LIBPCRE1_JIT)))'\' >>$@+
2385        @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@+
2386        @echo NO_PTHREADS=\''$(subst ','\'',$(subst ','\'',$(NO_PTHREADS)))'\' >>$@+
2387        @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+
2388        @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
2389        @echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
2390        @echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
2391ifdef TEST_OUTPUT_DIRECTORY
2392        @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+
2393endif
2394ifdef GIT_TEST_OPTS
2395        @echo GIT_TEST_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_OPTS)))'\' >>$@+
2396endif
2397ifdef GIT_TEST_CMP
2398        @echo GIT_TEST_CMP=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_CMP)))'\' >>$@+
2399endif
2400ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
2401        @echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@+
2402endif
2403        @echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@+
2404        @echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@+
2405ifdef GIT_PERF_REPEAT_COUNT
2406        @echo GIT_PERF_REPEAT_COUNT=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPEAT_COUNT)))'\' >>$@+
2407endif
2408ifdef GIT_PERF_REPO
2409        @echo GIT_PERF_REPO=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPO)))'\' >>$@+
2410endif
2411ifdef GIT_PERF_LARGE_REPO
2412        @echo GIT_PERF_LARGE_REPO=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_LARGE_REPO)))'\' >>$@+
2413endif
2414ifdef GIT_PERF_MAKE_OPTS
2415        @echo GIT_PERF_MAKE_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_MAKE_OPTS)))'\' >>$@+
2416endif
2417ifdef GIT_PERF_MAKE_COMMAND
2418        @echo GIT_PERF_MAKE_COMMAND=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_MAKE_COMMAND)))'\' >>$@+
2419endif
2420ifdef GIT_INTEROP_MAKE_OPTS
2421        @echo GIT_INTEROP_MAKE_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_INTEROP_MAKE_OPTS)))'\' >>$@+
2422endif
2423ifdef TEST_GIT_INDEX_VERSION
2424        @echo TEST_GIT_INDEX_VERSION=\''$(subst ','\'',$(subst ','\'',$(TEST_GIT_INDEX_VERSION)))'\' >>$@+
2425endif
2426        @if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
2427
2428### Detect Python interpreter path changes
2429ifndef NO_PYTHON
2430TRACK_PYTHON = $(subst ','\'',-DPYTHON_PATH='$(PYTHON_PATH_SQ)')
2431
2432GIT-PYTHON-VARS: FORCE
2433        @VARS='$(TRACK_PYTHON)'; \
2434            if test x"$$VARS" != x"`cat $@ 2>/dev/null`" ; then \
2435                echo >&2 "    * new Python interpreter location"; \
2436                echo "$$VARS" >$@; \
2437            fi
2438endif
2439
2440test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))
2441
2442all:: $(TEST_PROGRAMS) $(test_bindir_programs)
2443all:: $(NO_INSTALL)
2444
2445bin-wrappers/%: wrap-for-bin.sh
2446        @mkdir -p bin-wrappers
2447        $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
2448             -e 's|@@BUILD_DIR@@|$(shell pwd)|' \
2449             -e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%,$(@F))|' < $< > $@ && \
2450        chmod +x $@
2451
2452# GNU make supports exporting all variables by "export" without parameters.
2453# However, the environment gets quite big, and some programs have problems
2454# with that.
2455
2456export NO_SVN_TESTS
2457export TEST_NO_MALLOC_CHECK
2458
2459### Testing rules
2460
2461test: all
2462        $(MAKE) -C t/ all
2463
2464perf: all
2465        $(MAKE) -C t/perf/ all
2466
2467.PHONY: test perf
2468
2469t/helper/test-line-buffer$X: $(VCSSVN_LIB)
2470
2471t/helper/test-svn-fe$X: $(VCSSVN_LIB)
2472
2473.PRECIOUS: $(TEST_OBJS)
2474
2475t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
2476        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
2477
2478check-sha1:: t/helper/test-sha1$X
2479        t/helper/test-sha1.sh
2480
2481SP_OBJ = $(patsubst %.o,%.sp,$(C_OBJ))
2482
2483$(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
2484        $(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) \
2485                $(SPARSE_FLAGS) $<
2486
2487.PHONY: sparse $(SP_OBJ)
2488sparse: $(SP_OBJ)
2489
2490.PHONY: style
2491style:
2492        git clang-format --style file --diff --extensions c,h
2493
2494check: common-cmds.h
2495        @if sparse; \
2496        then \
2497                echo >&2 "Use 'make sparse' instead"; \
2498                $(MAKE) --no-print-directory sparse; \
2499        else \
2500                echo >&2 "Did you mean 'make test'?"; \
2501                exit 1; \
2502        fi
2503
2504C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
2505%.cocci.patch: %.cocci $(C_SOURCES)
2506        @echo '    ' SPATCH $<; \
2507        ret=0; \
2508        for f in $(C_SOURCES); do \
2509                $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
2510                        { ret=$$?; break; }; \
2511        done >$@+ 2>$@.log; \
2512        if test $$ret != 0; \
2513        then \
2514                cat $@.log; \
2515                exit 1; \
2516        fi; \
2517        mv $@+ $@; \
2518        if test -s $@; \
2519        then \
2520                echo '    ' SPATCH result: $@; \
2521        fi
2522coccicheck: $(patsubst %.cocci,%.cocci.patch,$(wildcard contrib/coccinelle/*.cocci))
2523
2524### Installation rules
2525
2526ifneq ($(filter /%,$(firstword $(template_dir))),)
2527template_instdir = $(template_dir)
2528else
2529template_instdir = $(prefix)/$(template_dir)
2530endif
2531export template_instdir
2532
2533ifneq ($(filter /%,$(firstword $(gitexecdir))),)
2534gitexec_instdir = $(gitexecdir)
2535else
2536gitexec_instdir = $(prefix)/$(gitexecdir)
2537endif
2538gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
2539export gitexec_instdir
2540
2541ifneq ($(filter /%,$(firstword $(mergetoolsdir))),)
2542mergetools_instdir = $(mergetoolsdir)
2543else
2544mergetools_instdir = $(prefix)/$(mergetoolsdir)
2545endif
2546mergetools_instdir_SQ = $(subst ','\'',$(mergetools_instdir))
2547
2548install_bindir_programs := $(patsubst %,%$X,$(BINDIR_PROGRAMS_NEED_X)) $(BINDIR_PROGRAMS_NO_X)
2549
2550.PHONY: profile-install profile-fast-install
2551profile-install: profile
2552        $(MAKE) install
2553
2554profile-fast-install: profile-fast
2555        $(MAKE) install
2556
2557install: all
2558        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
2559        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2560        $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2561        $(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
2562        $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
2563        $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
2564        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
2565        $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
2566ifndef NO_GETTEXT
2567        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)'
2568        (cd po/build/locale && $(TAR) cf - .) | \
2569        (cd '$(DESTDIR_SQ)$(localedir_SQ)' && umask 022 && $(TAR) xof -)
2570endif
2571ifndef NO_PERL
2572        $(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
2573        $(MAKE) -C gitweb install
2574endif
2575ifndef NO_TCLTK
2576        $(MAKE) -C gitk-git install
2577        $(MAKE) -C git-gui gitexecdir='$(gitexec_instdir_SQ)' install
2578endif
2579ifneq (,$X)
2580        $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p' -ef '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p$X' || $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
2581endif
2582
2583        bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
2584        execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
2585        { test "$$bindir/" = "$$execdir/" || \
2586          for p in git$X $(filter $(install_bindir_programs),$(ALL_PROGRAMS)); do \
2587                $(RM) "$$execdir/$$p" && \
2588                test -z "$(NO_INSTALL_HARDLINKS)$(NO_CROSS_DIRECTORY_HARDLINKS)" && \
2589                ln "$$bindir/$$p" "$$execdir/$$p" 2>/dev/null || \
2590                cp "$$bindir/$$p" "$$execdir/$$p" || exit; \
2591          done; \
2592        } && \
2593        for p in $(filter $(install_bindir_programs),$(BUILT_INS)); do \
2594                $(RM) "$$bindir/$$p" && \
2595                test -z "$(NO_INSTALL_HARDLINKS)" && \
2596                ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
2597                ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
2598                cp "$$bindir/git$X" "$$bindir/$$p" || exit; \
2599        done && \
2600        for p in $(BUILT_INS); do \
2601                $(RM) "$$execdir/$$p" && \
2602                test -z "$(NO_INSTALL_HARDLINKS)" && \
2603                ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
2604                ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
2605                cp "$$execdir/git$X" "$$execdir/$$p" || exit; \
2606        done && \
2607        remote_curl_aliases="$(REMOTE_CURL_ALIASES)" && \
2608        for p in $$remote_curl_aliases; do \
2609                $(RM) "$$execdir/$$p" && \
2610                test -z "$(NO_INSTALL_HARDLINKS)" && \
2611                ln "$$execdir/git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
2612                ln -s "git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
2613                cp "$$execdir/git-remote-http$X" "$$execdir/$$p" || exit; \
2614        done && \
2615        ./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"
2616
2617.PHONY: install-gitweb install-doc install-man install-html install-info install-pdf
2618.PHONY: quick-install-doc quick-install-man quick-install-html
2619install-gitweb:
2620        $(MAKE) -C gitweb install
2621
2622install-doc:
2623        $(MAKE) -C Documentation install
2624
2625install-man:
2626        $(MAKE) -C Documentation install-man
2627
2628install-html:
2629        $(MAKE) -C Documentation install-html
2630
2631install-info:
2632        $(MAKE) -C Documentation install-info
2633
2634install-pdf:
2635        $(MAKE) -C Documentation install-pdf
2636
2637quick-install-doc:
2638        $(MAKE) -C Documentation quick-install
2639
2640quick-install-man:
2641        $(MAKE) -C Documentation quick-install-man
2642
2643quick-install-html:
2644        $(MAKE) -C Documentation quick-install-html
2645
2646
2647
2648### Maintainer's dist rules
2649
2650GIT_TARNAME = git-$(GIT_VERSION)
2651dist: git-archive$(X) configure
2652        ./git-archive --format=tar \
2653                --prefix=$(GIT_TARNAME)/ HEAD^{tree} > $(GIT_TARNAME).tar
2654        @mkdir -p $(GIT_TARNAME)
2655        @cp configure $(GIT_TARNAME)
2656        @echo $(GIT_VERSION) > $(GIT_TARNAME)/version
2657        @$(MAKE) -C git-gui TARDIR=../$(GIT_TARNAME)/git-gui dist-version
2658        $(TAR) rf $(GIT_TARNAME).tar \
2659                $(GIT_TARNAME)/configure \
2660                $(GIT_TARNAME)/version \
2661                $(GIT_TARNAME)/git-gui/version
2662        @$(RM) -r $(GIT_TARNAME)
2663        gzip -f -9 $(GIT_TARNAME).tar
2664
2665rpm::
2666        @echo >&2 "Use distro packaged sources to run rpmbuild"
2667        @false
2668.PHONY: rpm
2669
2670htmldocs = git-htmldocs-$(GIT_VERSION)
2671manpages = git-manpages-$(GIT_VERSION)
2672.PHONY: dist-doc distclean
2673dist-doc:
2674        $(RM) -r .doc-tmp-dir
2675        mkdir .doc-tmp-dir
2676        $(MAKE) -C Documentation WEBDOC_DEST=../.doc-tmp-dir install-webdoc
2677        cd .doc-tmp-dir && $(TAR) cf ../$(htmldocs).tar .
2678        gzip -n -9 -f $(htmldocs).tar
2679        :
2680        $(RM) -r .doc-tmp-dir
2681        mkdir -p .doc-tmp-dir/man1 .doc-tmp-dir/man5 .doc-tmp-dir/man7
2682        $(MAKE) -C Documentation DESTDIR=./ \
2683                man1dir=../.doc-tmp-dir/man1 \
2684                man5dir=../.doc-tmp-dir/man5 \
2685                man7dir=../.doc-tmp-dir/man7 \
2686                install
2687        cd .doc-tmp-dir && $(TAR) cf ../$(manpages).tar .
2688        gzip -n -9 -f $(manpages).tar
2689        $(RM) -r .doc-tmp-dir
2690
2691### Cleaning rules
2692
2693distclean: clean
2694        $(RM) configure
2695        $(RM) config.log config.status config.cache
2696        $(RM) config.mak.autogen config.mak.append
2697        $(RM) -r autom4te.cache
2698
2699profile-clean:
2700        $(RM) $(addsuffix *.gcda,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
2701        $(RM) $(addsuffix *.gcno,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
2702
2703clean: profile-clean coverage-clean
2704        $(RM) *.res
2705        $(RM) $(OBJECTS)
2706        $(RM) $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
2707        $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
2708        $(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
2709        $(RM) -r bin-wrappers $(dep_dirs)
2710        $(RM) -r po/build/
2711        $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h $(ETAGS_TARGET) tags cscope*
2712        $(RM) -r $(GIT_TARNAME) .doc-tmp-dir
2713        $(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
2714        $(RM) $(htmldocs).tar.gz $(manpages).tar.gz
2715        $(RM) contrib/coccinelle/*.cocci.patch*
2716        $(MAKE) -C Documentation/ clean
2717ifndef NO_PERL
2718        $(MAKE) -C gitweb clean
2719        $(MAKE) -C perl clean
2720endif
2721        $(MAKE) -C templates/ clean
2722        $(MAKE) -C t/ clean
2723ifndef NO_TCLTK
2724        $(MAKE) -C gitk-git clean
2725        $(MAKE) -C git-gui clean
2726endif
2727        $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
2728        $(RM) GIT-USER-AGENT GIT-PREFIX
2729        $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PYTHON-VARS
2730
2731.PHONY: all install profile-clean clean strip
2732.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
2733.PHONY: FORCE cscope
2734
2735### Check documentation
2736#
2737ALL_COMMANDS = $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS)
2738ALL_COMMANDS += git
2739ALL_COMMANDS += gitk
2740ALL_COMMANDS += gitweb
2741ALL_COMMANDS += git-gui git-citool
2742
2743.PHONY: check-docs
2744check-docs::
2745        $(MAKE) -C Documentation lint-docs
2746        @(for v in $(ALL_COMMANDS); \
2747        do \
2748                case "$$v" in \
2749                git-merge-octopus | git-merge-ours | git-merge-recursive | \
2750                git-merge-resolve | git-merge-subtree | \
2751                git-fsck-objects | git-init-db | \
2752                git-remote-* | git-stage | \
2753                git-?*--?* ) continue ;; \
2754                esac ; \
2755                test -f "Documentation/$$v.txt" || \
2756                echo "no doc: $$v"; \
2757                sed -e '1,/^### command list/d' -e '/^#/d' command-list.txt | \
2758                grep -q "^$$v[  ]" || \
2759                case "$$v" in \
2760                git) ;; \
2761                *) echo "no link: $$v";; \
2762                esac ; \
2763        done; \
2764        ( \
2765                sed -e '1,/^### command list/d' \
2766                    -e '/^#/d' \
2767                    -e 's/[     ].*//' \
2768                    -e 's/^/listed /' command-list.txt; \
2769                $(MAKE) -C Documentation print-man1 | \
2770                grep '\.txt$$' | \
2771                sed -e 's|Documentation/|documented |' \
2772                    -e 's/\.txt//'; \
2773        ) | while read how cmd; \
2774        do \
2775                case " $(ALL_COMMANDS) " in \
2776                *" $$cmd "*)    ;; \
2777                *) echo "removed but $$how: $$cmd" ;; \
2778                esac; \
2779        done ) | sort
2780
2781### Make sure built-ins do not have dups and listed in git.c
2782#
2783check-builtins::
2784        ./check-builtins.sh
2785
2786### Test suite coverage testing
2787#
2788.PHONY: coverage coverage-clean coverage-compile coverage-test coverage-report
2789.PHONY: coverage-untested-functions cover_db cover_db_html
2790.PHONY: coverage-clean-results
2791
2792coverage:
2793        $(MAKE) coverage-test
2794        $(MAKE) coverage-untested-functions
2795
2796object_dirs := $(sort $(dir $(OBJECTS)))
2797coverage-clean-results:
2798        $(RM) $(addsuffix *.gcov,$(object_dirs))
2799        $(RM) $(addsuffix *.gcda,$(object_dirs))
2800        $(RM) coverage-untested-functions
2801        $(RM) -r cover_db/
2802        $(RM) -r cover_db_html/
2803
2804coverage-clean: coverage-clean-results
2805        $(RM) $(addsuffix *.gcno,$(object_dirs))
2806
2807COVERAGE_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
2808COVERAGE_LDFLAGS = $(CFLAGS)  -O0 -lgcov
2809GCOVFLAGS = --preserve-paths --branch-probabilities --all-blocks
2810
2811coverage-compile:
2812        $(MAKE) CFLAGS="$(COVERAGE_CFLAGS)" LDFLAGS="$(COVERAGE_LDFLAGS)" all
2813
2814coverage-test: coverage-clean-results coverage-compile
2815        $(MAKE) CFLAGS="$(COVERAGE_CFLAGS)" LDFLAGS="$(COVERAGE_LDFLAGS)" \
2816                DEFAULT_TEST_TARGET=test -j1 test
2817
2818coverage-report:
2819        $(QUIET_GCOV)for dir in $(object_dirs); do \
2820                $(GCOV) $(GCOVFLAGS) --object-directory=$$dir $$dir*.c || exit; \
2821        done
2822
2823coverage-untested-functions: coverage-report
2824        grep '^function.*called 0 ' *.c.gcov \
2825                | sed -e 's/\([^:]*\)\.gcov: *function \([^ ]*\) called.*/\1: \2/' \
2826                > coverage-untested-functions
2827
2828cover_db: coverage-report
2829        gcov2perl -db cover_db *.gcov
2830
2831cover_db_html: cover_db
2832        cover -report html -outputdir cover_db_html cover_db
2833