a291bb157ec9eb14037bcc2a2f7b238527dc7adb
   1# The default target of this Makefile is...
   2all:
   3
   4# Define MOZILLA_SHA1 environment variable when running make to make use of
   5# a bundled SHA1 routine coming from Mozilla. It is GPL'd and should be fast
   6# on non-x86 architectures (e.g. PowerPC), while the OpenSSL version (default
   7# choice) has very fast version optimized for i586.
   8#
   9# Define NO_OPENSSL environment variable if you do not have OpenSSL. You will
  10# miss out git-rev-list --merge-order. This also implies MOZILLA_SHA1.
  11#
  12# Define NO_CURL if you do not have curl installed.  git-http-pull and
  13# git-http-push are not built, and you cannot use http:// and https://
  14# transports.
  15#
  16# Define CURLDIR=/foo/bar if your curl header and library files are in
  17# /foo/bar/include and /foo/bar/lib directories.
  18#
  19# Define NO_EXPAT if you do not have expat installed.  git-http-push is
  20# not built, and you cannot push using http:// and https:// transports.
  21#
  22# Define NO_STRCASESTR if you don't have strcasestr.
  23#
  24# Define NO_SETENV if you don't have setenv in the C library.
  25#
  26# Define USE_SYMLINK_HEAD if you want .git/HEAD to be a symbolic link.
  27# Don't enable it on Windows.
  28#
  29# Define PPC_SHA1 environment variable when running make to make use of
  30# a bundled SHA1 routine optimized for PowerPC.
  31#
  32# Define ARM_SHA1 environment variable when running make to make use of
  33# a bundled SHA1 routine optimized for ARM.
  34#
  35# Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin).
  36#
  37# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
  38#
  39# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
  40# Patrick Mauritz).
  41#
  42# Define NO_MMAP if you want to avoid mmap.
  43#
  44# Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3.
  45#
  46# Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
  47#
  48# Define COLLISION_CHECK below if you believe that SHA1's
  49# 1461501637330902918203684832716283019655932542976 hashes do not give you
  50# sufficient guarantee that no collisions between objects will ever happen.
  51
  52# Define USE_NSEC below if you want git to care about sub-second file mtimes
  53# and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and
  54# it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely
  55# randomly break unless your underlying filesystem supports those sub-second
  56# times (my ext3 doesn't).
  57
  58# Define USE_STDEV below if you want git to care about the underlying device
  59# change being considered an inode change from the update-cache perspective.
  60
  61GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
  62        @sh ./GIT-VERSION-GEN
  63-include GIT-VERSION-FILE
  64
  65# CFLAGS and LDFLAGS are for the users to override from the command line.
  66
  67CFLAGS = -g -O2 -Wall
  68LDFLAGS =
  69ALL_CFLAGS = $(CFLAGS)
  70ALL_LDFLAGS = $(LDFLAGS)
  71STRIP ?= strip
  72
  73prefix = $(HOME)
  74bindir = $(prefix)/bin
  75gitexecdir = $(prefix)/bin
  76template_dir = $(prefix)/share/git-core/templates/
  77GIT_PYTHON_DIR = $(prefix)/share/git-core/python
  78# DESTDIR=
  79
  80CC = gcc
  81AR = ar
  82TAR = tar
  83INSTALL = install
  84RPMBUILD = rpmbuild
  85
  86# sparse is architecture-neutral, which means that we need to tell it
  87# explicitly what architecture to check for. Fix this up for yours..
  88SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
  89
  90
  91
  92### --- END CONFIGURATION SECTION ---
  93
  94SCRIPT_SH = \
  95        git-add.sh git-bisect.sh git-branch.sh git-checkout.sh \
  96        git-cherry.sh git-clone.sh git-commit.sh \
  97        git-count-objects.sh git-diff.sh git-fetch.sh \
  98        git-format-patch.sh git-log.sh git-ls-remote.sh \
  99        git-merge-one-file.sh git-parse-remote.sh \
 100        git-prune.sh git-pull.sh git-push.sh git-rebase.sh \
 101        git-repack.sh git-request-pull.sh git-reset.sh \
 102        git-resolve.sh git-revert.sh git-sh-setup.sh git-status.sh \
 103        git-tag.sh git-verify-tag.sh git-whatchanged.sh \
 104        git-applymbox.sh git-applypatch.sh git-am.sh \
 105        git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 106        git-merge-resolve.sh git-merge-ours.sh git-grep.sh \
 107        git-lost-found.sh
 108
 109SCRIPT_PERL = \
 110        git-archimport.perl git-cvsimport.perl git-relink.perl \
 111        git-shortlog.perl git-fmt-merge-msg.perl \
 112        git-svnimport.perl git-mv.perl git-cvsexportcommit.perl
 113
 114SCRIPT_PYTHON = \
 115        git-merge-recursive.py
 116
 117SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
 118          $(patsubst %.perl,%,$(SCRIPT_PERL)) \
 119          $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
 120          git-cherry-pick
 121
 122# The ones that do not have to link with lcrypto nor lz.
 123SIMPLE_PROGRAMS = \
 124        git-get-tar-commit-id$X git-mailinfo$X git-mailsplit$X \
 125        git-stripspace$X git-daemon$X
 126
 127# ... and all the rest that could be moved out of bindir to gitexecdir
 128PROGRAMS = \
 129        git-apply$X git-cat-file$X \
 130        git-checkout-index$X git-clone-pack$X git-commit-tree$X \
 131        git-convert-objects$X git-diff-files$X \
 132        git-diff-index$X git-diff-stages$X \
 133        git-diff-tree$X git-fetch-pack$X git-fsck-objects$X \
 134        git-hash-object$X git-index-pack$X git-init-db$X \
 135        git-local-fetch$X git-ls-files$X git-ls-tree$X git-merge-base$X \
 136        git-merge-index$X git-mktag$X git-pack-objects$X git-patch-id$X \
 137        git-peek-remote$X git-prune-packed$X git-read-tree$X \
 138        git-receive-pack$X git-rev-list$X git-rev-parse$X \
 139        git-send-pack$X git-show-branch$X git-shell$X \
 140        git-show-index$X git-ssh-fetch$X \
 141        git-ssh-upload$X git-tar-tree$X git-unpack-file$X \
 142        git-unpack-objects$X git-update-index$X git-update-server-info$X \
 143        git-upload-pack$X git-verify-pack$X git-write-tree$X \
 144        git-update-ref$X git-symbolic-ref$X git-check-ref-format$X \
 145        git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
 146        git-describe$X
 147
 148# what 'all' will build and 'install' will install, in gitexecdir
 149ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
 150
 151# Backward compatibility -- to be removed after 1.0
 152PROGRAMS += git-ssh-pull$X git-ssh-push$X
 153
 154# Set paths to tools early so that they can be used for version tests.
 155ifndef SHELL_PATH
 156        SHELL_PATH = /bin/sh
 157endif
 158ifndef PERL_PATH
 159        PERL_PATH = /usr/bin/perl
 160endif
 161ifndef PYTHON_PATH
 162        PYTHON_PATH = /usr/bin/python
 163endif
 164
 165PYMODULES = \
 166        gitMergeCommon.py
 167
 168LIB_FILE=libgit.a
 169
 170LIB_H = \
 171        blob.h cache.h commit.h count-delta.h csum-file.h delta.h \
 172        diff.h epoch.h object.h pack.h pkt-line.h quote.h refs.h \
 173        run-command.h strbuf.h tag.h tree.h git-compat-util.h
 174
 175DIFF_OBJS = \
 176        diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
 177        diffcore-pickaxe.o diffcore-rename.o tree-diff.o
 178
 179LIB_OBJS = \
 180        blob.o commit.o connect.o count-delta.o csum-file.o \
 181        date.o diff-delta.o entry.o exec_cmd.o ident.o index.o \
 182        object.o pack-check.o patch-delta.o path.o pkt-line.o \
 183        quote.o read-cache.o refs.o run-command.o \
 184        server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
 185        tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
 186        fetch-clone.o \
 187        $(DIFF_OBJS)
 188
 189LIBS = $(LIB_FILE)
 190LIBS += -lz
 191
 192# Shell quote;
 193# Result of this needs to be placed inside ''
 194shq = $(subst ','\'',$(1))
 195# This has surrounding ''
 196shellquote = '$(call shq,$(1))'
 197
 198#
 199# Platform specific tweaks
 200#
 201
 202# We choose to avoid "if .. else if .. else .. endif endif"
 203# because maintaining the nesting to match is a pain.  If
 204# we had "elif" things would have been much nicer...
 205uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
 206uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
 207uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
 208uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
 209
 210ifeq ($(uname_S),Darwin)
 211        NEEDS_SSL_WITH_CRYPTO = YesPlease
 212        NEEDS_LIBICONV = YesPlease
 213        ## fink
 214        ALL_CFLAGS += -I/sw/include
 215        ALL_LDFLAGS += -L/sw/lib
 216        ## darwinports
 217        ALL_CFLAGS += -I/opt/local/include
 218        ALL_LDFLAGS += -L/opt/local/lib
 219endif
 220ifeq ($(uname_S),SunOS)
 221        NEEDS_SOCKET = YesPlease
 222        NEEDS_NSL = YesPlease
 223        NEEDS_LIBICONV = YesPlease
 224        SHELL_PATH = /bin/bash
 225        NO_STRCASESTR = YesPlease
 226        ifeq ($(uname_R),5.8)
 227                NO_SETENV = YesPlease
 228        endif
 229        INSTALL = ginstall
 230        TAR = gtar
 231        ALL_CFLAGS += -D__EXTENSIONS__
 232endif
 233ifeq ($(uname_O),Cygwin)
 234        NO_STRCASESTR = YesPlease
 235        NEEDS_LIBICONV = YesPlease
 236        # There are conflicting reports about this.
 237        # On some boxes NO_MMAP is needed, and not so elsewhere.
 238        # Try uncommenting this if you see things break -- YMMV.
 239        # NO_MMAP = YesPlease
 240        NO_IPV6 = YesPlease
 241        X = .exe
 242endif
 243ifeq ($(uname_S),OpenBSD)
 244        NO_STRCASESTR = YesPlease
 245        NEEDS_LIBICONV = YesPlease
 246        ALL_CFLAGS += -I/usr/local/include
 247        ALL_LDFLAGS += -L/usr/local/lib
 248endif
 249ifeq ($(uname_S),NetBSD)
 250        NEEDS_LIBICONV = YesPlease
 251        ALL_CFLAGS += -I/usr/pkg/include
 252        ALL_LDFLAGS += -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib
 253endif
 254ifeq ($(uname_S),AIX)
 255        NO_STRCASESTR=YesPlease
 256        NEEDS_LIBICONV=YesPlease
 257endif
 258ifneq (,$(findstring arm,$(uname_M)))
 259        ARM_SHA1 = YesPlease
 260endif
 261
 262-include config.mak
 263
 264ifdef WITH_OWN_SUBPROCESS_PY
 265        PYMODULES += compat/subprocess.py
 266else
 267        ifneq ($(shell $(PYTHON_PATH) -c 'import subprocess;print"OK"' 2>/dev/null),OK)
 268                PYMODULES += compat/subprocess.py
 269        endif
 270endif
 271
 272ifdef WITH_SEND_EMAIL
 273        SCRIPT_PERL += git-send-email.perl
 274endif
 275
 276ifndef NO_CURL
 277        ifdef CURLDIR
 278                # This is still problematic -- gcc does not always want -R.
 279                ALL_CFLAGS += -I$(CURLDIR)/include
 280                CURL_LIBCURL = -L$(CURLDIR)/lib -R$(CURLDIR)/lib -lcurl
 281        else
 282                CURL_LIBCURL = -lcurl
 283        endif
 284        PROGRAMS += git-http-fetch$X
 285        curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p)
 286        ifeq "$(curl_check)" "070908"
 287                ifndef NO_EXPAT
 288                        EXPAT_LIBEXPAT = -lexpat
 289                        PROGRAMS += git-http-push$X
 290                endif
 291        endif
 292endif
 293
 294ifndef NO_OPENSSL
 295        LIB_OBJS += epoch.o
 296        OPENSSL_LIBSSL = -lssl
 297        ifdef OPENSSLDIR
 298                # Again this may be problematic -- gcc does not always want -R.
 299                ALL_CFLAGS += -I$(OPENSSLDIR)/include
 300                OPENSSL_LINK = -L$(OPENSSLDIR)/lib -R$(OPENSSLDIR)/lib
 301        else
 302                OPENSSL_LINK =
 303        endif
 304else
 305        ALL_CFLAGS += -DNO_OPENSSL
 306        MOZILLA_SHA1 = 1
 307        OPENSSL_LIBSSL =
 308endif
 309ifdef NEEDS_SSL_WITH_CRYPTO
 310        LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto -lssl
 311else
 312        LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto
 313endif
 314ifdef NEEDS_LIBICONV
 315        ifdef ICONVDIR
 316                # Again this may be problematic -- gcc does not always want -R.
 317                ALL_CFLAGS += -I$(ICONVDIR)/include
 318                ICONV_LINK = -L$(ICONVDIR)/lib -R$(ICONVDIR)/lib
 319        else
 320                ICONV_LINK =
 321        endif
 322        LIB_4_ICONV = $(ICONV_LINK) -liconv
 323else
 324        LIB_4_ICONV =
 325endif
 326ifdef NEEDS_SOCKET
 327        LIBS += -lsocket
 328        SIMPLE_LIB += -lsocket
 329endif
 330ifdef NEEDS_NSL
 331        LIBS += -lnsl
 332        SIMPLE_LIB += -lnsl
 333endif
 334ifdef NO_STRCASESTR
 335        COMPAT_CFLAGS += -DNO_STRCASESTR
 336        COMPAT_OBJS += compat/strcasestr.o
 337endif
 338ifdef NO_SETENV
 339        COMPAT_CFLAGS += -DNO_SETENV
 340        COMPAT_OBJS += compat/setenv.o
 341endif
 342ifdef NO_MMAP
 343        COMPAT_CFLAGS += -DNO_MMAP
 344        COMPAT_OBJS += compat/mmap.o
 345endif
 346ifdef NO_IPV6
 347        ALL_CFLAGS += -DNO_IPV6 -Dsockaddr_storage=sockaddr_in
 348endif
 349
 350ifdef PPC_SHA1
 351        SHA1_HEADER = "ppc/sha1.h"
 352        LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
 353else
 354ifdef ARM_SHA1
 355        SHA1_HEADER = "arm/sha1.h"
 356        LIB_OBJS += arm/sha1.o arm/sha1_arm.o
 357else
 358ifdef MOZILLA_SHA1
 359        SHA1_HEADER = "mozilla-sha1/sha1.h"
 360        LIB_OBJS += mozilla-sha1/sha1.o
 361else
 362        SHA1_HEADER = <openssl/sha.h>
 363        LIBS += $(LIB_4_CRYPTO)
 364endif
 365endif
 366endif
 367
 368ALL_CFLAGS += -DSHA1_HEADER=$(call shellquote,$(SHA1_HEADER)) $(COMPAT_CFLAGS)
 369LIB_OBJS += $(COMPAT_OBJS)
 370export prefix TAR INSTALL DESTDIR SHELL_PATH template_dir
 371### Build rules
 372
 373all: $(ALL_PROGRAMS) git$X gitk
 374
 375all:
 376        $(MAKE) -C templates
 377
 378strip: $(PROGRAMS) git$X
 379        $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
 380
 381git$X: git.c $(LIB_FILE)
 382        $(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
 383                $(CFLAGS) $(COMPAT_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE)
 384
 385$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
 386        rm -f $@
 387        sed -e '1s|#!.*/sh|#!$(call shq,$(SHELL_PATH))|' \
 388            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 389            $@.sh >$@
 390        chmod +x $@
 391
 392$(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl
 393        rm -f $@
 394        sed -e '1s|#!.*perl|#!$(call shq,$(PERL_PATH))|' \
 395            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 396            $@.perl >$@
 397        chmod +x $@
 398
 399$(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py
 400        rm -f $@
 401        sed -e '1s|#!.*python|#!$(call shq,$(PYTHON_PATH))|' \
 402            -e 's|@@GIT_PYTHON_PATH@@|$(call shq,$(GIT_PYTHON_DIR))|g' \
 403            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 404            $@.py >$@
 405        chmod +x $@
 406
 407git-cherry-pick: git-revert
 408        cp $< $@
 409
 410# These can record GIT_VERSION
 411git$X git.spec \
 412        $(patsubst %.sh,%,$(SCRIPT_SH)) \
 413        $(patsubst %.perl,%,$(SCRIPT_PERL)) \
 414        $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
 415        : GIT-VERSION-FILE
 416
 417%.o: %.c
 418        $(CC) -o $*.o -c $(ALL_CFLAGS) $<
 419%.o: %.S
 420        $(CC) -o $*.o -c $(ALL_CFLAGS) $<
 421
 422exec_cmd.o: ALL_CFLAGS += -DGIT_EXEC_PATH=\"$(gitexecdir)\"
 423
 424git-%$X: %.o $(LIB_FILE)
 425        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 426
 427git-mailinfo$X : SIMPLE_LIB += $(LIB_4_ICONV)
 428$(SIMPLE_PROGRAMS) : $(LIB_FILE)
 429$(SIMPLE_PROGRAMS) : git-%$X : %.o
 430        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 431                $(LIB_FILE) $(SIMPLE_LIB)
 432
 433git-http-fetch$X: fetch.o http.o
 434git-http-push$X: http.o
 435git-local-fetch$X: fetch.o
 436git-ssh-fetch$X: rsh.o fetch.o
 437git-ssh-upload$X: rsh.o
 438git-ssh-pull$X: rsh.o fetch.o
 439git-ssh-push$X: rsh.o
 440
 441git-http-fetch$X: LIBS += $(CURL_LIBCURL)
 442git-http-push$X: LIBS += $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 443git-rev-list$X: LIBS += $(OPENSSL_LIBSSL)
 444
 445init-db.o: init-db.c
 446        $(CC) -c $(ALL_CFLAGS) \
 447                -DDEFAULT_GIT_TEMPLATE_DIR=$(call shellquote,"$(template_dir)") $*.c
 448
 449$(LIB_OBJS): $(LIB_H)
 450$(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H)
 451$(DIFF_OBJS): diffcore.h
 452
 453$(LIB_FILE): $(LIB_OBJS)
 454        $(AR) rcs $@ $(LIB_OBJS)
 455
 456doc:
 457        $(MAKE) -C Documentation all
 458
 459
 460### Testing rules
 461
 462test: all
 463        $(MAKE) -C t/ all
 464
 465test-date$X: test-date.c date.o ctype.o
 466        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) test-date.c date.o ctype.o
 467
 468test-delta$X: test-delta.c diff-delta.o patch-delta.o
 469        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^
 470
 471check:
 472        for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done
 473
 474
 475
 476### Installation rules
 477
 478install: all
 479        $(INSTALL) -d -m755 $(call shellquote,$(DESTDIR)$(bindir))
 480        $(INSTALL) -d -m755 $(call shellquote,$(DESTDIR)$(gitexecdir))
 481        $(INSTALL) $(ALL_PROGRAMS) $(call shellquote,$(DESTDIR)$(gitexecdir))
 482        $(INSTALL) git$X gitk $(call shellquote,$(DESTDIR)$(bindir))
 483        $(MAKE) -C templates install
 484        $(INSTALL) -d -m755 $(call shellquote,$(DESTDIR)$(GIT_PYTHON_DIR))
 485        $(INSTALL) $(PYMODULES) $(call shellquote,$(DESTDIR)$(GIT_PYTHON_DIR))
 486
 487install-doc:
 488        $(MAKE) -C Documentation install
 489
 490
 491
 492
 493### Maintainer's dist rules
 494
 495git.spec: git.spec.in
 496        sed -e 's/@@VERSION@@/$(GIT_VERSION)/g' < $< > $@
 497
 498GIT_TARNAME=git-$(GIT_VERSION)
 499dist: git.spec git-tar-tree
 500        ./git-tar-tree HEAD $(GIT_TARNAME) > $(GIT_TARNAME).tar
 501        @mkdir -p $(GIT_TARNAME)
 502        @cp git.spec $(GIT_TARNAME)
 503        @echo $(GIT_VERSION) > $(GIT_TARNAME)/version
 504        $(TAR) rf $(GIT_TARNAME).tar \
 505                $(GIT_TARNAME)/git.spec $(GIT_TARNAME)/version
 506        @rm -rf $(GIT_TARNAME)
 507        gzip -f -9 $(GIT_TARNAME).tar
 508
 509rpm: dist
 510        $(RPMBUILD) -ta $(GIT_TARNAME).tar.gz
 511
 512### Cleaning rules
 513
 514clean:
 515        rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o $(LIB_FILE)
 516        rm -f $(ALL_PROGRAMS) git$X
 517        rm -f *.spec *.pyc *.pyo */*.pyc */*.pyo
 518        rm -rf $(GIT_TARNAME)
 519        rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
 520        $(MAKE) -C Documentation/ clean
 521        $(MAKE) -C templates clean
 522        $(MAKE) -C t/ clean
 523        rm -f GIT-VERSION-FILE
 524
 525.PHONY: all install clean strip
 526.PHONY: .FORCE-GIT-VERSION-FILE
 527