Makefile 21.8 KB
Newer Older
1 2 3
# The default target of this Makefile is...
all:

4 5 6 7
# Define MOZILLA_SHA1 environment variable when running make to make use of
# a bundled SHA1 routine coming from Mozilla. It is GPL'd and should be fast
# on non-x86 architectures (e.g. PowerPC), while the OpenSSL version (default
# choice) has very fast version optimized for i586.
8
#
9 10
# Define NO_OPENSSL environment variable if you do not have OpenSSL.
# This also implies MOZILLA_SHA1.
11
#
12 13 14
# Define NO_CURL if you do not have curl installed.  git-http-pull and
# git-http-push are not built, and you cannot use http:// and https://
# transports.
15
#
P
Patrick Mauritz 已提交
16 17 18
# Define CURLDIR=/foo/bar if your curl header and library files are in
# /foo/bar/include and /foo/bar/lib directories.
#
19 20 21
# Define NO_EXPAT if you do not have expat installed.  git-http-push is
# not built, and you cannot push using http:// and https:// transports.
#
22 23
# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
#
24 25 26
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
# d_type in struct dirent (latest Cygwin -- will be fixed soonish).
#
27 28
# Define NO_STRCASESTR if you don't have strcasestr.
#
29 30
# Define NO_STRLCPY if you don't have strlcpy.
#
J
Jason Riedy 已提交
31 32
# Define NO_SETENV if you don't have setenv in the C library.
#
33 34
# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
# Enable it on Windows.  By default, symrefs are still used.
35
#
36 37
# Define PPC_SHA1 environment variable when running make to make use of
# a bundled SHA1 routine optimized for PowerPC.
38
#
39 40 41
# Define ARM_SHA1 environment variable when running make to make use of
# a bundled SHA1 routine optimized for ARM.
#
42
# Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin).
43
#
44
# Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
45 46 47 48
#
# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
# Patrick Mauritz).
#
49 50
# Define NO_MMAP if you want to avoid mmap.
#
51 52
# Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3.
#
53 54
# Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
#
55 56 57
# Define NO_SOCKADDR_STORAGE if your platform does not have struct
# sockaddr_storage.
#
58 59
# Define NO_ICONV if your libc does not properly support iconv.
#
60 61 62
# Define NO_ACCURATE_DIFF if your diff program at least sometimes misses
# a missing newline at the end of the file.
#
63 64
# Define NO_PYTHON if you want to loose all benefits of the recursive merge.
#
65 66 67 68 69 70 71 72 73 74 75 76 77
# Define COLLISION_CHECK below if you believe that SHA1's
# 1461501637330902918203684832716283019655932542976 hashes do not give you
# sufficient guarantee that no collisions between objects will ever happen.

# Define USE_NSEC below if you want git to care about sub-second file mtimes
# and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and
# it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely
# randomly break unless your underlying filesystem supports those sub-second
# times (my ext3 doesn't).

# Define USE_STDEV below if you want git to care about the underlying device
# change being considered an inode change from the update-cache perspective.

78
GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
79
	@$(SHELL_PATH) ./GIT-VERSION-GEN
80
-include GIT-VERSION-FILE
81

82 83 84 85 86 87
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')

J
Junio C Hamano 已提交
88
# CFLAGS and LDFLAGS are for the users to override from the command line.
89

90
CFLAGS = -g -O2 -Wall
J
Junio C Hamano 已提交
91
LDFLAGS =
92
ALL_CFLAGS = $(CFLAGS)
J
Junio C Hamano 已提交
93
ALL_LDFLAGS = $(LDFLAGS)
J
Junio C Hamano 已提交
94
STRIP ?= strip
95

96 97
prefix = $(HOME)
bindir = $(prefix)/bin
98
gitexecdir = $(bindir)
99
template_dir = $(prefix)/share/git-core/templates/
100
GIT_PYTHON_DIR = $(prefix)/share/git-core/python
101
# DESTDIR=
102

103 104
CC = gcc
AR = ar
105
TAR = tar
106 107
INSTALL = install
RPMBUILD = rpmbuild
108

109 110
# sparse is architecture-neutral, which means that we need to tell it
# explicitly what architecture to check for. Fix this up for yours..
111
SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
112

P
Petr Baudis 已提交
113 114 115 116


### --- END CONFIGURATION SECTION ---

