blob: a3668d5bb54e5adcd00fdce6cce0c1d35004dad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
all::

CGIT_VERSION = v2.1.0
CGIT_SCRIPT_NAME = cgit.cgi
CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
CGIT_CONFIG = /etc/cgitrc
CACHE_ROOT = /var/cache/cgit

prefix = /usr/local
libdir = $(prefix)/lib
filterdir = $(libdir)/cgit/filters
docdir = $(prefix)/share/doc/cgit
htmldir = $(docdir)
mandir = $(prefix)/share/man

SHA1_HEADER = <openssl/sha.h>
GIT_VER = 2.54.0
GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.xz

INSTALL = install
COPYTREE = cp -r

# Project layout. Sources live in source/, web assets in assets/, the bundled
# Git tree in libraries/git, and every generated file lands in build/.
SRCDIR   = source
ASSETDIR = assets
GITDIR   = libraries/git
BUILDDIR = build

# The bundled Git tree is two levels down, so the sub-make reaches back to the
# project root with "../../".
TO_ROOT = ../../

# Documentation. The man-page source (*.5.txt) sits at the project root and is
# rendered into build/.
MAN5_TXT = $(wildcard *.5.txt)
MAN_TXT  = $(MAN5_TXT)
DOC_MAN5 = $(patsubst %.txt,$(BUILDDIR)/%,$(MAN5_TXT))
DOC_HTML = $(patsubst %.txt,$(BUILDDIR)/%.html,$(MAN_TXT))

ASCIIDOC = asciidoc
ASCIIDOC_EXTRA =
ASCIIDOC_HTML = xhtml11
ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA)
TXT_TO_HTML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML)

# Reuse Git's platform detection, then let the user override the settings
# above through cgit.conf.
-include $(GITDIR)/config.mak.uname
-include cgit.conf

export CGIT_VERSION CGIT_SCRIPT_NAME CGIT_SCRIPT_PATH CGIT_DATA_PATH CGIT_CONFIG CACHE_ROOT

.SUFFIXES:

all:: cgit

# cgit is compiled inside the bundled Git tree so it can reuse Git's build
# machinery (see source/cgit.mk). Objects and the binary go to build/.
cgit:
	+@$(MAKE) -C $(GITDIR) -f $(TO_ROOT)$(SRCDIR)/cgit.mk \
		$(TO_ROOT)$(BUILDDIR)/cgit $(EXTRA_GIT_TARGETS) NO_CURL=1 NO_OPENSSL=1

sparse:
	+@$(MAKE) -C $(GITDIR) -f $(TO_ROOT)$(SRCDIR)/cgit.mk \
		NO_CURL=1 NO_OPENSSL=1 cgit-sparse

# Building the test suite needs a fully built Git tree for its helpers, hence
# EXTRA_GIT_TARGETS=all.
test: cgit-with-git
	+@$(MAKE) -C tests all

cgit-with-git:
	+@$(MAKE) cgit EXTRA_GIT_TARGETS=all

install: all
	$(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH)
	$(INSTALL) -m 0755 $(BUILDDIR)/cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
	$(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
	$(INSTALL) -m 0644 $(ASSETDIR)/cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
	$(INSTALL) -m 0644 $(ASSETDIR)/cgit.js $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js
	$(INSTALL) -m 0644 $(ASSETDIR)/cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
	$(INSTALL) -m 0644 $(ASSETDIR)/favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico
	$(INSTALL) -m 0644 $(ASSETDIR)/robots.txt $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt
	$(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir)
	$(COPYTREE) extensions/* $(DESTDIR)$(filterdir)

install-doc: install-man install-html

install-man: doc-man
	$(INSTALL) -m 0755 -d $(DESTDIR)$(mandir)/man5
	$(INSTALL) -m 0644 $(DOC_MAN5) $(DESTDIR)$(mandir)/man5

install-html: doc-html
	$(INSTALL) -m 0755 -d $(DESTDIR)$(htmldir)
	$(INSTALL) -m 0644 $(DOC_HTML) $(DESTDIR)$(htmldir)

define rm_f
rm -f $(1)

endef

uninstall:
	rm -f $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
	rm -f $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
	rm -f $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js
	rm -f $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
	rm -f $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico
	rm -f $(DESTDIR)$(CGIT_DATA_PATH)/robots.txt
	$(foreach file,$(patsubst extensions/%,%,$(shell find extensions/ ! -type d)), \
		$(call rm_f,$(DESTDIR)$(filterdir)/$(file)))

uninstall-doc: uninstall-man uninstall-html

uninstall-man:
	@for i in $(notdir $(DOC_MAN5)); do \
	    rm -fv $(DESTDIR)$(mandir)/man5/$$i; \
	done

uninstall-html:
	@for i in $(notdir $(DOC_HTML)); do \
	    rm -fv $(DESTDIR)$(htmldir)/$$i; \
	done

doc: doc-man doc-html
doc-man: doc-man5
doc-man5: $(DOC_MAN5)
doc-html: $(DOC_HTML)

$(DOC_MAN5): $(BUILDDIR)/%.5 : %.5.txt
	@mkdir -p $(BUILDDIR)
	a2x -f manpage -D $(BUILDDIR) $<

$(DOC_HTML): $(BUILDDIR)/%.html : %.txt
	@mkdir -p $(BUILDDIR)
	$(TXT_TO_HTML) -o $@ $<

# Compiled output lives under build/; the test suite writes into tests/, so
# cleaning removes both. The tests descent is guarded because tests/Makefile
# includes git's config.mak.uname, which needs the submodule present.
clean:
	$(RM) -r $(BUILDDIR)
	@if test -e $(GITDIR)/config.mak.uname; then $(MAKE) -C tests clean; fi

cleanall: clean
	@if test -e $(GITDIR)/Makefile; then $(MAKE) -C $(GITDIR) clean; fi

# Fetch a Git release tarball for builds without the submodule checked out.
get-git:
	mkdir -p $(dir $(GITDIR))
	curl -L $(GIT_URL) | tar -xJf - && rm -rf $(GITDIR) && mv git-$(GIT_VER) $(GITDIR)

tags:
	@mkdir -p $(BUILDDIR)
	find $(SRCDIR) -name '*.[ch]' | xargs ctags -f $(BUILDDIR)/tags

.PHONY: all cgit cgit-with-git sparse test get-git tags
.PHONY: clean cleanall
.PHONY: doc doc-html doc-man doc-man5
.PHONY: install install-doc install-html install-man
.PHONY: uninstall uninstall-doc uninstall-html uninstall-man