Correct Adam Simpkins' name
[libgit2.git] / Makefile
blobff5f93335a52245a405e12e9ad1091f4cb875b5a
1 all::
3 # Define NO_VISIBILITY if your compiler does not support symbol
4 # visibility in general (and the -fvisibility switch in particular).
7 DOXYGEN = doxygen
8 INSTALL = install
9 RANLIB = ranlib
10 AR = ar cr
12 prefix=/usr/local
13 libdir=$(prefix)/lib
15 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo no')
17 ifdef MSVC
18 # avoid the MinGW and Cygwin configuration sections
19 uname_S := Windows
20 endif
22 CFLAGS = -g -O2 -Wall
23 OS = unix
25 EXTRA_SRC =
26 EXTRA_OBJ =
27 EXTRA_CFLAGS =
29 AR_OUT=
30 CC_OUT=-o # add a space
32 # Platform specific tweaks
34 ifeq ($(uname_S),Windows)
35 OS=win32
36 RANLIB = echo
37 CC = cl -nologo
38 AR = lib -nologo
39 CFLAGS = -TC -W3 -RTC1 -Zi -DWIN32 -D_DEBUG -D_LIB
40 AR_OUT=-out:
41 CC_OUT=-Fo
42 NO_VISIBILITY=YesPlease
43 endif
45 ifneq (,$(findstring CYGWIN,$(uname_S)))
46 NO_VISIBILITY=YesPlease
47 endif
49 ifneq (,$(findstring MINGW,$(uname_S)))
50 OS=win32
51 NO_VISIBILITY=YesPlease
52 SPARSE_FLAGS=-Wno-one-bit-signed-bitfield
53 endif
55 SRC_C = $(wildcard src/*.c)
56 OS_SRC = $(wildcard src/$(OS)/*.c)
57 SRC_C += $(OS_SRC)
58 OBJS = $(patsubst %.c,%.o,$(SRC_C)) $(EXTRA_OBJ)
59 HDRS = $(wildcard src/*.h)
60 PUBLIC_HEADERS = $(wildcard src/git/*.h)
61 HDRS += $(PUBLIC_HEADERS)
63 GIT_LIB = libgit2.a
65 TEST_OBJ = $(patsubst %.c,%.o,\
66 $(wildcard tests/t[0-9][0-9][0-9][0-9]-*.c))
67 TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ))
68 TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE))
69 TEST_VAL = $(patsubst %.exe,%.val,$(TEST_EXE))
71 ifdef PPC_SHA1
72 EXTRA_SRC += src/ppc/sha1.c src/ppc/sha1ppc.S
73 EXTRA_OBJ += src/ppc/sha1.o src/ppc/sha1ppc.o
74 EXTRA_CFLAGS += -DPPC_SHA1
75 else
76 EXTRA_SRC += src/block-sha1/sha1.c
77 EXTRA_OBJ += src/block-sha1/sha1.o
78 endif
80 BASIC_CFLAGS := -Isrc
81 ifndef NO_VISIBILITY
82 BASIC_CFLAGS += -fvisibility=hidden
83 endif
85 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) $(EXTRA_CFLAGS)
87 all:: $(GIT_LIB)
89 clean:
90 rm -f $(GIT_LIB)
91 rm -f libgit2.pc
92 rm -f *.pdb
93 rm -f src/*.o src/*/*.o
94 rm -rf apidocs
95 rm -f *~ src/*~ src/git/*~ src/sha1/*~ src/unix/*~ src/win32/*~
96 @$(MAKE) -C tests -s --no-print-directory clean
97 @$(MAKE) -s --no-print-directory cov-clean
99 test-clean:
100 @$(MAKE) -C tests -s --no-print-directory clean
102 apidocs:
103 $(DOXYGEN) api.doxygen
104 cp CONVENTIONS apidocs/
106 test: $(GIT_LIB)
107 @$(MAKE) -C tests --no-print-directory test
109 valgrind: $(GIT_LIB)
110 @$(MAKE) -C tests --no-print-directory valgrind
112 sparse:
113 cgcc -no-compile $(ALL_CFLAGS) $(SPARSE_FLAGS) $(SRC_C)
115 install-headers: $(PUBLIC_HEADERS)
116 @$(INSTALL) -d /tmp/gitinc/git
117 @for i in $^; do cat .HEADER $$i > /tmp/gitinc/$${i##src/}; done
119 install: $(GIT_LIB) $(PUBLIC_HEADERS) libgit2.pc
120 @$(INSTALL) -d $(DESTDIR)/$(prefix)/include/git
121 @for i in $(PUBLIC_HEADERS); do \
122 cat .HEADER $$i > $(DESTDIR)/$(prefix)/include/$${i##src/}; \
123 done
124 @$(INSTALL) -d $(DESTDIR)/$(libdir)
125 @$(INSTALL) $(GIT_LIB) $(DESTDIR)/$(libdir)/libgit2.a
126 @$(INSTALL) -d $(DESTDIR)/$(libdir)/pkgconfig
127 @$(INSTALL) libgit2.pc $(DESTDIR)/$(libdir)/pkgconfig/libgit2.pc
129 uninstall:
130 @rm -f $(DESTDIR)/$(libdir)/libgit2.a
131 @rm -f $(DESTDIR)/$(libdir)/pkgconfig/libgit2.pc
132 @for i in $(PUBLIC_HEADERS); do \
133 rm -f $(DESTDIR)/$(prefix)/include/$${i##src/}; \
134 done
135 @rmdir $(DESTDIR)/$(prefix)/include/git
137 .c.o:
138 $(CC) $(ALL_CFLAGS) -c $< $(CC_OUT)$@
140 .S.o:
141 $(CC) $(ALL_CFLAGS) -c $< $(CC_OUT)$@
143 $(OBJS): $(HDRS)
144 $(GIT_LIB): $(OBJS)
145 rm -f $(GIT_LIB)
146 $(AR) $(AR_OUT)$(GIT_LIB) $(OBJS)
147 $(RANLIB) $(GIT_LIB)
149 $(TEST_OBJ) $(TEST_EXE) $(TEST_RUN) $(TEST_VAL): $(GIT_LIB)
150 @$(MAKE) -C tests --no-print-directory \
151 OS=$(OS) NO_OPENSSL=$(NO_OPENSSL) $(@F)
153 libgit2.pc: libgit2.pc.in
154 sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' $< > $@
156 .PHONY: all
157 .PHONY: clean
158 .PHONY: test $(TEST_VAL) $(TEST_RUN) $(TEST_EXE) $(TEST_OBJ)
159 .PHONY: apidocs
160 .PHONY: install-headers
161 .PHONY: install uninstall
162 .PHONY: sparse
164 ### Test suite coverage testing
166 .PHONY: coverage cov-clean cov-build cov-report
168 COV_GCDA = $(patsubst %.c,%.gcda,$(SRC_C))
169 COV_GCNO = $(patsubst %.c,%.gcno,$(SRC_C))
171 coverage:
172 @$(MAKE) -s --no-print-directory clean
173 @$(MAKE) --no-print-directory cov-build
174 @$(MAKE) --no-print-directory cov-report
176 cov-clean:
177 rm -f $(COV_GCDA) $(COV_GCNO) *.gcov untested
179 COV_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
181 cov-build:
182 $(MAKE) CFLAGS="$(COV_CFLAGS)" all
183 $(MAKE) TEST_COVERAGE=1 NO_OPENSSL=$(NO_OPENSSL) test
185 cov-report:
186 @echo "--- untested files:" | tee untested
187 @{ for f in $(SRC_C); do \
188 gcda=$$(dirname $$f)"/"$$(basename $$f .c)".gcda"; \
189 if test -f $$gcda; then \
190 gcov -b -p -o $$(dirname $$f) $$f >/dev/null; \
191 else \
192 echo $$f | tee -a untested; \
193 fi; \
194 done; }
195 @rm -f *.h.gcov
196 @echo "--- untested functions:" | tee -a untested
197 @grep '^function .* called 0' *.c.gcov \
198 | sed -e 's/\([^:]*\)\.gcov:function \([^ ]*\) called.*/\1: \2/' \
199 | sed -e 's|#|/|g' | tee -a untested