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