# The rules that compile and link cgit itself. They run with the bundled Git # tree as the working directory so that Git's build variables and platform # detection can be reused, which is why every path back into the project leads # through CGIT_ROOT. The top level Makefile invokes it roughly as # # make -C vendor/git -f ../../source/cgit.mk ../../build/cgit # # so sources are read from ../../source and all output is written to # ../../build. include Makefile # TOOLSDIR and BUILDDIR are named relative to the project root because the # version recipe changes into the root before using them. CGIT_SRC and # CGIT_BUILD lead to the sources and the output from vendor/git, where # everything else here runs. CGIT_ROOT = ../.. SRCDIR = source TOOLSDIR = tools BUILDDIR = build CGIT_SRC = $(CGIT_ROOT)/$(SRCDIR) CGIT_BUILD = $(CGIT_ROOT)/$(BUILDDIR) # Read again here because a sub make inherits only the variables the top level # Makefile exports, which leaves out the build options this file reads. -include $(CGIT_ROOT)/cgit.conf # The CGIT_ values used below are exported by the top level Makefile. $(CGIT_BUILD)/VERSION: force-version @mkdir -p $(CGIT_BUILD)/ @cd $(CGIT_ROOT) && '$(SHELL_PATH_SQ)' $(TOOLSDIR)/gen-version.sh "$(CGIT_VERSION)" $(BUILDDIR)/VERSION -include $(CGIT_BUILD)/VERSION .PHONY: force-version # The language the cgit sources are written in. Both GCC and Clang default to # this today, so pinning it changes nothing now and stops the meaning of the # sources drifting when a compiler moves its default on, as GCC 15 did by # defaulting to gnu23. The GNU dialect rather than plain c17 because git's # headers use GNU extensions, and because dlsym cannot be used through a # conforming cast. Only the cgit objects are held to this, and Git keeps # whatever its own build decides, which on some platforms is a different # standard again. CGIT_STD ?= gnu17 # CGIT_CFLAGS is tracked separately so that changing it does not force a rebuild # of Git itself. CGIT_CFLAGS += -std=$(CGIT_STD) CGIT_CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' CGIT_CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' CGIT_CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' # Reaches only the cgit objects, so a caller can tighten the build, the way the # release build passes -Werror=format-security, without holding git's own # sources to the same standard. CGIT_CFLAGS += $(CGIT_EXTRA_CFLAGS) PKG_CONFIG ?= pkg-config ifdef NO_C99_FORMAT CFLAGS += -DNO_C99_FORMAT endif ifdef NO_LUA LUA_MESSAGE := linking without specified Lua support CGIT_CFLAGS += -DNO_LUA else ifeq ($(LUA_PKGCONFIG),) LUA_PKGCONFIG := $(shell for pc in luajit lua lua5.4 lua5.3 lua5.2 lua5.1; do \ $(PKG_CONFIG) --exists $$pc 2>/dev/null && echo $$pc && break; \ done) LUA_MODE := autodetected else LUA_MODE := specified endif ifneq ($(LUA_PKGCONFIG),) LUA_MESSAGE := linking with $(LUA_MODE) $(LUA_PKGCONFIG) LUA_LIBS := $(shell $(PKG_CONFIG) --libs $(LUA_PKGCONFIG) 2>/dev/null) LUA_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(LUA_PKGCONFIG) 2>/dev/null) CGIT_LIBS += $(LUA_LIBS) CGIT_CFLAGS += $(LUA_CFLAGS) else LUA_MESSAGE := linking without autodetected Lua support NO_LUA := YesPlease CGIT_CFLAGS += -DNO_LUA endif endif # The filters reach libc's write through dlsym, which lives in a library of its # own on the systems that use GNU libc. ifneq (,$(filter $(uname_S),Linux GNU GNU/kFreeBSD)) CGIT_LIBS += -ldl endif # The cache sends a stored page straight to stdout with sendfile where it can. # Only Linux is assumed to offer it, so everywhere else falls back to reading # and writing the file by hand. ifeq ($(uname_S),Linux) HAVE_LINUX_SENDFILE = YesPlease endif ifdef HAVE_LINUX_SENDFILE CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE endif CGIT_OBJ_NAMES += cgit.o CGIT_OBJ_NAMES += cache.o CGIT_OBJ_NAMES += cmd.o CGIT_OBJ_NAMES += config.o CGIT_OBJ_NAMES += filter.o CGIT_OBJ_NAMES += html.o CGIT_OBJ_NAMES += parsing.o CGIT_OBJ_NAMES += scan-tree.o CGIT_OBJ_NAMES += shared.o CGIT_OBJ_NAMES += ui-atom.o CGIT_OBJ_NAMES += ui-blame.o CGIT_OBJ_NAMES += ui-blob.o CGIT_OBJ_NAMES += ui-clone.o CGIT_OBJ_NAMES += ui-commit.o CGIT_OBJ_NAMES += ui-diff.o CGIT_OBJ_NAMES += ui-empty.o CGIT_OBJ_NAMES += ui-log.o CGIT_OBJ_NAMES += ui-patch.o CGIT_OBJ_NAMES += ui-plain.o CGIT_OBJ_NAMES += ui-refs.o CGIT_OBJ_NAMES += ui-repolist.o CGIT_OBJ_NAMES += ui-shared.o CGIT_OBJ_NAMES += ui-snapshot.o CGIT_OBJ_NAMES += ui-ssdiff.o CGIT_OBJ_NAMES += ui-stats.o 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)) # 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): EXTRA_CPPFLAGS = \ -DCGIT_VERSION='"$(CGIT_VERSION)"' # Git builds its list of dependency files with := before this file adds the # cgit objects, so those are missing from it and have to be picked up here. cgit_dep_files := $(foreach f,$(CGIT_OBJS),$(dir $f).depend/$(notdir $f).d) cgit_dep_files_present := $(wildcard $(cgit_dep_files)) ifneq ($(cgit_dep_files_present),) include $(cgit_dep_files_present) endif ifeq ($(wildcard $(CGIT_BUILD)/.depend),) missing_dep_dirs += $(CGIT_BUILD)/.depend endif $(CGIT_BUILD)/.depend: @mkdir -p $@ $(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 \ echo 1>&2 " * new CGit build flags"; \ echo "$$FLAGS" >$(CGIT_BUILD)/CGIT-CFLAGS; \ fi $(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>&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 $(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $(SPARSE_FLAGS) $< cgit-sparse: $(CGIT_SP_OBJS)