Add some more (macro) file operation wrappers
[libgit2.git] / Makefile
blob9aa923b26f49d08404fd272e0688f57c899d9116
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 -include config.mak
57 SRC_C = $(wildcard src/*.c)
58 OS_SRC = $(wildcard src/$(OS)/*.c)
59 SRC_C += $(OS_SRC) $(EXTRA_SRC)
60 OBJS = $(patsubst %.c,%.o,$(SRC_C)) $(EXTRA_OBJ)
61 HDRS = $(wildcard src/*.h)
62 PUBLIC_HEADERS = $(wildcard src/git/*.h)
63 HDRS += $(PUBLIC_HEADERS)
65 GIT_LIB = libgit2.a
67 TEST_OBJ = $(patsubst %.c,%.o,\
68 $(wildcard tests/t[0-9][0-9][0-9][0-9]-*.c))
69 TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ))
70 TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE))
71 TEST_VAL = $(patsubst %.exe,%.val,$(TEST_EXE))
73 ifdef PPC_SHA1
74 EXTRA_SRC += src/ppc/sha1.c
75 EXTRA_OBJ += src/ppc/sha1ppc.o
76 EXTRA_CFLAGS += -DPPC_SHA1
77 else
78 EXTRA_SRC += src/block-sha1/sha1.c
79 endif
81 BASIC_CFLAGS := -Isrc
82 ifndef NO_VISIBILITY
83 BASIC_CFLAGS += -fvisibility=hidden
84 endif
86 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) $(EXTRA_CFLAGS)
88 all:: $(GIT_LIB)
90 clean:
91 rm -f $(GIT_LIB)
92 rm -f libgit2.pc
93 rm -f *.pdb
94 rm -f src/*.o src/*/*.o
95 rm -rf apidocs
96 rm -f *~ src/*~ src/*/*~
97 @$(MAKE) -C tests -s --no-print-directory clean
98 @$(MAKE) -s --no-print-directory cov-clean
100 test-clean:
101 @$(MAKE) -C tests -s --no-print-directory clean
103 apidocs:
104 $(DOXYGEN) api.doxygen
105 cp CONVENTIONS apidocs/
107 test: $(GIT_LIB)
108 @$(MAKE) -C tests --no-print-directory test
110 valgrind: $(GIT_LIB)
111 @$(MAKE) -C tests --no-print-directory valgrind
113 sparse:
114 cgcc -no-compile $(ALL_CFLAGS) $(SPARSE_FLAGS) $(SRC_C)
116 install-headers: $(PUBLIC_HEADERS)
117 @$(INSTALL) -d /tmp/gitinc/git
118 @for i in $^; do cat .HEADER $$i > /tmp/gitinc/$${i##src/}; done
120 install: $(GIT_LIB) $(PUBLIC_HEADERS) libgit2.pc
121 @$(INSTALL) -d $(DESTDIR)/$(prefix)/include/git
122 @for i in $(PUBLIC_HEADERS); do \
123 cat .HEADER $$i > $(DESTDIR)/$(prefix)/include/$${i##src/}; \
124 done
125 @$(INSTALL) -d $(DESTDIR)/$(libdir)
126 @$(INSTALL) $(GIT_LIB) $(DESTDIR)/$(libdir)/libgit2.a
127 @$(INSTALL) -d $(DESTDIR)/$(libdir)/pkgconfig
128 @$(INSTALL) libgit2.pc $(DESTDIR)/$(libdir)/pkgconfig/libgit2.pc
130 uninstall:
131 @rm -f $(DESTDIR)/$(libdir)/libgit2.a
132 @rm -f $(DESTDIR)/$(libdir)/pkgconfig/libgit2.pc
133 @for i in $(PUBLIC_HEADERS); do \
134 rm -f $(DESTDIR)/$(prefix)/include/$${i##src/}; \
135 done
136 @rmdir $(DESTDIR)/$(prefix)/include/git
138 .c.o:
139 $(CC) $(ALL_CFLAGS) -c $< $(CC_OUT)$@
141 .S.o:
142 $(CC) $(ALL_CFLAGS) -c $< $(CC_OUT)$@
144 $(OBJS): $(HDRS)
145 $(GIT_LIB): $(OBJS)
146 rm -f $(GIT_LIB)
147 $(AR) $(AR_OUT)$(GIT_LIB) $(OBJS)
148 $(RANLIB) $(GIT_LIB)
150 $(TEST_OBJ) $(TEST_EXE) $(TEST_RUN) $(TEST_VAL): $(GIT_LIB)
151 @$(MAKE) -C tests --no-print-directory \
152 OS=$(OS) $(@F)
154 libgit2.pc: libgit2.pc.in
155 sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' $< > $@
157 .PHONY: all
158 .PHONY: clean
159 .PHONY: test $(TEST_VAL) $(TEST_RUN) $(TEST_EXE) $(TEST_OBJ)
160 .PHONY: apidocs
161 .PHONY: install-headers
162 .PHONY: install uninstall
163 .PHONY: sparse
165 ### Test suite coverage testing
167 .PHONY: coverage cov-clean cov-build cov-report
169 COV_GCDA = $(patsubst %.c,%.gcda,$(SRC_C))
170 COV_GCNO = $(patsubst %.c,%.gcno,$(SRC_C))
172 coverage:
173 @$(MAKE) -s --no-print-directory clean
174 @$(MAKE) --no-print-directory cov-build
175 @$(MAKE) --no-print-directory cov-report
177 cov-clean:
178 rm -f $(COV_GCDA) $(COV_GCNO) *.gcov untested
180 COV_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
182 cov-build:
183 $(MAKE) CFLAGS="$(COV_CFLAGS)" all
184 $(MAKE) TEST_COVERAGE=1 test
186 cov-report:
187 @echo "--- untested files:" | tee untested
188 @{ for f in $(SRC_C); do \
189 gcda=$$(dirname $$f)"/"$$(basename $$f .c)".gcda"; \
190 if test -f $$gcda; then \
191 gcov -b -p -o $$(dirname $$f) $$f >/dev/null; \
192 else \
193 echo $$f | tee -a untested; \
194 fi; \
195 done; }
196 @rm -f *.h.gcov
197 @echo "--- untested functions:" | tee -a untested
198 @grep '^function .* called 0' *.c.gcov \
199 | sed -e 's/\([^:]*\)\.gcov:function \([^ ]*\) called.*/\1: \2/' \
200 | sed -e 's|#|/|g' | tee -a untested