# This Makefile runs inside the bundled Git tree (vendor/git) so that it # can reuse Git's build variables and platform detection. The top-level # Makefile invokes it as: # # make -C vendor/git -f ../../source/cgit.mk ../../build/cgit # # 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 vendor/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 # a 32 KB alignment from the size of git's 64 KB packet_buffer and warns # about reducing it on every macOS link. Use override so a command-line # CFLAGS (as tools/release-build.sh passes) still keeps the flag. override CFLAGS += -fno-common -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_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 # rebuild of Git itself. 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 (CI passes # -Werror) 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 # Add -ldl to linker flags on systems that commonly use GNU libc. ifneq (,$(filter $(uname_S),Linux GNU GNU/kFreeBSD)) CGIT_LIBS += -ldl endif # glibc 2.1+ offers sendfile which the most common C library on Linux 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 += configfile.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-help.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 handles dependencies using ":=" so dependencies in CGIT_OBJS are not # handled by that and we must handle them ourselves. 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)