cgit.mk (view raw)
1# This Makefile is run in the "git" directory in order to re-use Git's
2# build variables and operating system detection. Hence all files in
3# CGit's directory must be prefixed with "../".
4include Makefile
5
6CGIT_PREFIX = ../
7
8-include $(CGIT_PREFIX)cgit.conf
9
10# The CGIT_* variables are inherited when this file is called from the
11# main Makefile - they are defined there.
12
13$(CGIT_PREFIX)VERSION: force-version
14 @cd $(CGIT_PREFIX) && '$(SHELL_PATH_SQ)' ./gen-version.sh "$(CGIT_VERSION)"
15-include $(CGIT_PREFIX)VERSION
16.PHONY: force-version
17
18# CGIT_CFLAGS is a separate variable so that we can track it separately
19# and avoid rebuilding all of Git when these variables change.
20CGIT_CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
21CGIT_CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
22CGIT_CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
23
24ifdef NO_C99_FORMAT
25 CFLAGS += -DNO_C99_FORMAT
26endif
27
28ifdef NO_LUA
29 LUA_MESSAGE := linking without specified Lua support
30 CGIT_CFLAGS += -DNO_LUA
31else
32ifeq ($(LUA_PKGCONFIG),)
33 LUA_PKGCONFIG := $(shell for pc in luajit lua lua5.2 lua5.1; do \
34 pkg-config --exists $$pc && echo $$pc && break; \
35 done)
36 LUA_MODE := autodetected
37else
38 LUA_MODE := specified
39endif
40ifneq ($(LUA_PKGCONFIG),)
41 LUA_MESSAGE := linking with $(LUA_MODE) $(LUA_PKGCONFIG)
42 LUA_LIBS := $(shell pkg-config --libs $(LUA_PKGCONFIG) 2>/dev/null)
43 LUA_CFLAGS := $(shell pkg-config --cflags $(LUA_PKGCONFIG) 2>/dev/null)
44 CGIT_LIBS += $(LUA_LIBS)
45 CGIT_CFLAGS += $(LUA_CFLAGS)
46else
47 LUA_MESSAGE := linking without autodetected Lua support
48 NO_LUA := YesPlease
49 CGIT_CFLAGS += -DNO_LUA
50endif
51
52endif
53
54# Add -ldl to linker flags on non-BSD systems.
55ifeq ($(findstring BSD,$(uname_S)),)
56 CGIT_LIBS += -ldl
57endif
58
59# glibc 2.1+ offers sendfile which the most common C library on Linux
60ifeq ($(uname_S),Linux)
61 HAVE_LINUX_SENDFILE = YesPlease
62endif
63
64ifdef HAVE_LINUX_SENDFILE
65 CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE
66endif
67
68CGIT_OBJ_NAMES += cgit.o
69CGIT_OBJ_NAMES += cache.o
70CGIT_OBJ_NAMES += cmd.o
71CGIT_OBJ_NAMES += configfile.o
72CGIT_OBJ_NAMES += filter.o
73CGIT_OBJ_NAMES += html.o
74CGIT_OBJ_NAMES += parsing.o
75CGIT_OBJ_NAMES += scan-tree.o
76CGIT_OBJ_NAMES += shared.o
77CGIT_OBJ_NAMES += ui-atom.o
78CGIT_OBJ_NAMES += ui-blob.o
79CGIT_OBJ_NAMES += ui-clone.o
80CGIT_OBJ_NAMES += ui-commit.o
81CGIT_OBJ_NAMES += ui-diff.o
82CGIT_OBJ_NAMES += ui-log.o
83CGIT_OBJ_NAMES += ui-patch.o
84CGIT_OBJ_NAMES += ui-plain.o
85CGIT_OBJ_NAMES += ui-refs.o
86CGIT_OBJ_NAMES += ui-repolist.o
87CGIT_OBJ_NAMES += ui-shared.o
88CGIT_OBJ_NAMES += ui-snapshot.o
89CGIT_OBJ_NAMES += ui-ssdiff.o
90CGIT_OBJ_NAMES += ui-stats.o
91CGIT_OBJ_NAMES += ui-summary.o
92CGIT_OBJ_NAMES += ui-tag.o
93CGIT_OBJ_NAMES += ui-tree.o
94
95CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))
96
97# Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the
98# version changes.
99CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o)
100$(CGIT_VERSION_OBJS): $(CGIT_PREFIX)VERSION
101$(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \
102 -DCGIT_VERSION='"$(CGIT_VERSION)"'
103
104# Git handles dependencies using ":=" so dependencies in CGIT_OBJ are not
105# handled by that and we must handle them ourselves.
106cgit_dep_files := $(foreach f,$(CGIT_OBJS),$(dir $f).depend/$(notdir $f).d)
107cgit_dep_files_present := $(wildcard $(cgit_dep_files))
108ifneq ($(cgit_dep_files_present),)
109include $(cgit_dep_files_present)
110endif
111
112ifeq ($(wildcard $(CGIT_PREFIX).depend),)
113missing_dep_dirs += $(CGIT_PREFIX).depend
114endif
115
116$(CGIT_PREFIX).depend:
117 @mkdir -p $@
118
119$(CGIT_PREFIX)CGIT-CFLAGS: FORCE
120 @FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \
121 if test x"$$FLAGS" != x"`cat ../CGIT-CFLAGS 2>/dev/null`" ; then \
122 echo 1>&2 " * new CGit build flags"; \
123 echo "$$FLAGS" >$(CGIT_PREFIX)CGIT-CFLAGS; \
124 fi
125
126$(CGIT_OBJS): %.o: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS $(missing_dep_dirs)
127 $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $<
128
129$(CGIT_PREFIX)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
130 @echo 1>&1 " * $(LUA_MESSAGE)"
131 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS)