aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorGravatar Jamie Couture <jamie.couture@gmail.com>2012-11-18 03:02:17 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2013-03-04 23:25:24 (JST)
commitca59b26dfd6e5bed6622fad2c57d57083714f9e7 (patch)
treebea135c1e603b0986f6b986c11727b59946c9ecb /Makefile
parentfac4da38a074a831e2ef2476dde23a6bc073cc28 (diff)
downloadcgit-ca59b26dfd6e5bed6622fad2c57d57083714f9e7.zip
cgit-ca59b26dfd6e5bed6622fad2c57d57083714f9e7.tar.gz
Makefile: improve dependency generation
Makefile target generation would always be included for any makefile target that was not clean. Only care to include the '.deps' directory when building cgit, rather than generating and including dependencies when calling other makefile targets. Heavily borrowed from git's Makefile, but without definitions to test for the compiler's header dependency feature. Previous Makefile implementation never checked for this compiler feature anyway. - Removed makecmdgoal 'clean' check - Grouped like .PHONY target definitions - Place build dependency targets under .SUFFIXES - Re-arranged location of library inclusion definitions - Use google code mirror instead of github Signed-off-by: Jamie Couture <jamie.couture@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile152
1 files changed, 82 insertions, 70 deletions
diff --git a/Makefile b/Makefile
index bbce29d..42e8bfd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
1all::
2
1CGIT_VERSION = v0.9.1 3CGIT_VERSION = v0.9.1
2CGIT_SCRIPT_NAME = cgit.cgi 4CGIT_SCRIPT_NAME = cgit.cgi
3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit 5CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
@@ -12,8 +14,8 @@ htmldir = $(docdir)
12pdfdir = $(docdir) 14pdfdir = $(docdir)
13mandir = $(prefix)/share/man 15mandir = $(prefix)/share/man
14SHA1_HEADER = <openssl/sha.h> 16SHA1_HEADER = <openssl/sha.h>
15GIT_VER = 1.7.4 17GIT_VER = 1.7.12.4
16GIT_URL = https://github.com/git/git/archive/v$(GIT_VER).tar.gz 18GIT_URL = https://git-core.googlecode.com/files/git-$(GIT_VER).tar.gz
17INSTALL = install 19INSTALL = install
18MAN5_TXT = $(wildcard *.5.txt) 20MAN5_TXT = $(wildcard *.5.txt)
19MAN_TXT = $(MAN5_TXT) 21MAN_TXT = $(MAN5_TXT)
@@ -40,22 +42,14 @@ DOC_PDF = $(patsubst %.txt,%.pdf,$(MAN_TXT))
40# Platform specific tweaks 42# Platform specific tweaks
41# 43#
42 44
45VERSION: force-version
46 @./gen-version.sh "$(CGIT_VERSION)"
47-include VERSION
48
43uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 49uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
44uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') 50uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
45uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') 51uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
46 52
47ifeq ($(uname_O),Cygwin)
48 NO_STRCASESTR = YesPlease
49 NEEDS_LIBICONV = YesPlease
50endif
51
52ifeq ($(uname_S),$(filter $(uname_S),FreeBSD OpenBSD))
53 # Apparantly libiconv is installed in /usr/local on BSD
54 LDFLAGS ?= -L/usr/local/lib
55 CFLAGS ?= -I/usr/local/include
56 NEEDS_LIBICONV = yes
57endif
58
59# 53#
60# Let the user override the above settings. 54# Let the user override the above settings.
61# 55#
@@ -76,30 +70,62 @@ endif
76 70
77ifndef V 71ifndef V
78 QUIET_CC = @echo ' ' CC $@; 72 QUIET_CC = @echo ' ' CC $@;
79 QUIET_MM = @echo ' ' MM $@; 73 QUIET_LINK = @echo ' ' LINK $@;
80 QUIET_SUBDIR0 = +@subdir= 74 QUIET_SUBDIR0 = +@subdir=
81 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ 75 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
82 $(MAKE) $(PRINT_DIR) -C $$subdir 76 $(MAKE) $(PRINT_DIR) -C $$subdir
83 QUIET_TAGS = @echo ' ' TAGS $@; 77 QUIET_TAGS = @echo ' ' TAGS $@;
78 export V
84endif 79endif
85 80
86# 81LDFLAGS ?=
87# Define a pattern rule for automatic dependency building 82CFLAGS ?= -g -Wall
88# 83CFLAGS += -Igit
89%.d: %.c 84CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
90 $(QUIET_MM)$(CC) $(CFLAGS) -MM -MP $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ 85CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
86CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
87CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
88CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
91 89
92# 90ifeq ($(uname_O),Cygwin)
93# Define a pattern rule for silent object building 91 NO_STRCASESTR = YesPlease
94# 92 NEEDS_LIBICONV = YesPlease
95%.o: %.c 93endif
96 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
97 94
95ifeq ($(uname_S),$(filter $(uname_S),FreeBSD OpenBSD))
96 # Apparantly libiconv is installed in /usr/local on BSD
97 LDFLAGS += -L/usr/local/lib
98 CFLAGS += -I/usr/local/include
99 NEEDS_LIBICONV = yes
100endif
98 101
99EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread 102GIT_OPTIONS = prefix=/usr
100OBJECTS = 103OBJECTS =
101OBJECTS += cache.o 104
105ifdef NO_ICONV
106 CFLAGS += -DNO_ICONV
107endif
108ifdef NO_STRCASESTR
109 CFLAGS += -DNO_STRCASESTR
110endif
111ifdef NO_C99_FORMAT
112 CFLAGS += -DNO_C99_FORMAT
113endif
114ifdef NO_OPENSSL
115 CFLAGS += -DNO_OPENSSL
116 GIT_OPTIONS += NO_OPENSSL=1
117else
118 LDLIBS += -lcrypto
119endif
120
121ifdef NEEDS_LIBICONV
122 LDLIBS += -liconv
123endif
124
125LDLIBS += git/libgit.a git/xdiff/lib.a -lz -lpthread
126
102OBJECTS += cgit.o 127OBJECTS += cgit.o
128OBJECTS += cache.o
103OBJECTS += cmd.o 129OBJECTS += cmd.o
104OBJECTS += configfile.o 130OBJECTS += configfile.o
105OBJECTS += html.o 131OBJECTS += html.o
@@ -125,55 +151,30 @@ OBJECTS += ui-tag.o
125OBJECTS += ui-tree.o 151OBJECTS += ui-tree.o
126OBJECTS += vector.o 152OBJECTS += vector.o
127 153
128ifdef NEEDS_LIBICONV 154dep_files := $(foreach f,$(OBJECTS),$(dir $f).deps/$(notdir $f).d)
129 EXTLIBS += -liconv 155dep_dirs := $(addsuffix .deps,$(sort $(dir $OBJECTS)))
130endif
131 156
157$(dep_dirs):
158 @mkdir -p $@
132 159
133.PHONY: all libgit test install uninstall clean force-version get-git \ 160missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs))
134 doc clean-doc install-doc install-man install-html install-pdf \ 161dep_file = $(dir $@).deps/$(notdir $@).d
135 uninstall-doc uninstall-man uninstall-html uninstall-pdf tags 162dep_args = -MF $(dep_file) -MMD -MP
136 163
137all: cgit 164.SUFFIXES:
138 165
139VERSION: force-version 166$(OBJECTS): %.o: %.c $(missing_dep_dirs)
140 @./gen-version.sh "$(CGIT_VERSION)" 167 $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(CFLAGS) $<
141-include VERSION
142 168
143 169dep_files_present := $(wildcard $(dep_files))
144CFLAGS += -g -Wall -Igit 170ifneq ($(dep_files_present),)
145CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' 171include $(dep_files_present)
146CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
147CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
148CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
149CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
150
151GIT_OPTIONS = prefix=/usr
152
153ifdef NO_ICONV
154 CFLAGS += -DNO_ICONV
155endif 172endif
156ifdef NO_STRCASESTR
157 CFLAGS += -DNO_STRCASESTR
158endif
159ifdef NO_C99_FORMAT
160 CFLAGS += -DNO_C99_FORMAT
161endif
162ifdef NO_OPENSSL
163 CFLAGS += -DNO_OPENSSL
164 GIT_OPTIONS += NO_OPENSSL=1
165else
166 EXTLIBS += -lcrypto
167endif
168
169cgit: $(OBJECTS) libgit
170 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
171 173
172cgit.o: VERSION 174all:: cgit
173 175
174ifneq "$(MAKECMDGOALS)" "clean" 176cgit: VERSION $(OBJECTS) libgit
175 -include $(OBJECTS:.o=.d) 177 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
176endif
177 178
178libgit: 179libgit:
179 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a 180 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a
@@ -243,13 +244,24 @@ $(DOC_PDF): %.pdf : %.txt
243 a2x -f pdf cgitrc.5.txt 244 a2x -f pdf cgitrc.5.txt
244 245
245clean: clean-doc 246clean: clean-doc
246 rm -f cgit VERSION *.o *.d tags 247 $(RM) cgit VERSION *.o tags
248 $(RM) -r .deps
249
250cleanall: clean
251 $(MAKE) -C git clean
247 252
248clean-doc: 253clean-doc:
249 rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo 254 $(RM) cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo
250 255
251get-git: 256get-git:
252 curl -L $(GIT_URL) | tar -xzf - && rm -rf git && mv git-$(GIT_VER) git 257 curl -L $(GIT_URL) | tar -xzf - && rm -rf git && mv git-$(GIT_VER) git
253 258
254tags: 259tags:
255 $(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags 260 $(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags
261
262.PHONY: all cgit get-git libgit force-version
263.PHONY: clean clean-doc cleanall
264.PHONY: doc doc-html doc-man doc-pdf
265.PHONY: install install-doc install-html install-man install-pdf
266.PHONY: tags test
267.PHONY: uninstall uninstall-doc uninstall-html uninstall-man uninstall-pdf