Fix warning in util.h (signed vs unsigned comparison)
[libgit2.git] / Makefile
blobab5685026cc2b70c18e2c43689a57944eacf59ed
1 all::
3 # Define NO_VISIBILITY if your compiler does not support symbol
4 # visibility in general (and the -fvisibility switch in particular).
6 # Define OPENSSL_SHA1 if you want use the SHA1 routines from the
7 # OpenSSL crypto library, rather than the built-in C versions.
9 # Define PPC_SHA1 if you want to use the bundled SHA1 routines that
10 # are optimized for PowerPC, rather than the built-in C versions.
13 DOXYGEN = doxygen
14 INSTALL = install
15 RANLIB = ranlib
16 AR = ar cr
18 prefix=/usr/local
19 libdir=$(prefix)/lib
21 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo no')
23 ifdef MSVC
24 # avoid the MinGW and Cygwin configuration sections
25 uname_S := Windows
26 endif
28 CFLAGS = -g -O2 -Wall -Wextra
29 OS = unix
31 EXTRA_SRC =
32 EXTRA_OBJ =
33 EXTRA_CFLAGS =
35 AR_OUT=
36 CC_OUT=-o # add a space
38 # Platform specific tweaks
40 ifeq ($(uname_S),Windows)
41 OS=win32
42 RANLIB = echo
43 CC = cl -nologo
44 AR = lib -nologo
45 CFLAGS = -TC -W4 -RTC1 -Zi -DWIN32 -D_DEBUG -D_LIB
46 AR_OUT=-out:
47 CC_OUT=-Fo
48 NO_VISIBILITY=YesPlease
49 endif
51 ifneq (,$(findstring CYGWIN,$(uname_S)))
52 NO_VISIBILITY=YesPlease
53 endif
55 ifneq (,$(findstring MINGW,$(uname_S)))
56 OS=win32
57 NO_VISIBILITY=YesPlease
58 SPARSE_FLAGS=-Wno-one-bit-signed-bitfield
59 endif
61 -include config.mak
63 SRC_C = $(wildcard src/*.c)
64 OS_SRC = $(wildcard src/$(OS)/*.c)
65 SRC_C += $(OS_SRC) $(EXTRA_SRC)
66 OBJS = $(patsubst %.c,%.o,$(SRC_C)) $(EXTRA_OBJ)
67 HDRS = $(wildcard src/*.h)
68 PUBLIC_HEADERS = $(wildcard src/git/*.h)
69 HDRS += $(PUBLIC_HEADERS)
71 GIT_LIB = libgit2.a
73 TEST_OBJ = $(patsubst %.c,%.o,\
74 $(wildcard tests/t[0-9][0-9][0-9][0-9]-*.c))
75 TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ))
76 TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE))
77 TEST_VAL = $(patsubst %.exe,%.val,$(TEST_EXE))
79 ifdef PPC_SHA1
80 EXTRA_SRC += src/ppc/sha1.c
81 EXTRA_OBJ += src/ppc/sha1ppc.o
82 EXTRA_CFLAGS += -DPPC_SHA1
83 else
84 ifdef OPENSSL_SHA1
85 EXTRA_CFLAGS += -DOPENSSL_SHA1
86 else
87 EXTRA_SRC += src/block-sha1/sha1.c
88 endif
89 endif
91 BASIC_CFLAGS := -Isrc
92 ifndef NO_VISIBILITY
93 BASIC_CFLAGS += -fvisibility=hidden
94 endif
96 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) $(EXTRA_CFLAGS)
98 all:: $(GIT_LIB)
100 clean:
101 rm -f $(GIT_LIB)
102 rm -f libgit2.pc
103 rm -f *.pdb
104 rm -f src/*.[oi] src/*/*.[oi]
105 rm -rf apidocs
106 rm -f *~ src/*~ src/*/*~
107 @$(MAKE) -C tests -s --no-print-directory clean
108 @$(MAKE) -s --no-print-directory cov-clean
110 test-clean:
111 @$(MAKE) -C tests -s --no-print-directory clean
113 apidocs:
114 $(DOXYGEN) api.doxygen
115 cp CONVENTIONS apidocs/
117 test: $(GIT_LIB)
118 @$(MAKE) -C tests --no-print-directory test
120 valgrind: $(GIT_LIB)
121 @$(MAKE) -C tests --no-print-directory valgrind
123 sparse:
124 cgcc -no-compile $(ALL_CFLAGS) $(SPARSE_FLAGS) $(SRC_C)
126 install-headers: $(PUBLIC_HEADERS)
127 @$(INSTALL) -d /tmp/gitinc/git
128 @for i in $^; do cat .HEADER $$i > /tmp/gitinc/$${i##src/}; done
130 install: $(GIT_LIB) $(PUBLIC_HEADERS) libgit2.pc
131 @$(INSTALL) -d $(DESTDIR)/$(prefix)/include/git
132 @for i in $(PUBLIC_HEADERS); do \
133 cat .HEADER $$i > $(DESTDIR)/$(prefix)/include/$${i##src/}; \
134 done
135 @$(INSTALL) -d $(DESTDIR)/$(libdir)
136 @$(INSTALL) $(GIT_LIB) $(DESTDIR)/$(libdir)/libgit2.a
137 @$(INSTALL) -d $(DESTDIR)/$(libdir)/pkgconfig
138 @$(INSTALL) libgit2.pc $(DESTDIR)/$(libdir)/pkgconfig/libgit2.pc
140 uninstall:
141 @rm -f $(DESTDIR)/$(libdir)/libgit2.a
142 @rm -f $(DESTDIR)/$(libdir)/pkgconfig/libgit2.pc
143 @for i in $(PUBLIC_HEADERS); do \
144 rm -f $(DESTDIR)/$(prefix)/include/$${i##src/}; \
145 done
146 @rmdir $(DESTDIR)/$(prefix)/include/git
148 .c.o:
149 $(CC) $(ALL_CFLAGS) -c $< $(CC_OUT)$@
151 .S.o:
152 $(CC) $(ALL_CFLAGS) -c $< $(CC_OUT)$@
154 %.i: %.c FORCE
155 $(CC) $(ALL_CFLAGS) -E $< >$*.i
157 $(OBJS): $(HDRS)
158 $(GIT_LIB): $(OBJS)
159 rm -f $(GIT_LIB)
160 $(AR) $(AR_OUT)$(GIT_LIB) $(OBJS)
161 $(RANLIB) $(GIT_LIB)
163 $(TEST_OBJ) $(TEST_EXE) $(TEST_RUN) $(TEST_VAL): $(GIT_LIB)
164 @$(MAKE) -C tests --no-print-directory \
165 OS=$(OS) $(@F)
167 libgit2.pc: libgit2.pc.in
168 sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' $< > $@
170 .PHONY: all
171 .PHONY: clean
172 .PHONY: test $(TEST_VAL) $(TEST_RUN) $(TEST_EXE) $(TEST_OBJ)
173 .PHONY: apidocs
174 .PHONY: install-headers
175 .PHONY: install uninstall
176 .PHONY: sparse
177 .PHONY: FORCE
179 ### Test suite coverage testing
181 .PHONY: coverage cov-clean cov-build cov-report
183 COV_GCDA = $(patsubst %.c,%.gcda,$(SRC_C))
184 COV_GCNO = $(patsubst %.c,%.gcno,$(SRC_C))
186 coverage:
187 @$(MAKE) -s --no-print-directory clean
188 @$(MAKE) --no-print-directory cov-build
189 @$(MAKE) --no-print-directory cov-report
191 cov-clean:
192 rm -f $(COV_GCDA) $(COV_GCNO) *.gcov untested
194 COV_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
196 cov-build:
197 $(MAKE) CFLAGS="$(COV_CFLAGS)" all
198 $(MAKE) TEST_COVERAGE=1 test
200 cov-report:
201 @echo "--- untested files:" | tee untested
202 @{ for f in $(SRC_C); do \
203 gcda=$$(dirname $$f)"/"$$(basename $$f .c)".gcda"; \
204 if test -f $$gcda; then \
205 gcov -b -p -o $$(dirname $$f) $$f >/dev/null; \
206 else \
207 echo $$f | tee -a untested; \
208 fi; \
209 done; }
210 @rm -f *.h.gcov
211 @echo "--- untested functions:" | tee -a untested
212 @grep '^function .* called 0' *.c.gcov \
213 | sed -e 's/\([^:]*\)\.gcov:function \([^ ]*\) called.*/\1: \2/' \
214 | sed -e 's|#|/|g' | tee -a untested