socklen_t is unsigned int on most Linux platforms
[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 is not
10 # built, and you cannot use http:// and https:// transports.
11 #
12 # Define CURLDIR=/foo/bar if your curl header and library files are in
13 # /foo/bar/include and /foo/bar/lib directories.
14 #
15 # Define NO_STRCASESTR if you don't have strcasestr.
16 #
17 # Define PPC_SHA1 environment variable when running make to make use of
18 # a bundled SHA1 routine optimized for PowerPC.
19 #
20 # Define ARM_SHA1 environment variable when running make to make use of
21 # a bundled SHA1 routine optimized for ARM.
22 #
23 # Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin).
24 #
25 # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
26 #
27 # Define NEEDS_SOCKET if linking with libc is not enough (SunOS,
28 # Patrick Mauritz).
29 #
30 # Define WITH_OWN_SUBPROCESS_PY if you want to use with python 2.3.
31 #
32 # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().
33 #
34 # Define COLLISION_CHECK below if you believe that SHA1's
35 # 1461501637330902918203684832716283019655932542976 hashes do not give you
36 # sufficient guarantee that no collisions between objects will ever happen.
37
38 # DEFINES += -DCOLLISION_CHECK
39
40 # Define USE_NSEC below if you want git to care about sub-second file mtimes
41 # and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and
42 # it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely
43 # randomly break unless your underlying filesystem supports those sub-second
44 # times (my ext3 doesn't).
45
46 # DEFINES += -DUSE_NSEC
47
48 # Define USE_STDEV below if you want git to care about the underlying device
49 # change being considered an inode change from the update-cache perspective.
50
51 # DEFINES += -DUSE_STDEV
52
53 GIT_VERSION = 0.99.7.GIT
54
55 CFLAGS = -g -O2 -Wall
56 ALL_CFLAGS = $(CFLAGS) $(PLATFORM_DEFINES) $(DEFINES)
57
58 prefix = $(HOME)
59 bindir = $(prefix)/bin
60 template_dir = $(prefix)/share/git-core/templates/
61 GIT_PYTHON_DIR = $(prefix)/share/git-core/python
62 # DESTDIR=
63
64 CC = gcc
65 AR = ar
66 TAR = tar
67 INSTALL = install
68 RPMBUILD = rpmbuild
69
70 # sparse is architecture-neutral, which means that we need to tell it
71 # explicitly what architecture to check for. Fix this up for yours..
72 SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
73
74
75
76 ### --- END CONFIGURATION SECTION ---
77
78 SCRIPT_SH = \
79         git-add.sh git-bisect.sh git-branch.sh git-checkout.sh \
80         git-cherry.sh git-clone.sh git-commit.sh \
81         git-count-objects.sh git-diff.sh git-fetch.sh \
82         git-format-patch.sh git-log.sh git-ls-remote.sh \
83         git-merge-one-file.sh git-octopus.sh git-parse-remote.sh \
84         git-prune.sh git-pull.sh git-push.sh git-rebase.sh \
85         git-repack.sh git-request-pull.sh git-reset.sh \
86         git-resolve.sh git-revert.sh git-sh-setup.sh git-status.sh \
87         git-tag.sh git-verify-tag.sh git-whatchanged.sh git.sh \
88         git-applymbox.sh git-applypatch.sh \
89         git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
90         git-merge-resolve.sh git-grep.sh
91
92 SCRIPT_PERL = \
93         git-archimport.perl git-cvsimport.perl git-relink.perl \
94         git-rename.perl git-shortlog.perl git-fmt-merge-msg.perl
95
96 SCRIPT_PYTHON = \
97         git-merge-recursive.py
98
99 # The ones that do not have to link with lcrypto nor lz.
100 SIMPLE_PROGRAMS = \
101         git-get-tar-commit-id$X git-mailinfo$X git-mailsplit$X \
102         git-stripspace$X git-var$X git-daemon$X
103
104 # ... and all the rest
105 PROGRAMS = \
106         git-apply$X git-cat-file$X git-checkout-index$X         \
107         git-clone-pack$X git-commit-tree$X git-convert-objects$X        \
108         git-diff-files$X git-diff-index$X git-diff-stages$X     \
109         git-diff-tree$X git-fetch-pack$X git-fsck-objects$X     \
110         git-hash-object$X git-init-db$X git-local-fetch$X               \
111         git-ls-files$X git-ls-tree$X git-merge-base$X           \
112         git-merge-index$X git-mktag$X git-pack-objects$X                \
113         git-patch-id$X git-peek-remote$X git-prune-packed$X     \
114         git-read-tree$X git-receive-pack$X git-rev-list$X               \
115         git-rev-parse$X git-send-pack$X git-show-branch$X               \
116         git-show-index$X git-ssh-fetch$X git-ssh-upload$X               \
117         git-tar-tree$X git-unpack-file$X git-unpack-objects$X   \
118         git-update-index$X git-update-server-info$X                     \
119         git-upload-pack$X git-verify-pack$X git-write-tree$X    \
120         git-update-ref$X $(SIMPLE_PROGRAMS)
121
122 # Backward compatibility -- to be removed after 1.0
123 PROGRAMS += git-ssh-pull$X git-ssh-push$X
124
125 PYMODULES = \
126         gitMergeCommon.py
127
128 ifdef WITH_OWN_SUBPROCESS_PY
129         PYMODULES += compat/subprocess.py
130 endif
131
132 ifdef WITH_SEND_EMAIL
133         SCRIPT_PERL += git-send-email.perl
134 endif
135
136 LIB_FILE=libgit.a
137
138 LIB_H = \
139         blob.h cache.h commit.h count-delta.h csum-file.h delta.h \
140         diff.h epoch.h object.h pack.h pkt-line.h quote.h refs.h \
141         run-command.h strbuf.h tag.h tree.h
142
143 DIFF_OBJS = \
144         diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
145         diffcore-pickaxe.o diffcore-rename.o
146
147 LIB_OBJS = \
148         blob.o commit.o connect.o count-delta.o csum-file.o \
149         date.o diff-delta.o entry.o ident.o index.o \
150         object.o pack-check.o patch-delta.o path.o pkt-line.o \
151         quote.o read-cache.o refs.o run-command.o \
152         server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
153         tag.o tree.o usage.o $(DIFF_OBJS)
154
155 LIBS = $(LIB_FILE)
156 LIBS += -lz
157
158 #
159 # Platform specific tweaks
160 #
161 ifeq ($(shell uname -s),Darwin)
162         NEEDS_SSL_WITH_CRYPTO = YesPlease
163         NEEDS_LIBICONV = YesPlease
164 endif
165 ifeq ($(shell uname -s),SunOS)
166         NEEDS_SOCKET = YesPlease
167         NEEDS_NSL = YesPlease
168         SHELL_PATH = /bin/bash
169         NO_STRCASESTR = YesPlease
170         CURLDIR = /opt/sfw
171         INSTALL = ginstall
172         TAR = gtar
173         PLATFORM_DEFINES += -D__EXTENSIONS__
174 endif
175 ifeq ($(shell uname -o),Cygwin)
176         NO_STRCASESTR = YesPlease
177         NEEDS_LIBICONV = YesPlease
178         NO_IPV6 = YesPlease
179         X = .exe
180 endif
181 ifneq (,$(findstring arm,$(shell uname -m)))
182         ARM_SHA1 = YesPlease
183 endif
184
185 ifndef NO_CURL
186         ifdef CURLDIR
187                 # This is still problematic -- gcc does not want -R.
188                 CFLAGS += -I$(CURLDIR)/include
189                 CURL_LIBCURL = -L$(CURLDIR)/lib -R$(CURLDIR)/lib -lcurl
190         else
191                 CURL_LIBCURL = -lcurl
192         endif
193         PROGRAMS += git-http-fetch$X
194 endif
195
196 ifndef SHELL_PATH
197         SHELL_PATH = /bin/sh
198 endif
199 ifndef PERL_PATH
200         PERL_PATH = /usr/bin/perl
201 endif
202 ifndef PYTHON_PATH
203         PYTHON_PATH = /usr/bin/python
204 endif
205
206 ifndef NO_OPENSSL
207         LIB_OBJS += epoch.o
208         OPENSSL_LIBSSL = -lssl
209 else
210         DEFINES += '-DNO_OPENSSL'
211         MOZILLA_SHA1 = 1
212         OPENSSL_LIBSSL =
213 endif
214 ifdef NEEDS_SSL_WITH_CRYPTO
215         LIB_4_CRYPTO = -lcrypto -lssl
216 else
217         LIB_4_CRYPTO = -lcrypto
218 endif
219 ifdef NEEDS_LIBICONV
220         LIB_4_ICONV = -liconv
221 else
222         LIB_4_ICONV =
223 endif
224 ifdef NEEDS_SOCKET
225         LIBS += -lsocket
226         SIMPLE_LIB += -lsocket
227 endif
228 ifdef NEEDS_NSL
229         LIBS += -lnsl
230         SIMPLE_LIB += -lnsl
231 endif
232 ifdef NO_STRCASESTR
233         DEFINES += -Dstrcasestr=gitstrcasestr
234         LIB_OBJS += compat/strcasestr.o
235 endif
236 ifdef NO_IPV6
237         DEFINES += -DNO_IPV6 -Dsockaddr_storage=sockaddr_in
238 endif
239
240 ifdef PPC_SHA1
241         SHA1_HEADER = "ppc/sha1.h"
242         LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
243 else
244 ifdef ARM_SHA1
245         SHA1_HEADER = "arm/sha1.h"
246         LIB_OBJS += arm/sha1.o arm/sha1_arm.o
247 else
248 ifdef MOZILLA_SHA1
249         SHA1_HEADER = "mozilla-sha1/sha1.h"
250         LIB_OBJS += mozilla-sha1/sha1.o
251 else
252         SHA1_HEADER = <openssl/sha.h>
253         LIBS += $(LIB_4_CRYPTO)
254 endif
255 endif
256 endif
257
258 DEFINES += '-DSHA1_HEADER=$(SHA1_HEADER)'
259
260 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
261           $(patsubst %.perl,%,$(SCRIPT_PERL)) \
262           $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
263           gitk
264
265 export TAR INSTALL DESTDIR SHELL_PATH
266 ### Build rules
267
268 all: $(PROGRAMS) $(SCRIPTS)
269
270 all:
271         $(MAKE) -C templates
272
273 git: git.sh Makefile
274         rm -f $@+ $@
275         sed -e '1s|#!.*/sh|#!$(SHELL_PATH)|' \
276             -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' <$@.sh >$@+
277         chmod +x $@+
278         mv $@+ $@
279
280 $(filter-out git,$(patsubst %.sh,%,$(SCRIPT_SH))) : % : %.sh
281         rm -f $@
282         sed -e '1s|#!.*/sh|#!$(SHELL_PATH)|' $@.sh >$@
283         chmod +x $@
284
285 $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl
286         rm -f $@
287         sed -e '1s|#!.*perl|#!$(PERL_PATH)|' $@.perl >$@
288         chmod +x $@
289
290 $(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py
291         rm -f $@
292         sed -e '1s|#!.*python|#!$(PYTHON_PATH)|' \
293             -e 's|@@GIT_PYTHON_PATH@@|$(GIT_PYTHON_DIR)|g' \
294                 $@.py >$@
295         chmod +x $@
296
297 %.o: %.c
298         $(CC) -o $*.o -c $(ALL_CFLAGS) $<
299 %.o: %.S
300         $(CC) -o $*.o -c $(ALL_CFLAGS) $<
301
302 git-%$X: %.o $(LIB_FILE)
303         $(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
304
305 git-mailinfo$X : SIMPLE_LIB += $(LIB_4_ICONV)
306 $(SIMPLE_PROGRAMS) : $(LIB_FILE)
307 $(SIMPLE_PROGRAMS) : git-%$X : %.o
308         $(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^) $(LIB_FILE) $(SIMPLE_LIB)
309
310 git-http-fetch$X: fetch.o
311 git-local-fetch$X: fetch.o
312 git-ssh-fetch$X: rsh.o fetch.o
313 git-ssh-upload$X: rsh.o
314 git-ssh-pull$X: rsh.o fetch.o
315 git-ssh-push$X: rsh.o
316
317 git-http-fetch$X: LIBS += $(CURL_LIBCURL)
318 git-rev-list$X: LIBS += $(OPENSSL_LIBSSL)
319
320 init-db.o: init-db.c
321         $(CC) -c $(ALL_CFLAGS) \
322                 -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir)"' $*.c
323
324 $(LIB_OBJS): $(LIB_H)
325 $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H)
326 $(DIFF_OBJS): diffcore.h
327
328 $(LIB_FILE): $(LIB_OBJS)
329         $(AR) rcs $@ $(LIB_OBJS)
330
331 doc:
332         $(MAKE) -C Documentation all
333
334
335 ### Testing rules
336
337 test: all
338         $(MAKE) -C t/ all
339
340 test-date$X: test-date.c date.o
341         $(CC) $(ALL_CFLAGS) -o $@ test-date.c date.o
342
343 test-delta$X: test-delta.c diff-delta.o patch-delta.o
344         $(CC) $(ALL_CFLAGS) -o $@ $^
345
346 check:
347         for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i; done
348
349
350
351 ### Installation rules
352
353 install: $(PROGRAMS) $(SCRIPTS)
354         $(INSTALL) -d -m755 $(DESTDIR)$(bindir)
355         $(INSTALL) $(PROGRAMS) $(SCRIPTS) $(DESTDIR)$(bindir)
356         $(INSTALL) git-revert $(DESTDIR)$(bindir)/git-cherry-pick
357         sh ./cmd-rename.sh $(DESTDIR)$(bindir)
358         $(MAKE) -C templates install
359         $(INSTALL) -d -m755 $(DESTDIR)$(GIT_PYTHON_DIR)
360         $(INSTALL) $(PYMODULES) $(DESTDIR)$(GIT_PYTHON_DIR)
361
362 install-doc:
363         $(MAKE) -C Documentation install
364
365
366
367
368 ### Maintainer's dist rules
369
370 git-core.spec: git-core.spec.in Makefile
371         sed -e 's/@@VERSION@@/$(GIT_VERSION)/g' < $< > $@
372
373 GIT_TARNAME=git-core-$(GIT_VERSION)
374 dist: git-core.spec git-tar-tree
375         ./git-tar-tree HEAD $(GIT_TARNAME) > $(GIT_TARNAME).tar
376         @mkdir -p $(GIT_TARNAME)
377         @cp git-core.spec $(GIT_TARNAME)
378         $(TAR) rf $(GIT_TARNAME).tar $(GIT_TARNAME)/git-core.spec
379         @rm -rf $(GIT_TARNAME)
380         gzip -f -9 $(GIT_TARNAME).tar
381
382 rpm: dist
383         $(RPMBUILD) -ta git-core-$(GIT_VERSION).tar.gz
384
385 deb: dist
386         rm -rf $(GIT_TARNAME)
387         $(TAR) zxf $(GIT_TARNAME).tar.gz
388         dpkg-source -b $(GIT_TARNAME)
389         cd $(GIT_TARNAME) && fakeroot debian/rules binary
390
391 ### Cleaning rules
392
393 clean:
394         rm -f *.o mozilla-sha1/*.o ppc/*.o compat/*.o $(PROGRAMS) $(LIB_FILE)
395         rm -f $(filter-out gitk,$(SCRIPTS))
396         rm -f git-core.spec *.pyc *.pyo
397         rm -rf $(GIT_TARNAME)
398         rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
399         rm -f git-core_$(GIT_VERSION)-*.deb git-core_$(GIT_VERSION)-*.dsc
400         rm -f git-tk_$(GIT_VERSION)-*.deb
401         $(MAKE) -C Documentation/ clean
402         $(MAKE) -C templates clean
403         $(MAKE) -C t/ clean