J
Junio C Hamano 已提交
117
SCRIPT_SH = \
118
	git-bisect.sh git-branch.sh git-checkout.sh \
P
Pavel Roskin 已提交
119
	git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
J
Junio C Hamano 已提交
120
	git-fetch.sh \
J
Junio C Hamano 已提交
121
	git-ls-remote.sh \
J
Junio C Hamano 已提交
122
	git-merge-one-file.sh git-parse-remote.sh \
J
Junio C Hamano 已提交
123
	git-prune.sh git-pull.sh git-rebase.sh \
J
Junio C Hamano 已提交
124
	git-repack.sh git-request-pull.sh git-reset.sh \
L
Linus Torvalds 已提交
125
	git-resolve.sh git-revert.sh git-sh-setup.sh \
126
	git-tag.sh git-verify-tag.sh \
127
	git-applymbox.sh git-applypatch.sh git-am.sh \
128
	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
129
	git-merge-resolve.sh git-merge-ours.sh \
E
Eric W. Biederman 已提交
130
	git-lost-found.sh git-quiltimport.sh
J
Junio C Hamano 已提交
131 132 133

SCRIPT_PERL = \
	git-archimport.perl git-cvsimport.perl git-relink.perl \
134
	git-shortlog.perl git-fmt-merge-msg.perl git-rerere.perl \
J
Junio C Hamano 已提交
135
	git-annotate.perl git-cvsserver.perl \
E
Eric Wong 已提交
136 137
	git-svnimport.perl git-mv.perl git-cvsexportcommit.perl \
	git-send-email.perl
138

139
SCRIPT_PYTHON = \
140
	git-merge-recursive.py
141

142 143 144
SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
	  $(patsubst %.perl,%,$(SCRIPT_PERL)) \
	  $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
145
	  git-cherry-pick git-status
146

147
# The ones that do not have to link with lcrypto, lz nor xdiff.
148
SIMPLE_PROGRAMS = \
L
Lukas Sandström 已提交
149
	git-daemon$X
150

J
Junio C Hamano 已提交
151
# ... and all the rest that could be moved out of bindir to gitexecdir
J
Junio C Hamano 已提交
152
PROGRAMS = \
J
Junio C Hamano 已提交
153
	git-checkout-index$X \
154
	git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
T
Timo Hirvonen 已提交
155
	git-hash-object$X git-index-pack$X git-local-fetch$X \
L
Lukas Sandström 已提交
156
	git-merge-base$X \
157
	git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
C
Christian Couder 已提交
158
	git-peek-remote$X git-prune-packed$X git-receive-pack$X \
P
Peter Eriksen 已提交
159
	git-send-pack$X git-shell$X \
160
	git-show-index$X git-ssh-fetch$X \
P
Peter Eriksen 已提交
161
	git-ssh-upload$X git-unpack-file$X \
162
	git-unpack-objects$X git-update-server-info$X \
L
Lukas Sandström 已提交
163
	git-upload-pack$X git-verify-pack$X \
L
Lukas Sandström 已提交
164
	git-symbolic-ref$X \
L
Linus Torvalds 已提交
165
	git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
166
	git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
167

L
Lukas Sandström 已提交
168
BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
L
Lukas Sandström 已提交
169
	git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
L
Lukas Sandström 已提交
170
	git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
L
Lukas Sandström 已提交
171
	git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
J
Junio C Hamano 已提交
172
	git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
R
Rene Scharfe 已提交
173
	git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
L
Lukas Sandström 已提交
174
	git-read-tree$X git-commit-tree$X git-write-tree$X \
175
	git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
T
Timo Hirvonen 已提交
176
	git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
J
Junio C Hamano 已提交
177

J
Junio C Hamano 已提交
178
# what 'all' will build and 'install' will install, in gitexecdir
J
Junio C Hamano 已提交
179
ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
180

181
# Backward compatibility -- to be removed after 1.0
182
PROGRAMS += git-ssh-pull$X git-ssh-push$X
183

184 185 186 187 188 189 190 191 192 193 194
# Set paths to tools early so that they can be used for version tests.
ifndef SHELL_PATH
	SHELL_PATH = /bin/sh
endif
ifndef PERL_PATH
	PERL_PATH = /usr/bin/perl
endif
ifndef PYTHON_PATH
	PYTHON_PATH = /usr/bin/python
endif

