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