blob: 369f3099a9d0a28775eb618b1f2be362858354b0 [file] [log] [blame]
John Keeping5f323c12013-03-06 21:22:06 +00001# 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
John Keepingcfb77e92013-04-01 14:14:12 +01008-include $(CGIT_PREFIX)cgit.conf
9
John Keeping5f323c12013-03-06 21:22:06 +000010# 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
John Keeping7669f7f2013-03-06 21:22:09 +000014 @cd $(CGIT_PREFIX) && '$(SHELL_PATH_SQ)' ./gen-version.sh "$(CGIT_VERSION)"
John Keeping5f323c12013-03-06 21:22:06 +000015-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.
John Keeping5f323c12013-03-06 21:22:06 +000020CGIT_CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
21CGIT_CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
22CGIT_CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
23
Kylie McClain5062fbe2016-06-07 17:22:35 -040024PKG_CONFIG ?= pkg-config
25
John Keeping5f323c12013-03-06 21:22:06 +000026ifdef NO_C99_FORMAT
27 CFLAGS += -DNO_C99_FORMAT
28endif
29
Jason A. Donenfeldf43b2282014-01-13 14:18:51 +010030ifdef NO_LUA
Jason A. Donenfelda9a7f682014-01-14 13:47:28 +010031 LUA_MESSAGE := linking without specified Lua support
Jason A. Donenfeld3488d122014-01-14 01:50:31 +010032 CGIT_CFLAGS += -DNO_LUA
Jason A. Donenfeldf43b2282014-01-13 14:18:51 +010033else
Natanael Copa44ccae42014-01-22 13:15:08 +010034ifeq ($(LUA_PKGCONFIG),)
35 LUA_PKGCONFIG := $(shell for pc in luajit lua lua5.2 lua5.1; do \
Kylie McClain5062fbe2016-06-07 17:22:35 -040036 $(PKG_CONFIG) --exists $$pc 2>/dev/null && echo $$pc && break; \
Natanael Copa44ccae42014-01-22 13:15:08 +010037 done)
38 LUA_MODE := autodetected
39else
40 LUA_MODE := specified
41endif
42ifneq ($(LUA_PKGCONFIG),)
43 LUA_MESSAGE := linking with $(LUA_MODE) $(LUA_PKGCONFIG)
Kylie McClain5062fbe2016-06-07 17:22:35 -040044 LUA_LIBS := $(shell $(PKG_CONFIG) --libs $(LUA_PKGCONFIG) 2>/dev/null)
45 LUA_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(LUA_PKGCONFIG) 2>/dev/null)
Jason A. Donenfeld3488d122014-01-14 01:50:31 +010046 CGIT_LIBS += $(LUA_LIBS)
47 CGIT_CFLAGS += $(LUA_CFLAGS)
48else
Jason A. Donenfelda9a7f682014-01-14 13:47:28 +010049 LUA_MESSAGE := linking without autodetected Lua support
Jason A. Donenfeld3488d122014-01-14 01:50:31 +010050 NO_LUA := YesPlease
51 CGIT_CFLAGS += -DNO_LUA
Jason A. Donenfeldf43b2282014-01-13 14:18:51 +010052endif
53
54endif
55
Jason A. Donenfeld3488d122014-01-14 01:50:31 +010056# Add -ldl to linker flags on non-BSD systems.
57ifeq ($(findstring BSD,$(uname_S)),)
58 CGIT_LIBS += -ldl
59endif
Jason A. Donenfeldf43b2282014-01-13 14:18:51 +010060
Sebastian Andrzej Siewiord3581b52014-01-18 21:24:58 +010061# glibc 2.1+ offers sendfile which the most common C library on Linux
62ifeq ($(uname_S),Linux)
63 HAVE_LINUX_SENDFILE = YesPlease
64endif
65
66ifdef HAVE_LINUX_SENDFILE
67 CGIT_CFLAGS += -DHAVE_LINUX_SENDFILE
68endif
Jason A. Donenfeldf43b2282014-01-13 14:18:51 +010069
John Keeping5f323c12013-03-06 21:22:06 +000070CGIT_OBJ_NAMES += cgit.o
71CGIT_OBJ_NAMES += cache.o
72CGIT_OBJ_NAMES += cmd.o
73CGIT_OBJ_NAMES += configfile.o
Jason A. Donenfeld3eae4062014-01-10 05:19:05 +010074CGIT_OBJ_NAMES += filter.o
John Keeping5f323c12013-03-06 21:22:06 +000075CGIT_OBJ_NAMES += html.o
76CGIT_OBJ_NAMES += parsing.o
77CGIT_OBJ_NAMES += scan-tree.o
78CGIT_OBJ_NAMES += shared.o
79CGIT_OBJ_NAMES += ui-atom.o
80CGIT_OBJ_NAMES += ui-blob.o
81CGIT_OBJ_NAMES += ui-clone.o
82CGIT_OBJ_NAMES += ui-commit.o
83CGIT_OBJ_NAMES += ui-diff.o
84CGIT_OBJ_NAMES += ui-log.o
85CGIT_OBJ_NAMES += ui-patch.o
86CGIT_OBJ_NAMES += ui-plain.o
87CGIT_OBJ_NAMES += ui-refs.o
88CGIT_OBJ_NAMES += ui-repolist.o
89CGIT_OBJ_NAMES += ui-shared.o
90CGIT_OBJ_NAMES += ui-snapshot.o
91CGIT_OBJ_NAMES += ui-ssdiff.o
92CGIT_OBJ_NAMES += ui-stats.o
93CGIT_OBJ_NAMES += ui-summary.o
94CGIT_OBJ_NAMES += ui-tag.o
95CGIT_OBJ_NAMES += ui-tree.o
John Keeping5f323c12013-03-06 21:22:06 +000096
97CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))
98
John Keepingd6768a62013-03-06 21:22:08 +000099# Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the
100# version changes.
John Keeping5150b7c2015-03-08 16:32:15 +0000101CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o cgit.sp)
John Keepingd6768a62013-03-06 21:22:08 +0000102$(CGIT_VERSION_OBJS): $(CGIT_PREFIX)VERSION
103$(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \
104 -DCGIT_VERSION='"$(CGIT_VERSION)"'
105
John Keepinga5e4ad22013-04-04 18:32:24 +0100106# Git handles dependencies using ":=" so dependencies in CGIT_OBJ are not
107# handled by that and we must handle them ourselves.
108cgit_dep_files := $(foreach f,$(CGIT_OBJS),$(dir $f).depend/$(notdir $f).d)
109cgit_dep_files_present := $(wildcard $(cgit_dep_files))
110ifneq ($(cgit_dep_files_present),)
111include $(cgit_dep_files_present)
112endif
113
John Keeping5f323c12013-03-06 21:22:06 +0000114ifeq ($(wildcard $(CGIT_PREFIX).depend),)
115missing_dep_dirs += $(CGIT_PREFIX).depend
116endif
117
118$(CGIT_PREFIX).depend:
119 @mkdir -p $@
120
121$(CGIT_PREFIX)CGIT-CFLAGS: FORCE
122 @FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \
123 if test x"$$FLAGS" != x"`cat ../CGIT-CFLAGS 2>/dev/null`" ; then \
124 echo 1>&2 " * new CGit build flags"; \
125 echo "$$FLAGS" >$(CGIT_PREFIX)CGIT-CFLAGS; \
126 fi
127
128$(CGIT_OBJS): %.o: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS $(missing_dep_dirs)
129 $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $<
130
131$(CGIT_PREFIX)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
Jason A. Donenfelda9a7f682014-01-14 13:47:28 +0100132 @echo 1>&1 " * $(LUA_MESSAGE)"
Jason A. Donenfelde83b51b2014-01-13 14:16:18 +0100133 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS)
John Keeping5150b7c2015-03-08 16:32:15 +0000134
135CGIT_SP_OBJS := $(patsubst %.o,%.sp,$(CGIT_OBJS))
136
137$(CGIT_SP_OBJS): %.sp: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS FORCE
138 $(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $(SPARSE_FLAGS) $<
139
140cgit-sparse: $(CGIT_SP_OBJS)