195 196 197
PYMODULES = \
	gitMergeCommon.py

L
Linus Torvalds 已提交
198
LIB_FILE=libgit.a
199
XDIFF_LIB=xdiff/lib.a
J
Junio C Hamano 已提交
200

J
Junio C Hamano 已提交
201
LIB_H = \
202
	blob.h cache.h commit.h csum-file.h delta.h \
203
	diff.h object.h pack.h pkt-line.h quote.h refs.h \
J
Junio C Hamano 已提交
204
	run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
205
	tree-walk.h log-tree.h dir.h
206

J
Junio C Hamano 已提交
207
DIFF_OBJS = \
J
Junio C Hamano 已提交
208
	diff.o diff-lib.o diffcore-break.o diffcore-order.o \
209
	diffcore-pickaxe.o diffcore-rename.o tree-diff.o combine-diff.o \
210
	diffcore-delta.o log-tree.o
211

J
Junio C Hamano 已提交
212
LIB_OBJS = \
213
	blob.o commit.o connect.o csum-file.o cache-tree.o base85.o \
214
	date.o diff-delta.o entry.o exec_cmd.o ident.o lockfile.o \
J
Junio C Hamano 已提交
215
	object.o pack-check.o patch-delta.o path.o pkt-line.o \
216
	quote.o read-cache.o refs.o run-command.o dir.o object-refs.o \
J
Junio C Hamano 已提交
217
	server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
218
	tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
219
	fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
220
	alloc.o $(DIFF_OBJS)
J
Junio C Hamano 已提交
221

222
BUILTIN_OBJS = \
J
Junio C Hamano 已提交
223
	builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
L
Linus Torvalds 已提交
224
	builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
C
Christian Couder 已提交
225
	builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
226
	builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
L
Lukas Sandström 已提交
227
	builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
L
Lukas Sandström 已提交
228
	builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
229
	builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
T
Timo Hirvonen 已提交
230
	builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
L
Lukas Sandström 已提交
231 232
	builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \
	builtin-update-ref.o
233

234 235
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
LIBS = $(GITLIBS) -lz
236

237 238 239
#
# Platform specific tweaks
#
240 241 242 243 244

# We choose to avoid "if .. else if .. else .. endif endif"
# because maintaining the nesting to match is a pain.  If
# we had "elif" things would have been much nicer...

245 246 247
ifeq ($(uname_S),Linux)
	NO_STRLCPY = YesPlease
endif
248
ifeq ($(uname_S),Darwin)
249 250
	NEEDS_SSL_WITH_CRYPTO = YesPlease
	NEEDS_LIBICONV = YesPlease
251
	NO_STRLCPY = YesPlease
252
	## fink
S
Shawn Pearce 已提交
253 254 255 256
	ifeq ($(shell test -d /sw/lib && echo y),y)
		ALL_CFLAGS += -I/sw/include
		ALL_LDFLAGS += -L/sw/lib
	endif
257
	## darwinports
S
Shawn Pearce 已提交
258 259 260 261
	ifeq ($(shell test -d /opt/local/lib && echo y),y)
		ALL_CFLAGS += -I/opt/local/include
		ALL_LDFLAGS += -L/opt/local/lib
	endif
262
endif
263
ifeq ($(uname_S),SunOS)
264
	NEEDS_SOCKET = YesPlease
265
	NEEDS_NSL = YesPlease
266 267
	SHELL_PATH = /bin/bash
	NO_STRCASESTR = YesPlease
268
	NO_STRLCPY = YesPlease
J
Jason Riedy 已提交
269
	ifeq ($(uname_R),5.8)
270
		NEEDS_LIBICONV = YesPlease
J
Jason Riedy 已提交
271
		NO_UNSETENV = YesPlease
J
Jason Riedy 已提交
272 273
		NO_SETENV = YesPlease
	endif
274 275 276 277
	ifeq ($(uname_R),5.9)
		NO_UNSETENV = YesPlease
		NO_SETENV = YesPlease
	endif
278 279
	INSTALL = ginstall
	TAR = gtar
280
	ALL_CFLAGS += -D__EXTENSIONS__
281
endif
282
ifeq ($(uname_O),Cygwin)
283
	NO_D_TYPE_IN_DIRENT = YesPlease
284
	NO_D_INO_IN_DIRENT = YesPlease
