diff options
| -rw-r--r-- | Makefile | 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/cgit.mk | 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0001-validate-git-versions.sh | 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 files changed, 98 insertions, 97 deletions
@@ -1,5 +1,27 @@ -all:: +# 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 extensions/, the bundled Git tree in libraries/git, and every generated +# file lands in build/. CGIT_ROOT reaches from the Git tree back to the root. +SRCDIR = source +ASSETDIR = assets +EXTDIR = extensions +GITDIR = libraries/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.54.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.1.0 CGIT_SCRIPT_NAME = cgit.cgi CGIT_SCRIPT_PATH = /var/www/htdocs/cgit @@ -7,6 +29,8 @@ 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 @@ -14,77 +38,71 @@ 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 +# 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)) -# 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/. +# 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) -MAN_TXT = $(MAN5_TXT) DOC_MAN5 = $(patsubst %.txt,$(BUILDDIR)/%,$(MAN5_TXT)) -DOC_HTML = $(patsubst %.txt,$(BUILDDIR)/%.html,$(MAN_TXT)) +DOC_HTML = $(patsubst %.txt,$(BUILDDIR)/%.html,$(MAN5_TXT)) +INSTALL = install +COPYTREE = cp -r 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. +# 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 -.SUFFIXES: - -all:: cgit +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 + +@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk \ + $(CGIT_ROOT)/$(BUILDDIR)/cgit $(EXTRA_GIT_TARGETS) NO_CURL=1 NO_OPENSSL=1 sparse: - +@$(MAKE) -C $(GITDIR) -f $(TO_ROOT)$(SRCDIR)/cgit.mk \ + +@$(MAKE) -C $(GITDIR) -f $(CGIT_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 +# 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 $(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 0644 $(addprefix $(ASSETDIR)/,$(ASSETS)) $(DESTDIR)$(CGIT_DATA_PATH) $(INSTALL) -m 0755 -d $(DESTDIR)$(filterdir) - $(COPYTREE) extensions/* $(DESTDIR)$(filterdir) + $(INSTALL) -m 0644 $(EXTDIR)/*.lua $(DESTDIR)$(filterdir) install-doc: install-man install-html @@ -96,20 +114,10 @@ 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))) + $(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 @@ -123,19 +131,6 @@ uninstall-html: 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. @@ -149,14 +144,15 @@ cleanall: clean # 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) + 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 -.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 +# 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 diff --git a/source/cgit.mk b/source/cgit.mk index 661d351..f864ecb 100644 --- a/source/cgit.mk +++ b/source/cgit.mk @@ -4,14 +4,19 @@ # # make -C libraries/git -f ../../source/cgit.mk ../../build/cgit # -# so every path back into the project is prefixed with "../../": sources come -# from ../../source and all build output goes to ../../build. +# so every path back into the project reaches through CGIT_ROOT ("../.."): +# sources come from ../../source and all build output goes to ../../build. include Makefile -# Locations relative to libraries/git, where this file is run. -CGIT_PREFIX = ../../ -CGIT_SRC = $(CGIT_PREFIX)source/ -CGIT_BUILD = $(CGIT_PREFIX)build/ +# Locations relative to libraries/git, where this file is run. SRCDIR and +# BUILDDIR name the root-relative subdirs (matching the top-level Makefile and +# used by the version recipe, which cds to the root); CGIT_SRC and CGIT_BUILD +# are their full paths from here. +CGIT_ROOT = ../.. +SRCDIR = source +BUILDDIR = build +CGIT_SRC = $(CGIT_ROOT)/$(SRCDIR) +CGIT_BUILD = $(CGIT_ROOT)/$(BUILDDIR) # Emit zero-initialised globals as plain definitions instead of common # symbols, the default everywhere but Apple clang. ld64 otherwise derives @@ -20,14 +25,14 @@ CGIT_BUILD = $(CGIT_PREFIX)build/ # CFLAGS (as tools/release-build.sh passes) still keeps the flag. override CFLAGS += -fno-common --include $(CGIT_PREFIX)cgit.conf +-include $(CGIT_ROOT)/cgit.conf # The CGIT_* variables are inherited from the top-level Makefile. -$(CGIT_BUILD)VERSION: force-version - @mkdir -p $(CGIT_BUILD) - @cd $(CGIT_PREFIX) && '$(SHELL_PATH_SQ)' source/gen-version.sh "$(CGIT_VERSION)" build/VERSION --include $(CGIT_BUILD)VERSION +$(CGIT_BUILD)/VERSION: force-version + @mkdir -p $(CGIT_BUILD)/ + @cd $(CGIT_ROOT) && '$(SHELL_PATH_SQ)' $(SRCDIR)/gen-version.sh "$(CGIT_VERSION)" $(BUILDDIR)/VERSION +-include $(CGIT_BUILD)/VERSION .PHONY: force-version # CGIT_CFLAGS is tracked separately so that changing it does not force a @@ -111,12 +116,12 @@ CGIT_OBJ_NAMES += ui-summary.o CGIT_OBJ_NAMES += ui-tag.o CGIT_OBJ_NAMES += ui-tree.o -CGIT_OBJS := $(addprefix $(CGIT_BUILD),$(CGIT_OBJ_NAMES)) +CGIT_OBJS := $(addprefix $(CGIT_BUILD)/,$(CGIT_OBJ_NAMES)) # Only cgit.c references CGIT_VERSION, so only its objects rebuild when the # version changes. -CGIT_VERSION_OBJS := $(addprefix $(CGIT_BUILD),cgit.o cgit.sp) -$(CGIT_VERSION_OBJS): $(CGIT_BUILD)VERSION +CGIT_VERSION_OBJS := $(addprefix $(CGIT_BUILD)/,cgit.o cgit.sp) +$(CGIT_VERSION_OBJS): $(CGIT_BUILD)/VERSION $(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \ -DCGIT_VERSION='"$(CGIT_VERSION)"' @@ -128,31 +133,31 @@ ifneq ($(cgit_dep_files_present),) include $(cgit_dep_files_present) endif -ifeq ($(wildcard $(CGIT_BUILD).depend),) -missing_dep_dirs += $(CGIT_BUILD).depend +ifeq ($(wildcard $(CGIT_BUILD)/.depend),) +missing_dep_dirs += $(CGIT_BUILD)/.depend endif -$(CGIT_BUILD).depend: +$(CGIT_BUILD)/.depend: @mkdir -p $@ -$(CGIT_BUILD)CGIT-CFLAGS: FORCE - @mkdir -p $(CGIT_BUILD) +$(CGIT_BUILD)/CGIT-CFLAGS: FORCE + @mkdir -p $(CGIT_BUILD)/ @FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \ - if test x"$$FLAGS" != x"`cat $(CGIT_BUILD)CGIT-CFLAGS 2>/dev/null`" ; then \ + if test x"$$FLAGS" != x"`cat $(CGIT_BUILD)/CGIT-CFLAGS 2>/dev/null`" ; then \ echo 1>&2 " * new CGit build flags"; \ - echo "$$FLAGS" >$(CGIT_BUILD)CGIT-CFLAGS; \ + echo "$$FLAGS" >$(CGIT_BUILD)/CGIT-CFLAGS; \ fi -$(CGIT_OBJS): $(CGIT_BUILD)%.o: $(CGIT_SRC)%.c GIT-CFLAGS $(CGIT_BUILD)CGIT-CFLAGS $(missing_dep_dirs) +$(CGIT_OBJS): $(CGIT_BUILD)/%.o: $(CGIT_SRC)/%.c GIT-CFLAGS $(CGIT_BUILD)/CGIT-CFLAGS $(missing_dep_dirs) $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $< -$(CGIT_BUILD)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS) - @echo 1>&1 " * $(LUA_MESSAGE)" +$(CGIT_BUILD)/cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS) + @echo 1>&2 " * $(LUA_MESSAGE)" $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS) CGIT_SP_OBJS := $(patsubst %.o,%.sp,$(CGIT_OBJS)) -$(CGIT_SP_OBJS): $(CGIT_BUILD)%.sp: $(CGIT_SRC)%.c GIT-CFLAGS $(CGIT_BUILD)CGIT-CFLAGS FORCE +$(CGIT_SP_OBJS): $(CGIT_BUILD)/%.sp: $(CGIT_SRC)/%.c GIT-CFLAGS $(CGIT_BUILD)/CGIT-CFLAGS FORCE $(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $(SPARSE_FLAGS) $< cgit-sparse: $(CGIT_SP_OBJS) diff --git a/tests/t0001-validate-git-versions.sh b/tests/t0001-validate-git-versions.sh index 79699fd..acc412d 100755 --- a/tests/t0001-validate-git-versions.sh +++ b/tests/t0001-validate-git-versions.sh @@ -9,8 +9,8 @@ CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh test_expect_success 'extract Git version from Makefile' ' - sed -n -e "/^GIT_VER[ ]*=/ { - s/^GIT_VER[ ]*=[ ]*// + sed -n -e "/^GIT_VERSION[ ]*=/ { + s/^GIT_VERSION[ ]*=[ ]*// p }" ../../Makefile >makefile_version ' |
