Makefileon commit Git.pm: Support for perl/ being built by a different compiler (8d7f586)
   1# The default target of this Makefile is...
   2all:
   3
   4# Define NO_OPENSSL environment variable if you do not have OpenSSL.
   5# This also implies MOZILLA_SHA1.
   6#
   7# Define NO_CURL if you do not have curl installed.  git-http-pull and
   8# git-http-push are not built, and you cannot use http:// and https://
   9# transports.
  10#
  11# Define CURLDIR=/foo/bar if your curl header and library files are in
  12# /foo/bar/include and /foo/bar/lib directories.
  13#
  14# Define NO_EXPAT if you do not have expat installed.  git-http-push is
  15# not built, and you cannot push using http:// and https:// transports.
  16#
  17# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
  18#
  19# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
  20# d_type in struct dirent (latest Cygwin -- will be fixed soonish).
  21#
  22# Define NO_STRCASESTR if you don't have strcasestr.
  23#
  24# Define NO_STRLCPY if you don't have strlcpy.
  25#
  26# Define NO_SETENV if you don't have setenv in the C library.
  27#
  28# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
  29# Enable it on Windows.  By default, symrefs are still used.
  30#
  31# Define PPC_SHA1 environment variable when running make to make use of
  32# a bundled SHA1 routine optimized for PowerPC.
  33#
  34# Define ARM_SHA1 environment variable when running make to make use of
  35# a bundled SHA1 routine optimized for ARM.
  36#
  37# Define MOZILLA_SHA1 environment variable when running make to make use of
  38# a bundled SHA1 routine coming from Mozilla. It is GPL'd and should be fast
  39# on non-x86 architectures (e.g. PowerPC), while the OpenSSL version (default
  40# choice) has very fast version optimized for i586.
  41#
  42# Define USE_PIC if you need the main git objects to be built with -fPIC
  43# in order to build and link perl/Git.so.  x86-64 seems to need this.
  44#
  45# Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin).
  46#
  47# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
  48#
  49# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
  50# Patrick Mauritz).
  51#
  52# Define NO_MMAP if you want to avoid mmap.
  53#
  54# Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3.
  55#
  56# Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
  57#
  58# Define NO_SOCKADDR_STORAGE if your platform does not have struct
  59# sockaddr_storage.
  60#
  61# Define NO_ICONV if your libc does not properly support iconv.
  62#
  63# Define NO_ACCURATE_DIFF if your diff program at least sometimes misses
  64# a missing newline at the end of the file.
  65#
  66# Define NO_PYTHON if you want to loose all benefits of the recursive merge.
  67#
  68# Define COLLISION_CHECK below if you believe that SHA1's
  69# 1461501637330902918203684832716283019655932542976 hashes do not give you
  70# sufficient guarantee that no collisions between objects will ever happen.
  71#
  72# Define USE_NSEC below if you want git to care about sub-second file mtimes
  73# and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and
  74# it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely
  75# randomly break unless your underlying filesystem supports those sub-second
  76# times (my ext3 doesn't).
  77#
  78# Define USE_STDEV below if you want git to care about the underlying device
  79# change being considered an inode change from the update-cache perspective.
  80
  81GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
  82        @$(SHELL_PATH) ./GIT-VERSION-GEN
  83-include GIT-VERSION-FILE
  84
  85uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
  86uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
  87uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
  88uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
  89uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
  90
  91# CFLAGS and LDFLAGS are for the users to override from the command line.
  92
  93CFLAGS = -g -O2 -Wall
  94LDFLAGS =
  95ALL_CFLAGS = $(CFLAGS)
  96ALL_LDFLAGS = $(LDFLAGS)
  97STRIP ?= strip
  98
  99prefix = $(HOME)
 100bindir = $(prefix)/bin
 101gitexecdir = $(bindir)
 102template_dir = $(prefix)/share/git-core/templates/
 103GIT_PYTHON_DIR = $(prefix)/share/git-core/python
 104# DESTDIR=
 105
 106CC = gcc
 107AR = ar
 108TAR = tar
 109INSTALL = install
 110RPMBUILD = rpmbuild
 111
 112# sparse is architecture-neutral, which means that we need to tell it
 113# explicitly what architecture to check for. Fix this up for yours..
 114SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
 115
 116
 117
 118### --- END CONFIGURATION SECTION ---
 119
 120# Those must not be GNU-specific; they are shared with perl/ which may
 121# be built by a different compiler.
 122BASIC_CFLAGS =
 123BASIC_LDFLAGS =
 124
 125SCRIPT_SH = \
 126        git-bisect.sh git-branch.sh git-checkout.sh \
 127        git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
 128        git-fetch.sh \
 129        git-ls-remote.sh \
 130        git-merge-one-file.sh git-parse-remote.sh \
 131        git-prune.sh git-pull.sh git-rebase.sh \
 132        git-repack.sh git-request-pull.sh git-reset.sh \
 133        git-resolve.sh git-revert.sh git-sh-setup.sh \
 134        git-tag.sh git-verify-tag.sh \
 135        git-applymbox.sh git-applypatch.sh git-am.sh \
 136        git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 137        git-merge-resolve.sh git-merge-ours.sh \
 138        git-lost-found.sh git-quiltimport.sh
 139
 140SCRIPT_PERL = \
 141        git-archimport.perl git-cvsimport.perl git-relink.perl \
 142        git-shortlog.perl git-fmt-merge-msg.perl git-rerere.perl \
 143        git-annotate.perl git-cvsserver.perl \
 144        git-svnimport.perl git-mv.perl git-cvsexportcommit.perl \
 145        git-send-email.perl
 146
 147SCRIPT_PYTHON = \
 148        git-merge-recursive.py
 149
 150SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
 151          $(patsubst %.perl,%,$(SCRIPT_PERL)) \
 152          $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
 153          git-cherry-pick git-status
 154
 155# The ones that do not have to link with lcrypto, lz nor xdiff.
 156SIMPLE_PROGRAMS = \
 157        git-daemon$X
 158
 159# ... and all the rest that could be moved out of bindir to gitexecdir
 160PROGRAMS = \
 161        git-checkout-index$X \
 162        git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
 163        git-hash-object$X git-index-pack$X git-local-fetch$X \
 164        git-merge-base$X \
 165        git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
 166        git-peek-remote$X git-prune-packed$X git-receive-pack$X \
 167        git-send-pack$X git-shell$X \
 168        git-show-index$X git-ssh-fetch$X \
 169        git-ssh-upload$X git-unpack-file$X \
 170        git-unpack-objects$X git-update-server-info$X \
 171        git-upload-pack$X git-verify-pack$X \
 172        git-symbolic-ref$X \
 173        git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
 174        git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
 175
 176BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
 177        git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
 178        git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
 179        git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
 180        git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
 181        git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
 182        git-read-tree$X git-commit-tree$X git-write-tree$X \
 183        git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
 184        git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
 185
 186# what 'all' will build and 'install' will install, in gitexecdir
 187ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
 188
 189# Backward compatibility -- to be removed after 1.0
 190PROGRAMS += git-ssh-pull$X git-ssh-push$X
 191
 192# Set paths to tools early so that they can be used for version tests.
 193ifndef SHELL_PATH
 194        SHELL_PATH = /bin/sh
 195endif
 196ifndef PERL_PATH
 197        PERL_PATH = /usr/bin/perl
 198endif
 199ifndef PYTHON_PATH
 200        PYTHON_PATH = /usr/bin/python
 201endif
 202
 203PYMODULES = \
 204        gitMergeCommon.py
 205
 206LIB_FILE=libgit.a
 207XDIFF_LIB=xdiff/lib.a
 208
 209LIB_H = \
 210        blob.h cache.h commit.h csum-file.h delta.h \
 211        diff.h object.h pack.h pkt-line.h quote.h refs.h \
 212        run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
 213        tree-walk.h log-tree.h dir.h
 214
 215DIFF_OBJS = \
 216        diff.o diff-lib.o diffcore-break.o diffcore-order.o \
 217        diffcore-pickaxe.o diffcore-rename.o tree-diff.o combine-diff.o \
 218        diffcore-delta.o log-tree.o
 219
 220LIB_OBJS = \
 221        blob.o commit.o connect.o csum-file.o cache-tree.o base85.o \
 222        date.o diff-delta.o entry.o exec_cmd.o ident.o lockfile.o \
 223        object.o pack-check.o patch-delta.o path.o pkt-line.o \
 224        quote.o read-cache.o refs.o run-command.o dir.o object-refs.o \
 225        server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
 226        tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
 227        fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
 228        alloc.o $(DIFF_OBJS)
 229
 230BUILTIN_OBJS = \
 231        builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
 232        builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
 233        builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
 234        builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
 235        builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
 236        builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
 237        builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
 238        builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
 239        builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \
 240        builtin-update-ref.o
 241
 242GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
 243EXTLIBS = -lz
 244
 245#
 246# Platform specific tweaks
 247#
 248
 249# We choose to avoid "if .. else if .. else .. endif endif"
 250# because maintaining the nesting to match is a pain.  If
 251# we had "elif" things would have been much nicer...
 252
 253ifeq ($(uname_S),Linux)
 254        NO_STRLCPY = YesPlease
 255endif
 256ifeq ($(uname_S),Darwin)
 257        NEEDS_SSL_WITH_CRYPTO = YesPlease
 258        NEEDS_LIBICONV = YesPlease
 259        NO_STRLCPY = YesPlease
 260        ## fink
 261        ifeq ($(shell test -d /sw/lib && echo y),y)
 262                BASIC_CFLAGS += -I/sw/include
 263                BASIC_LDFLAGS += -L/sw/lib
 264        endif
 265        ## darwinports
 266        ifeq ($(shell test -d /opt/local/lib && echo y),y)
 267                BASIC_CFLAGS += -I/opt/local/include
 268                BASIC_LDFLAGS += -L/opt/local/lib
 269        endif
 270endif
 271ifeq ($(uname_S),SunOS)
 272        NEEDS_SOCKET = YesPlease
 273        NEEDS_NSL = YesPlease
 274        SHELL_PATH = /bin/bash
 275        NO_STRCASESTR = YesPlease
 276        NO_STRLCPY = YesPlease
 277        ifeq ($(uname_R),5.8)
 278                NEEDS_LIBICONV = YesPlease
 279                NO_UNSETENV = YesPlease
 280                NO_SETENV = YesPlease
 281        endif
 282        ifeq ($(uname_R),5.9)
 283                NO_UNSETENV = YesPlease
 284                NO_SETENV = YesPlease
 285        endif
 286        INSTALL = ginstall
 287        TAR = gtar
 288        BASIC_CFLAGS += -D__EXTENSIONS__
 289endif
 290ifeq ($(uname_O),Cygwin)
 291        NO_D_TYPE_IN_DIRENT = YesPlease
 292        NO_D_INO_IN_DIRENT = YesPlease
 293        NO_STRCASESTR = YesPlease
 294        NO_STRLCPY = YesPlease
 295        NO_SYMLINK_HEAD = YesPlease
 296        NEEDS_LIBICONV = YesPlease
 297        # There are conflicting reports about this.
 298        # On some boxes NO_MMAP is needed, and not so elsewhere.
 299        # Try uncommenting this if you see things break -- YMMV.
 300        # NO_MMAP = YesPlease
 301        NO_IPV6 = YesPlease
 302        X = .exe
 303endif
 304ifeq ($(uname_S),FreeBSD)
 305        NEEDS_LIBICONV = YesPlease
 306        BASIC_CFLAGS += -I/usr/local/include
 307        BASIC_LDFLAGS += -L/usr/local/lib
 308endif
 309ifeq ($(uname_S),OpenBSD)
 310        NO_STRCASESTR = YesPlease
 311        NEEDS_LIBICONV = YesPlease
 312        BASIC_CFLAGS += -I/usr/local/include
 313        BASIC_LDFLAGS += -L/usr/local/lib
 314endif
 315ifeq ($(uname_S),NetBSD)
 316        ifeq ($(shell expr "$(uname_R)" : '[01]\.'),2)
 317                NEEDS_LIBICONV = YesPlease
 318        endif
 319        BASIC_CFLAGS += -I/usr/pkg/include
 320        BASIC_LDFLAGS += -L/usr/pkg/lib
 321        ALL_LDFLAGS += -Wl,-rpath,/usr/pkg/lib
 322endif
 323ifeq ($(uname_S),AIX)
 324        NO_STRCASESTR=YesPlease
 325        NO_STRLCPY = YesPlease
 326        NEEDS_LIBICONV=YesPlease
 327endif
 328ifeq ($(uname_S),IRIX64)
 329        NO_IPV6=YesPlease
 330        NO_SETENV=YesPlease
 331        NO_STRCASESTR=YesPlease
 332        NO_STRLCPY = YesPlease
 333        NO_SOCKADDR_STORAGE=YesPlease
 334        SHELL_PATH=/usr/gnu/bin/bash
 335        BASIC_CFLAGS += -DPATH_MAX=1024
 336        # for now, build 32-bit version
 337        BASIC_LDFLAGS += -L/usr/lib32
 338endif
 339ifneq (,$(findstring arm,$(uname_M)))
 340        ARM_SHA1 = YesPlease
 341endif
 342
 343-include config.mak
 344
 345ifdef WITH_OWN_SUBPROCESS_PY
 346        PYMODULES += compat/subprocess.py
 347else
 348        ifeq ($(NO_PYTHON),)
 349                ifneq ($(shell $(PYTHON_PATH) -c 'import subprocess;print"OK"' 2>/dev/null),OK)
 350                        PYMODULES += compat/subprocess.py
 351                endif
 352        endif
 353endif
 354
 355ifndef NO_CURL
 356        ifdef CURLDIR
 357                # This is still problematic -- gcc does not always want -R.
 358                BASIC_CFLAGS += -I$(CURLDIR)/include
 359                CURL_LIBCURL = -L$(CURLDIR)/lib -R$(CURLDIR)/lib -lcurl
 360        else
 361                CURL_LIBCURL = -lcurl
 362        endif
 363        PROGRAMS += git-http-fetch$X
 364        curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p)
 365        ifeq "$(curl_check)" "070908"
 366                ifndef NO_EXPAT
 367                        PROGRAMS += git-http-push$X
 368                endif
 369        endif
 370        ifndef NO_EXPAT
 371                EXPAT_LIBEXPAT = -lexpat
 372        endif
 373endif
 374
 375ifndef NO_OPENSSL
 376        OPENSSL_LIBSSL = -lssl
 377        ifdef OPENSSLDIR
 378                # Again this may be problematic -- gcc does not always want -R.
 379                BASIC_CFLAGS += -I$(OPENSSLDIR)/include
 380                OPENSSL_LINK = -L$(OPENSSLDIR)/lib -R$(OPENSSLDIR)/lib
 381        else
 382                OPENSSL_LINK =
 383        endif
 384else
 385        BASIC_CFLAGS += -DNO_OPENSSL
 386        MOZILLA_SHA1 = 1
 387        OPENSSL_LIBSSL =
 388endif
 389ifdef NEEDS_SSL_WITH_CRYPTO
 390        LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto -lssl
 391else
 392        LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto
 393endif
 394ifdef NEEDS_LIBICONV
 395        ifdef ICONVDIR
 396                # Again this may be problematic -- gcc does not always want -R.
 397                BASIC_CFLAGS += -I$(ICONVDIR)/include
 398                ICONV_LINK = -L$(ICONVDIR)/lib -R$(ICONVDIR)/lib
 399        else
 400                ICONV_LINK =
 401        endif
 402        EXTLIBS += $(ICONV_LINK) -liconv
 403endif
 404ifdef NEEDS_SOCKET
 405        EXTLIBS += -lsocket
 406        SIMPLE_LIB += -lsocket
 407endif
 408ifdef NEEDS_NSL
 409        EXTLIBS += -lnsl
 410        SIMPLE_LIB += -lnsl
 411endif
 412ifdef NO_D_TYPE_IN_DIRENT
 413        BASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT
 414endif
 415ifdef NO_D_INO_IN_DIRENT
 416        BASIC_CFLAGS += -DNO_D_INO_IN_DIRENT
 417endif
 418ifdef NO_SYMLINK_HEAD
 419        BASIC_CFLAGS += -DNO_SYMLINK_HEAD
 420endif
 421ifdef NO_STRCASESTR
 422        COMPAT_CFLAGS += -DNO_STRCASESTR
 423        COMPAT_OBJS += compat/strcasestr.o
 424endif
 425ifdef NO_STRLCPY
 426        COMPAT_CFLAGS += -DNO_STRLCPY
 427        COMPAT_OBJS += compat/strlcpy.o
 428endif
 429ifdef NO_SETENV
 430        COMPAT_CFLAGS += -DNO_SETENV
 431        COMPAT_OBJS += compat/setenv.o
 432endif
 433ifdef NO_SETENV
 434        COMPAT_CFLAGS += -DNO_UNSETENV
 435        COMPAT_OBJS += compat/unsetenv.o
 436endif
 437ifdef NO_MMAP
 438        COMPAT_CFLAGS += -DNO_MMAP
 439        COMPAT_OBJS += compat/mmap.o
 440endif
 441ifdef NO_IPV6
 442        BASIC_CFLAGS += -DNO_IPV6
 443endif
 444ifdef NO_SOCKADDR_STORAGE
 445ifdef NO_IPV6
 446        BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in
 447else
 448        BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in6
 449endif
 450endif
 451ifdef NO_INET_NTOP
 452        LIB_OBJS += compat/inet_ntop.o
 453endif
 454
 455ifdef NO_ICONV
 456        BASIC_CFLAGS += -DNO_ICONV
 457endif
 458
 459ifdef PPC_SHA1
 460        SHA1_HEADER = "ppc/sha1.h"
 461        LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
 462else
 463ifdef ARM_SHA1
 464        SHA1_HEADER = "arm/sha1.h"
 465        LIB_OBJS += arm/sha1.o arm/sha1_arm.o
 466else
 467ifdef MOZILLA_SHA1
 468        SHA1_HEADER = "mozilla-sha1/sha1.h"
 469        LIB_OBJS += mozilla-sha1/sha1.o
 470else
 471        SHA1_HEADER = <openssl/sha.h>
 472        EXTLIBS += $(LIB_4_CRYPTO)
 473endif
 474endif
 475endif
 476ifdef USE_PIC
 477        ALL_CFLAGS += -fPIC
 478endif
 479ifdef NO_ACCURATE_DIFF
 480        BASIC_CFLAGS += -DNO_ACCURATE_DIFF
 481endif
 482
 483# Shell quote (do not use $(call) to accomodate ancient setups);
 484
 485SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
 486
 487DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
 488bindir_SQ = $(subst ','\'',$(bindir))
 489gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 490template_dir_SQ = $(subst ','\'',$(template_dir))
 491prefix_SQ = $(subst ','\'',$(prefix))
 492
 493SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 494PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 495PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
 496GIT_PYTHON_DIR_SQ = $(subst ','\'',$(GIT_PYTHON_DIR))
 497
 498LIBS = $(GITLIBS) $(EXTLIBS)
 499
 500BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' $(COMPAT_CFLAGS)
 501LIB_OBJS += $(COMPAT_OBJS)
 502
 503ALL_CFLAGS += $(BASIC_CFLAGS)
 504ALL_LDFLAGS += $(BASIC_LDFLAGS)
 505
 506export prefix TAR INSTALL DESTDIR SHELL_PATH template_dir
 507
 508
 509### Build rules
 510
 511all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk
 512
 513all: perl/Makefile
 514        $(MAKE) -C perl
 515        $(MAKE) -C templates
 516
 517strip: $(PROGRAMS) git$X
 518        $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
 519
 520git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS
 521        $(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
 522                $(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
 523                $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
 524
 525builtin-help.o: common-cmds.h
 526
 527$(BUILT_INS): git$X
 528        rm -f $@ && ln git$X $@
 529
 530common-cmds.h: Documentation/git-*.txt
 531        ./generate-cmdlist.sh > $@+
 532        mv $@+ $@
 533
 534$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
 535        rm -f $@ $@+
 536        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 537            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 538            -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
 539            -e 's/@@NO_PYTHON@@/$(NO_PYTHON)/g' \
 540            $@.sh >$@+
 541        chmod +x $@+
 542        mv $@+ $@
 543
 544$(patsubst %.perl,%,$(SCRIPT_PERL)): perl/Makefile
 545$(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
 546        rm -f $@ $@+
 547        INSTLIBDIR=`make -s -C perl instlibdir` && \
 548        sed -e '1s|#!.*perl\(.*\)|#!$(PERL_PATH_SQ)\1|' \
 549            -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
 550            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 551            $@.perl >$@+
 552        chmod +x $@+
 553        mv $@+ $@
 554
 555$(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py GIT-CFLAGS
 556        rm -f $@ $@+
 557        sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
 558            -e 's|@@GIT_PYTHON_PATH@@|$(GIT_PYTHON_DIR_SQ)|g' \
 559            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 560            $@.py >$@+
 561        chmod +x $@+
 562        mv $@+ $@
 563
 564git-cherry-pick: git-revert
 565        cp $< $@+
 566        mv $@+ $@
 567
 568git-status: git-commit
 569        cp $< $@+
 570        mv $@+ $@
 571
 572# These can record GIT_VERSION
 573git$X git.spec \
 574        $(patsubst %.sh,%,$(SCRIPT_SH)) \
 575        $(patsubst %.perl,%,$(SCRIPT_PERL)) \
 576        $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
 577        : GIT-VERSION-FILE
 578
 579%.o: %.c GIT-CFLAGS
 580        $(CC) -o $*.o -c $(ALL_CFLAGS) $<
 581%.o: %.S
 582        $(CC) -o $*.o -c $(ALL_CFLAGS) $<
 583
 584exec_cmd.o: exec_cmd.c GIT-CFLAGS
 585        $(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $<
 586builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
 587        $(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
 588
 589http.o: http.c GIT-CFLAGS
 590        $(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<
 591
 592ifdef NO_EXPAT
 593http-fetch.o: http-fetch.c http.h GIT-CFLAGS
 594        $(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $<
 595endif
 596
 597git-%$X: %.o $(GITLIBS)
 598        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 599
 600$(SIMPLE_PROGRAMS) : $(LIB_FILE)
 601$(SIMPLE_PROGRAMS) : git-%$X : %.o
 602        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 603                $(LIB_FILE) $(SIMPLE_LIB)
 604
 605git-local-fetch$X: fetch.o
 606git-ssh-fetch$X: rsh.o fetch.o
 607git-ssh-upload$X: rsh.o
 608git-ssh-pull$X: rsh.o fetch.o
 609git-ssh-push$X: rsh.o
 610
 611git-imap-send$X: imap-send.o $(LIB_FILE)
 612
 613http.o http-fetch.o http-push.o: http.h
 614git-http-fetch$X: fetch.o http.o http-fetch.o $(LIB_FILE)
 615        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 616                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 617
 618git-http-push$X: revision.o http.o http-push.o $(LIB_FILE)
 619        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 620                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 621
 622$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
 623$(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
 624$(DIFF_OBJS): diffcore.h
 625
 626$(LIB_FILE): $(LIB_OBJS)
 627        rm -f $@ && $(AR) rcs $@ $(LIB_OBJS)
 628
 629XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o
 630
 631$(XDIFF_LIB): $(XDIFF_OBJS)
 632        rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS)
 633
 634
 635PERL_DEFINE = $(BASIC_CFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"'
 636PERL_DEFINE_SQ = $(subst ','\'',$(PERL_DEFINE))
 637PERL_LIBS = $(BASIC_LDFLAGS) $(EXTLIBS)
 638PERL_LIBS_SQ = $(subst ','\'',$(PERL_LIBS))
 639perl/Makefile: perl/Git.pm perl/Makefile.PL GIT-CFLAGS
 640        (cd perl && $(PERL_PATH) Makefile.PL \
 641                PREFIX='$(prefix_SQ)' \
 642                DEFINE='$(PERL_DEFINE_SQ)' \
 643                LIBS='$(PERL_LIBS_SQ)')
 644
 645doc:
 646        $(MAKE) -C Documentation all
 647
 648TAGS:
 649        rm -f TAGS
 650        find . -name '*.[hcS]' -print | xargs etags -a
 651
 652tags:
 653        rm -f tags
 654        find . -name '*.[hcS]' -print | xargs ctags -a
 655
 656### Detect prefix changes
 657TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):$(GIT_PYTHON_DIR_SQ):\
 658             $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
 659
 660GIT-CFLAGS: .FORCE-GIT-CFLAGS
 661        @FLAGS='$(TRACK_CFLAGS)'; \
 662            if test x"$$FLAGS" != x"`cat GIT-CFLAGS 2>/dev/null`" ; then \
 663                echo 1>&2 "    * new build flags or prefix"; \
 664                echo "$$FLAGS" >GIT-CFLAGS; \
 665            fi
 666
 667### Testing rules
 668
 669# GNU make supports exporting all variables by "export" without parameters.
 670# However, the environment gets quite big, and some programs have problems
 671# with that.
 672
 673export NO_PYTHON
 674
 675test: all
 676        $(MAKE) -C t/ all
 677
 678test-date$X: test-date.c date.o ctype.o
 679        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) test-date.c date.o ctype.o
 680
 681test-delta$X: test-delta.c diff-delta.o patch-delta.o
 682        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^
 683
 684test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
 685        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 686
 687check:
 688        for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done
 689
 690
 691
 692### Installation rules
 693
 694install: all
 695        $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(bindir_SQ)'
 696        $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
 697        $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
 698        $(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)'
 699        $(MAKE) -C templates install
 700        $(MAKE) -C perl install
 701        $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'
 702        $(INSTALL) $(PYMODULES) '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'
 703        if test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \
 704        then \
 705                ln -f '$(DESTDIR_SQ)$(bindir_SQ)/git$X' \
 706                        '$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X' || \
 707                cp '$(DESTDIR_SQ)$(bindir_SQ)/git$X' \
 708                        '$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X'; \
 709        fi
 710        $(foreach p,$(BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;)
 711
 712install-doc:
 713        $(MAKE) -C Documentation install
 714
 715
 716
 717
 718### Maintainer's dist rules
 719
 720git.spec: git.spec.in
 721        sed -e 's/@@VERSION@@/$(GIT_VERSION)/g' < $< > $@+
 722        mv $@+ $@
 723
 724GIT_TARNAME=git-$(GIT_VERSION)
 725dist: git.spec git-tar-tree
 726        ./git-tar-tree HEAD^{tree} $(GIT_TARNAME) > $(GIT_TARNAME).tar
 727        @mkdir -p $(GIT_TARNAME)
 728        @cp git.spec $(GIT_TARNAME)
 729        @echo $(GIT_VERSION) > $(GIT_TARNAME)/version
 730        $(TAR) rf $(GIT_TARNAME).tar \
 731                $(GIT_TARNAME)/git.spec $(GIT_TARNAME)/version
 732        @rm -rf $(GIT_TARNAME)
 733        gzip -f -9 $(GIT_TARNAME).tar
 734
 735rpm: dist
 736        $(RPMBUILD) -ta $(GIT_TARNAME).tar.gz
 737
 738htmldocs = git-htmldocs-$(GIT_VERSION)
 739manpages = git-manpages-$(GIT_VERSION)
 740dist-doc:
 741        rm -fr .doc-tmp-dir
 742        mkdir .doc-tmp-dir
 743        $(MAKE) -C Documentation WEBDOC_DEST=../.doc-tmp-dir install-webdoc
 744        cd .doc-tmp-dir && $(TAR) cf ../$(htmldocs).tar .
 745        gzip -n -9 -f $(htmldocs).tar
 746        :
 747        rm -fr .doc-tmp-dir
 748        mkdir .doc-tmp-dir .doc-tmp-dir/man1 .doc-tmp-dir/man7
 749        $(MAKE) -C Documentation DESTDIR=./ \
 750                man1=../.doc-tmp-dir/man1 \
 751                man7=../.doc-tmp-dir/man7 \
 752                install
 753        cd .doc-tmp-dir && $(TAR) cf ../$(manpages).tar .
 754        gzip -n -9 -f $(manpages).tar
 755        rm -fr .doc-tmp-dir
 756
 757### Cleaning rules
 758
 759clean:
 760        rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
 761                $(LIB_FILE) $(XDIFF_LIB)
 762        rm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X
 763        rm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags
 764        rm -rf $(GIT_TARNAME) .doc-tmp-dir
 765        rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
 766        rm -f $(htmldocs).tar.gz $(manpages).tar.gz
 767        $(MAKE) -C Documentation/ clean
 768        [ ! -f perl/Makefile ] || $(MAKE) -C perl/ clean || $(MAKE) -C perl/ clean
 769        $(MAKE) -C templates/ clean
 770        $(MAKE) -C t/ clean
 771        rm -f GIT-VERSION-FILE GIT-CFLAGS
 772
 773.PHONY: all install clean strip
 774.PHONY: .FORCE-GIT-VERSION-FILE TAGS tags .FORCE-GIT-CFLAGS
 775
 776### Check documentation
 777#
 778check-docs::
 779        @for v in $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk; \
 780        do \
 781                case "$$v" in \
 782                git-merge-octopus | git-merge-ours | git-merge-recursive | \
 783                git-merge-resolve | git-merge-stupid | \
 784                git-ssh-pull | git-ssh-push ) continue ;; \
 785                esac ; \
 786                test -f "Documentation/$$v.txt" || \
 787                echo "no doc: $$v"; \
 788                grep -q "^gitlink:$$v\[[0-9]\]::" Documentation/git.txt || \
 789                case "$$v" in \
 790                git) ;; \
 791                *) echo "no link: $$v";; \
 792                esac ; \
 793        done | sort