H
hpa 已提交
285
	NO_STRCASESTR = YesPlease
286
	NO_STRLCPY = YesPlease
287
	NO_SYMLINK_HEAD = YesPlease
H
hpa 已提交
288
	NEEDS_LIBICONV = YesPlease
289 290 291 292
	# There are conflicting reports about this.
	# On some boxes NO_MMAP is needed, and not so elsewhere.
	# Try uncommenting this if you see things break -- YMMV.
	# NO_MMAP = YesPlease
293
	NO_IPV6 = YesPlease
P
Peter Anvin 已提交
294
	X = .exe
295
endif
A
Alecs King 已提交
296 297 298 299 300
ifeq ($(uname_S),FreeBSD)
	NEEDS_LIBICONV = YesPlease
	ALL_CFLAGS += -I/usr/local/include
	ALL_LDFLAGS += -L/usr/local/lib
endif
301
ifeq ($(uname_S),OpenBSD)
302
	NO_STRCASESTR = YesPlease
H
Han Boetes 已提交
303
	NEEDS_LIBICONV = YesPlease
J
Junio C Hamano 已提交
304 305 306 307
	ALL_CFLAGS += -I/usr/local/include
	ALL_LDFLAGS += -L/usr/local/lib
endif
ifeq ($(uname_S),NetBSD)
308 309 310
	ifeq ($(shell expr "$(uname_R)" : '[01]\.'),2)
		NEEDS_LIBICONV = YesPlease
	endif
J
Junio C Hamano 已提交
311 312
	ALL_CFLAGS += -I/usr/pkg/include
	ALL_LDFLAGS += -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib
H
Han Boetes 已提交
313
endif
314 315
ifeq ($(uname_S),AIX)
	NO_STRCASESTR=YesPlease
316
	NO_STRLCPY = YesPlease
317 318
	NEEDS_LIBICONV=YesPlease
endif
J
Johannes Schindelin 已提交
319 320 321 322
ifeq ($(uname_S),IRIX64)
	NO_IPV6=YesPlease
	NO_SETENV=YesPlease
	NO_STRCASESTR=YesPlease
323
	NO_STRLCPY = YesPlease
J
Johannes Schindelin 已提交
324 325 326 327 328 329
	NO_SOCKADDR_STORAGE=YesPlease
	SHELL_PATH=/usr/gnu/bin/bash
	ALL_CFLAGS += -DPATH_MAX=1024
	# for now, build 32-bit version
	ALL_LDFLAGS += -L/usr/lib32
endif
330 331 332
ifneq (,$(findstring arm,$(uname_M)))
	ARM_SHA1 = YesPlease
endif
333

334
-include config.mak
335

336 337 338
ifdef WITH_OWN_SUBPROCESS_PY
	PYMODULES += compat/subprocess.py
else
J
Johannes Schindelin 已提交
339 340 341 342
	ifeq ($(NO_PYTHON),)
		ifneq ($(shell $(PYTHON_PATH) -c 'import subprocess;print"OK"' 2>/dev/null),OK)
			PYMODULES += compat/subprocess.py
		endif
343 344 345
	endif
endif

346 347
ifndef NO_CURL
	ifdef CURLDIR
J
Junio C Hamano 已提交
348
		# This is still problematic -- gcc does not always want -R.
349
		ALL_CFLAGS += -I$(CURLDIR)/include
350 351 352 353
		CURL_LIBCURL = -L$(CURLDIR)/lib -R$(CURLDIR)/lib -lcurl
	else
		CURL_LIBCURL = -lcurl
	endif
354
	PROGRAMS += git-http-fetch$X
355 356 357 358 359
	curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p)
	ifeq "$(curl_check)" "070908"
		ifndef NO_EXPAT
			PROGRAMS += git-http-push$X
		endif
360
	endif
361 362 363
	ifndef NO_EXPAT
		EXPAT_LIBEXPAT = -lexpat
	endif
364 365
endif

P
Petr Baudis 已提交
366
ifndef NO_OPENSSL
J
Junio C Hamano 已提交
367
	OPENSSL_LIBSSL = -lssl
J
Junio C Hamano 已提交
368 369
	ifdef OPENSSLDIR
		# Again this may be problematic -- gcc does not always want -R.
370
		ALL_CFLAGS += -I$(OPENSSLDIR)/include
J
Junio C Hamano 已提交
371 372 373 374
		OPENSSL_LINK = -L$(OPENSSLDIR)/lib -R$(OPENSSLDIR)/lib
	else
		OPENSSL_LINK =
	endif
P
Petr Baudis 已提交
375
else
376
	ALL_CFLAGS += -DNO_OPENSSL
J
Junio C Hamano 已提交
377 378
	MOZILLA_SHA1 = 1
	OPENSSL_LIBSSL =
P
Petr Baudis 已提交
379
endif
380
ifdef NEEDS_SSL_WITH_CRYPTO
J
Junio C Hamano 已提交
381
	LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto -lssl
382
else
J
Junio C Hamano 已提交
383
	LIB_4_CRYPTO = $(OPENSSL_LINK) -lcrypto
384 385
endif
ifdef NEEDS_LIBICONV
J
Junio C Hamano 已提交
386 387
	ifdef ICONVDIR
		# Again this may be problematic -- gcc does not always want -R.
388
		ALL_CFLAGS += -I$(ICONVDIR)/include
J
Junio C Hamano 已提交
389 390 391 392
		ICONV_LINK = -L$(ICONVDIR)/lib -R$(ICONVDIR)/lib
	else
		ICONV_LINK =
	endif
L
Lukas Sandström 已提交
393
	LIBS += $(ICONV_LINK) -liconv
394
endif
395 396 397 398
ifdef NEEDS_SOCKET
	LIBS += -lsocket
	SIMPLE_LIB += -lsocket
endif
399 400 401 402
ifdef NEEDS_NSL
	LIBS += -lnsl
	SIMPLE_LIB += -lnsl
endif
403 404 405
ifdef NO_D_TYPE_IN_DIRENT
	ALL_CFLAGS += -DNO_D_TYPE_IN_DIRENT
endif
406 407 408
ifdef NO_D_INO_IN_DIRENT
	ALL_CFLAGS += -DNO_D_INO_IN_DIRENT
endif
409 410 411
ifdef NO_SYMLINK_HEAD
	ALL_CFLAGS += -DNO_SYMLINK_HEAD
endif
412
ifdef NO_STRCASESTR
413
	COMPAT_CFLAGS += -DNO_STRCASESTR
J
Jason Riedy 已提交
414 415
	COMPAT_OBJS += compat/strcasestr.o
endif
416 417 418 419
ifdef NO_STRLCPY
	COMPAT_CFLAGS += -DNO_STRLCPY
	COMPAT_OBJS += compat/strlcpy.o
endif
J
Jason Riedy 已提交
420
ifdef NO_SETENV
421
	COMPAT_CFLAGS += -DNO_SETENV
J
Jason Riedy 已提交
422
	COMPAT_OBJS += compat/setenv.o
423
endif
J
Jason Riedy 已提交
424 425 426 427
ifdef NO_SETENV
	COMPAT_CFLAGS += -DNO_UNSETENV
	COMPAT_OBJS += compat/unsetenv.o
endif
428
ifdef NO_MMAP
429
	COMPAT_CFLAGS += -DNO_MMAP
J
Jason Riedy 已提交
430
	COMPAT_OBJS += compat/mmap.o
431
endif
432
ifdef NO_IPV6
433 434 435 436 437 438 439 440
	ALL_CFLAGS += -DNO_IPV6
endif
ifdef NO_SOCKADDR_STORAGE
ifdef NO_IPV6
	ALL_CFLAGS += -Dsockaddr_storage=sockaddr_in
else
	ALL_CFLAGS += -Dsockaddr_storage=sockaddr_in6
endif
441
endif
442 443 444
ifdef NO_INET_NTOP
	LIB_OBJS += compat/inet_ntop.o
endif
445

446 447 448 449
ifdef NO_ICONV
	ALL_CFLAGS += -DNO_ICONV
endif

450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
ifdef PPC_SHA1
	SHA1_HEADER = "ppc/sha1.h"
	LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
else
ifdef ARM_SHA1
	SHA1_HEADER = "arm/sha1.h"
	LIB_OBJS += arm/sha1.o arm/sha1_arm.o
else
ifdef MOZILLA_SHA1
	SHA1_HEADER = "mozilla-sha1/sha1.h"
	LIB_OBJS += mozilla-sha1/sha1.o
else
	SHA1_HEADER = <openssl/sha.h>
	LIBS += $(LIB_4_CRYPTO)
endif
endif
endif
467 468 469
ifdef NO_ACCURATE_DIFF
	ALL_CFLAGS += -DNO_ACCURATE_DIFF
endif
470

471 472 473 474 475 476 477 478
# Shell quote (do not use $(call) to accomodate ancient setups);

SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))

DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
bindir_SQ = $(subst ','\'',$(bindir))
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
template_dir_SQ = $(subst ','\'',$(template_dir))
479
prefix_SQ = $(subst ','\'',$(prefix))
480 481 482 483 484 485 486

SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
GIT_PYTHON_DIR_SQ = $(subst ','\'',$(GIT_PYTHON_DIR))

ALL_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' $(COMPAT_CFLAGS)
J
Jason Riedy 已提交
487
LIB_OBJS += $(COMPAT_OBJS)
T
Tom Prince 已提交
488
export prefix TAR INSTALL DESTDIR SHELL_PATH template_dir
P
Petr Baudis 已提交
489 490
### Build rules

J
Junio C Hamano 已提交
491
all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk
492

P
Petr Baudis 已提交
493 494
all: perl/Makefile
	$(MAKE) -C perl
495
	$(MAKE) -C templates
496

J
Junio C Hamano 已提交
497 498 499
strip: $(PROGRAMS) git$X
	$(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X

500
git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS
501
	$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
502
		$(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
503
		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
504

505 506
builtin-help.o: common-cmds.h

J
Junio C Hamano 已提交
507 508 509
$(BUILT_INS): git$X
	rm -f $@ && ln git$X $@

F
Fredrik Kuivinen 已提交
510
common-cmds.h: Documentation/git-*.txt
511 512
	./generate-cmdlist.sh > $@+
	mv $@+ $@
F
Fredrik Kuivinen 已提交
513

514
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
515
	rm -f $@ $@+
516
	sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
517
	    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
518
	    -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
519
	    -e 's/@@NO_PYTHON@@/$(NO_PYTHON)/g' \
520 521 522
	    $@.sh >$@+
	chmod +x $@+
	mv $@+ $@
523 524

$(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl
525
	rm -f $@ $@+
P
Petr Baudis 已提交
526
	sed -e '1s|#!.*perl\(.*\)|#!$(PERL_PATH_SQ)\1 -I'"$$(make -s -C perl instlibdir)"'|' \
527
	    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
528 529 530
	    $@.perl >$@+
	chmod +x $@+
	mv $@+ $@
531

532
$(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py GIT-CFLAGS
533
	rm -f $@ $@+
534 535
	sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
	    -e 's|@@GIT_PYTHON_PATH@@|$(GIT_PYTHON_DIR_SQ)|g' \
536
	    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
537 538 539
	    $@.py >$@+
	chmod +x $@+
	mv $@+ $@
540

541
git-cherry-pick: git-revert
542 543
	cp $< $@+
	mv $@+ $@
544

J
Junio C Hamano 已提交
545
git-status: git-commit
546 547
	cp $< $@+
	mv $@+ $@
J
Junio C Hamano 已提交
548

549 550 551 552 553 554
# These can record GIT_VERSION
git$X git.spec \
	$(patsubst %.sh,%,$(SCRIPT_SH)) \
	$(patsubst %.perl,%,$(SCRIPT_PERL)) \
	$(patsubst %.py,%,$(SCRIPT_PYTHON)) \
	: GIT-VERSION-FILE
555

556
%.o: %.c GIT-CFLAGS
557 558 559
	$(CC) -o $*.o -c $(ALL_CFLAGS) $<
%.o: %.S
	$(CC) -o $*.o -c $(ALL_CFLAGS) $<
560

561
exec_cmd.o: exec_cmd.c GIT-CFLAGS
562
	$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' $<
563 564
builtin-init-db.o: builtin-init-db.c GIT-CFLAGS
	$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
565

566
http.o: http.c GIT-CFLAGS
567 568
	$(CC) -o $*.o -c $(ALL_CFLAGS) -DGIT_USER_AGENT='"git/$(GIT_VERSION)"' $<

569
ifdef NO_EXPAT
570
http-fetch.o: http-fetch.c http.h GIT-CFLAGS
571 572 573
	$(CC) -o $*.o -c $(ALL_CFLAGS) -DNO_EXPAT $<
endif

574
git-%$X: %.o $(GITLIBS)
J
Junio C Hamano 已提交
575
	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
576

577
$(SIMPLE_PROGRAMS) : $(LIB_FILE)
578
$(SIMPLE_PROGRAMS) : git-%$X : %.o
J
Junio C Hamano 已提交
579 580
	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
		$(LIB_FILE) $(SIMPLE_LIB)
581

582 583 584 585 586
git-local-fetch$X: fetch.o
git-ssh-fetch$X: rsh.o fetch.o
git-ssh-upload$X: rsh.o
git-ssh-pull$X: rsh.o fetch.o
git-ssh-push$X: rsh.o
587

588 589
git-imap-send$X: imap-send.o $(LIB_FILE)

J
Junio C Hamano 已提交
590
http.o http-fetch.o http-push.o: http.h
J
Johannes Schindelin 已提交
591
git-http-fetch$X: fetch.o http.o http-fetch.o $(LIB_FILE)
592
	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
593
		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
594

N
Nick Hengeveld 已提交
595
git-http-push$X: revision.o http.o http-push.o $(LIB_FILE)
596 597 598
	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)

599
$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
600
$(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
601
$(DIFF_OBJS): diffcore.h
602

P
Petr Baudis 已提交
603
$(LIB_FILE): $(LIB_OBJS)
604
	rm -f $@ && $(AR) rcs $@ $(LIB_OBJS)
P
Petr Baudis 已提交
605

606 607 608
XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o

$(XDIFF_LIB): $(XDIFF_OBJS)
609
	rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS)
610 611


P
Petr Baudis 已提交
612
perl/Makefile:	perl/Git.pm perl/Makefile.PL
P
Petr Baudis 已提交
613 614 615 616
	(cd perl && $(PERL_PATH) Makefile.PL \
		PREFIX="$(prefix)" \
		DEFINE="$(ALL_CFLAGS) -DGIT_VERSION=\\\"$(GIT_VERSION)\\\"" \
		LIBS="$(LIBS)")
P
Petr Baudis 已提交
617

P
Petr Baudis 已提交
618 619 620
doc:
	$(MAKE) -C Documentation all

621 622 623 624 625 626 627
TAGS:
	rm -f TAGS
	find . -name '*.[hcS]' -print | xargs etags -a

tags:
	rm -f tags
	find . -name '*.[hcS]' -print | xargs ctags -a
P
Petr Baudis 已提交
628

629
### Detect prefix changes
630
TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):$(GIT_PYTHON_DIR_SQ):\
631 632 633 634 635 636 637 638 639
             $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)

GIT-CFLAGS: .FORCE-GIT-CFLAGS
	@FLAGS='$(TRACK_CFLAGS)'; \
	    if test x"$$FLAGS" != x"`cat GIT-CFLAGS 2>/dev/null`" ; then \
		echo 1>&2 "    * new build flags or prefix"; \
		echo "$$FLAGS" >GIT-CFLAGS; \
            fi

P
Petr Baudis 已提交
640 641
### Testing rules

642 643 644 645 646 647
# GNU make supports exporting all variables by "export" without parameters.
# However, the environment gets quite big, and some programs have problems
# with that.

export NO_PYTHON

P
Petr Baudis 已提交
648 649 650
test: all
	$(MAKE) -C t/ all

J
Junio C Hamano 已提交
651
test-date$X: test-date.c date.o ctype.o
J
Junio C Hamano 已提交
652
	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) test-date.c date.o ctype.o
P
Petr Baudis 已提交
653

654
test-delta$X: test-delta.c diff-delta.o patch-delta.o
655
	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^
P
Petr Baudis 已提交
656

J
Junio C Hamano 已提交
657 658 659
test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)

P
Petr Baudis 已提交
660
check:
661
	for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done
P
Petr Baudis 已提交
662 663 664 665 666



### Installation rules

667
install: all
668 669 670 671
	$(INSTALL) -d -m755 '$(DESTDIR_SQ)$(bindir_SQ)'
	$(INSTALL) -d -m755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
	$(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)'
J
Junio C Hamano 已提交
672
	$(MAKE) -C templates install
P
Petr Baudis 已提交
673
	$(MAKE) -C perl install
674 675
	$(INSTALL) -d -m755 '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'
	$(INSTALL) $(PYMODULES) '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'
676 677 678 679 680 681 682 683
	if test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \
	then \
		ln -f '$(DESTDIR_SQ)$(bindir_SQ)/git$X' \
			'$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X' || \
		cp '$(DESTDIR_SQ)$(bindir_SQ)/git$X' \
			'$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X'; \
	fi
	$(foreach p,$(BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;)
P
Petr Baudis 已提交
684 685 686 687 688 689 690 691 692

install-doc:
	$(MAKE) -C Documentation install




### Maintainer's dist rules

693
git.spec: git.spec.in
694 695
	sed -e 's/@@VERSION@@/$(GIT_VERSION)/g' < $< > $@+
	mv $@+ $@
696

J
Junio C Hamano 已提交
697 698
GIT_TARNAME=git-$(GIT_VERSION)
dist: git.spec git-tar-tree
699
	./git-tar-tree HEAD^{tree} $(GIT_TARNAME) > $(GIT_TARNAME).tar
700
	@mkdir -p $(GIT_TARNAME)
J
Junio C Hamano 已提交
701
	@cp git.spec $(GIT_TARNAME)
702 703 704
	@echo $(GIT_VERSION) > $(GIT_TARNAME)/version
	$(TAR) rf $(GIT_TARNAME).tar \
		$(GIT_TARNAME)/git.spec $(GIT_TARNAME)/version
705
	@rm -rf $(GIT_TARNAME)
706
	gzip -f -9 $(GIT_TARNAME).tar
707 708

rpm: dist
J
Junio C Hamano 已提交
709
	$(RPMBUILD) -ta $(GIT_TARNAME).tar.gz
710

711 712 713 714 715 716 717 718 719 720 721
htmldocs = git-htmldocs-$(GIT_VERSION)
manpages = git-manpages-$(GIT_VERSION)
dist-doc:
	rm -fr .doc-tmp-dir
	mkdir .doc-tmp-dir
	$(MAKE) -C Documentation WEBDOC_DEST=../.doc-tmp-dir install-webdoc
	cd .doc-tmp-dir && $(TAR) cf ../$(htmldocs).tar .
	gzip -n -9 -f $(htmldocs).tar
	:
	rm -fr .doc-tmp-dir
	mkdir .doc-tmp-dir .doc-tmp-dir/man1 .doc-tmp-dir/man7
722
	$(MAKE) -C Documentation DESTDIR=./ \
723 724 725 726 727 728 729
		man1=../.doc-tmp-dir/man1 \
		man7=../.doc-tmp-dir/man7 \
		install
	cd .doc-tmp-dir && $(TAR) cf ../$(manpages).tar .
	gzip -n -9 -f $(manpages).tar
	rm -fr .doc-tmp-dir

P
Petr Baudis 已提交
730
### Cleaning rules
731

732
clean:
733 734
	rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
		$(LIB_FILE) $(XDIFF_LIB)
A
A Large Angry SCM 已提交
735
	rm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X
736
	rm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags
737
	rm -rf $(GIT_TARNAME) .doc-tmp-dir
738
	rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
739
	rm -f $(htmldocs).tar.gz $(manpages).tar.gz
740
	$(MAKE) -C Documentation/ clean
P
Petr Baudis 已提交
741 742
	[ ! -e perl/Makefile ] || $(MAKE) -C perl/ clean
	$(MAKE) -C templates/ clean
743
	$(MAKE) -C t/ clean
744
	rm -f GIT-VERSION-FILE GIT-CFLAGS
745

J
Junio C Hamano 已提交
746
.PHONY: all install clean strip
747
.PHONY: .FORCE-GIT-VERSION-FILE TAGS tags .FORCE-GIT-CFLAGS
J
Junio C Hamano 已提交
748

J
Junio C Hamano 已提交
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
### Check documentation
#
check-docs::
	@for v in $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk; \
	do \
		case "$$v" in \
		git-merge-octopus | git-merge-ours | git-merge-recursive | \
		git-merge-resolve | git-merge-stupid | \
		git-ssh-pull | git-ssh-push ) continue ;; \
		esac ; \
		test -f "Documentation/$$v.txt" || \
		echo "no doc: $$v"; \
		grep -q "^gitlink:$$v\[[0-9]\]::" Documentation/git.txt || \
		case "$$v" in \
		git) ;; \
		*) echo "no link: $$v";; \
		esac ; \
	done | sort