# cgit top-level Makefile. cgit itself is compiled inside the bundled Git tree # by source/cgit.mk, which this file invokes; everything else (docs, install, # packaging, maintenance) is driven from here. .DEFAULT_GOAL := all .SUFFIXES: # Project layout. Sources live in source/, web assets in assets/, Lua filters # in custom/extensions/, the bundled Git tree in vendor/git, and every generated # file lands in build/. CGIT_ROOT reaches from the Git tree back to the root. SRCDIR = source ASSETDIR = assets EXTDIR = custom/extensions GITDIR = vendor/git BUILDDIR = build CGIT_ROOT = ../.. # Git release fetched by get-git when the submodule is not checked out. Keep in # step with the submodule pin in .gitmodules. GIT_VERSION = 2.55.0 GIT_URL = https://www.kernel.org/pub/software/scm/git/git-$(GIT_VERSION).tar.xz # Compiled-in cgit defaults, overridable through cgit.conf. All carry the CGIT_ # prefix except CACHE_ROOT, inherited from upstream under that name. CGIT_VERSION = v2.2.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 # Standard GNU-style install directories, lowercase so packaging can override # them; filterdir is the one cgit-specific addition. prefix = /usr/local libdir = $(prefix)/lib filterdir = $(libdir)/cgit/filters docdir = $(prefix)/share/doc/cgit htmldir = $(docdir) mandir = $(prefix)/share/man # Files installed into the data path and the filter dir. One list each drives # both install and uninstall, so the two can never drift apart. ASSETS = cgit.css cgit.js cgit.png favicon.ico robots.txt FILTER_FILES = $(notdir $(wildcard $(EXTDIR)/*.lua)) # The man-page source (*.5.txt) sits at the project root and is rendered into # build/. Only one man section exists, so DOC_* derive straight from MAN5_TXT. MAN5_TXT = $(wildcard *.5.txt) DOC_MAN5 = $(patsubst %.txt,$(BUILDDIR)/%,$(MAN5_TXT)) DOC_HTML = $(patsubst %.txt,$(BUILDDIR)/%.html,$(MAN5_TXT)) INSTALL = install 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 any of the settings # above through cgit.conf. Both includes must stay after the defaults. -include $(GITDIR)/config.mak.uname -include cgit.conf export CGIT_VERSION CGIT_SCRIPT_NAME CGIT_SCRIPT_PATH CGIT_DATA_PATH CGIT_CONFIG CACHE_ROOT 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/. # # NO_RUST keeps Cargo out of the build. Git 2.55 inverted the flag that used # to be WITH_RUST, so Rust is now compiled in unless it is turned off, and # leaving this out would quietly make Cargo a build requirement. Git 3.0 drops # the choice entirely, at which point this stops working and Rust becomes # mandatory. GIT_BUILD_FLAGS = NO_CURL=1 NO_OPENSSL=1 NO_RUST=1 cgit: +@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk \ $(CGIT_ROOT)/$(BUILDDIR)/cgit $(EXTRA_GIT_TARGETS) $(GIT_BUILD_FLAGS) sparse: +@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk \ $(GIT_BUILD_FLAGS) cgit-sparse test: cgit-with-git +@$(MAKE) -C tests all # The test helpers link against a fully built Git tree, so this asks the # sub-make for Git's own `all` alongside cgit. cgit-with-git: +@$(MAKE) cgit EXTRA_GIT_TARGETS=all doc: doc-man doc-html doc-man: $(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 $@ $< 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 $(addprefix $(ASSETDIR)/,$(ASSETS)) $(DESTDIR)$(CGIT_DATA_PATH) $(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir) $(INSTALL) -m 0644 $(EXTDIR)/*.lua $(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) uninstall: $(RM) $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) $(RM) $(addprefix $(DESTDIR)$(CGIT_DATA_PATH)/,$(ASSETS)) $(RM) $(addprefix $(DESTDIR)$(filterdir)/,$(FILTER_FILES)) 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 # 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_VERSION) $(GITDIR) tags: @mkdir -p $(BUILDDIR) find $(SRCDIR) -name '*.[ch]' | xargs ctags -f $(BUILDDIR)/tags # Grouped to mirror the order of the targets above. .PHONY: all cgit cgit-with-git sparse test .PHONY: doc doc-man doc-html .PHONY: install install-doc install-man install-html .PHONY: uninstall uninstall-doc uninstall-man uninstall-html .PHONY: clean cleanall get-git tags