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 "../".
8 -include $(CGIT_PREFIX)cgit.conf
10 # The CGIT_* variables are inherited when this file is called from the
11 # main Makefile - they are defined there.
13 $(CGIT_PREFIX)VERSION: force-version
14 @cd $(CGIT_PREFIX) && '$(SHELL_PATH_SQ)' ./gen-version.sh "$(CGIT_VERSION)"
15 -include $(CGIT_PREFIX)VERSION
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.
20 CGIT_CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
21 CGIT_CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
22 CGIT_CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
25 CFLAGS += -DNO_C99_FORMAT
29 LUA_MESSAGE := linking without specified Lua support
30 CGIT_CFLAGS += -DNO_LUA
32 LUAJIT_CFLAGS := $(shell pkg-config --cflags luajit 2>/dev/null)
33 LUAJIT_LIBS := $(shell pkg-config --libs luajit 2>/dev/null)
34 LUA_LIBS := $(shell pkg-config --libs lua 2>/dev/null)
35 LUA_CFLAGS := $(shell pkg-config --cflags lua 2>/dev/null)
36 ifeq (JIT,$(LUA_IMPLEMENTATION))
37 ifeq ($(strip $(LUAJIT_LIBS)),)
38 $(error LuaJIT specified via LUA_IMPLEMENTATION=JIT, but library could not be found.)
40 LUA_MESSAGE := linking with selected LuaJIT
41 CGIT_LIBS += $(LUAJIT_LIBS)
42 CGIT_CFLAGS += $(LUAJIT_CFLAGS)
43 else ifeq (VANILLA,$(LUA_IMPLEMENTATION))
44 ifeq ($(strip $(LUA_LIBS)),)
45 $(error Lua specified via LUA_IMPLEMENTATION=VANILLA, but library could not be found.)
47 LUA_MESSAGE := linking with selected Lua
48 CGIT_LIBS += $(LUA_LIBS)
49 CGIT_LIBS += $(LUA_CFLAGS)
50 else ifneq ($(strip $(LUAJIT_LIBS)),)
51 LUA_MESSAGE := linking with autodetected LuaJIT
52 CGIT_LIBS += $(LUAJIT_LIBS)
53 CGIT_CFLAGS += $(LUAJIT_CFLAGS)
54 else ifneq ($(strip $(LUA_LIBS)),)
55 LUA_MESSAGE := linking with autodetected Lua
56 CGIT_LIBS += $(LUA_LIBS)
57 CGIT_CFLAGS += $(LUA_CFLAGS)
59 LUA_MESSAGE := linking without autodetected Lua support
61 CGIT_CFLAGS += -DNO_LUA
66 # Add -ldl to linker flags on non-BSD systems.
67 ifeq ($(findstring BSD,$(uname_S)),)
71 # glibc 2.1+ offers sendfile which the most common C library on Linux
72 ifeq ($(uname_S),Linux)
73 HAVE_LINUX_SENDFILE = YesPlease
76 ifdef HAVE_LINUX_SENDFILE
77 CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE
80 CGIT_OBJ_NAMES += cgit.o
81 CGIT_OBJ_NAMES += cache.o
82 CGIT_OBJ_NAMES += cmd.o
83 CGIT_OBJ_NAMES += configfile.o
84 CGIT_OBJ_NAMES += filter.o
85 CGIT_OBJ_NAMES += html.o
86 CGIT_OBJ_NAMES += parsing.o
87 CGIT_OBJ_NAMES += scan-tree.o
88 CGIT_OBJ_NAMES += shared.o
89 CGIT_OBJ_NAMES += ui-atom.o
90 CGIT_OBJ_NAMES += ui-blob.o
91 CGIT_OBJ_NAMES += ui-clone.o
92 CGIT_OBJ_NAMES += ui-commit.o
93 CGIT_OBJ_NAMES += ui-diff.o
94 CGIT_OBJ_NAMES += ui-log.o
95 CGIT_OBJ_NAMES += ui-patch.o
96 CGIT_OBJ_NAMES += ui-plain.o
97 CGIT_OBJ_NAMES += ui-refs.o
98 CGIT_OBJ_NAMES += ui-repolist.o
99 CGIT_OBJ_NAMES += ui-shared.o
100 CGIT_OBJ_NAMES += ui-snapshot.o
101 CGIT_OBJ_NAMES += ui-ssdiff.o
102 CGIT_OBJ_NAMES += ui-stats.o
103 CGIT_OBJ_NAMES += ui-summary.o
104 CGIT_OBJ_NAMES += ui-tag.o
105 CGIT_OBJ_NAMES += ui-tree.o
107 CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))
109 # Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the
111 CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o)
112 $(CGIT_VERSION_OBJS): $(CGIT_PREFIX)VERSION
113 $(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \
114 -DCGIT_VERSION='"$(CGIT_VERSION)"'
116 # Git handles dependencies using ":=" so dependencies in CGIT_OBJ are not
117 # handled by that and we must handle them ourselves.
118 cgit_dep_files := $(foreach f,$(CGIT_OBJS),$(dir $f).depend/$(notdir $f).d)
119 cgit_dep_files_present := $(wildcard $(cgit_dep_files))
120 ifneq ($(cgit_dep_files_present),)
121 include $(cgit_dep_files_present)
124 ifeq ($(wildcard $(CGIT_PREFIX).depend),)
125 missing_dep_dirs += $(CGIT_PREFIX).depend
128 $(CGIT_PREFIX).depend:
131 $(CGIT_PREFIX)CGIT-CFLAGS: FORCE
132 @FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \
133 if test x"$$FLAGS" != x"`cat ../CGIT-CFLAGS 2>/dev/null`" ; then \
134 echo 1>&2 " * new CGit build flags"; \
135 echo "$$FLAGS" >$(CGIT_PREFIX)CGIT-CFLAGS; \
138 $(CGIT_OBJS): %.o: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS $(missing_dep_dirs)
139 $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $<
141 $(CGIT_PREFIX)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
142 @echo 1>&1 " * $(LUA_MESSAGE)"
143 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS)