Makefile 8.69 KB
Newer Older
1
# See LICENSE file for license and copyright information
Moritz Lipp's avatar
Moritz Lipp committed
2

3
include config.mk
Moritz Lipp's avatar
Moritz Lipp committed
4
include colors.mk
5
include common.mk
Moritz Lipp's avatar
Moritz Lipp committed
6

7
# source files
8
OSOURCE       = $(sort $(wildcard ${PROJECT}/*.c) \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
9
                ${PROJECT}/resources.c)
10
SOURCE_FILTER =
11

12 13
ifneq (${WITH_SQLITE},0)
CPPFLAGS += -DWITH_SQLITE
14
else
15
SOURCE_FILTER += ${PROJECT}/database-sqlite.c
16 17
endif

18 19 20 21
ifneq ($(WITH_MAGIC),0)
CPPFLAGS += -DWITH_MAGIC
endif

22 23
ifneq ($(WITH_SYNCTEX),0)
CPPFLAGS += -DWITH_SYNCTEX
24 25
endif

26 27 28 29
ifneq ($(wildcard ${VALGRIND_SUPPRESSION_FILE}),)
VALGRIND_ARGUMENTS += --suppressions=${VALGRIND_SUPPRESSION_FILE}
endif

30 31 32 33 34 35 36 37 38 39
ifeq (,$(findstring -DZATHURA_PLUGINDIR,${CPPFLAGS}))
CPPFLAGS += -DZATHURA_PLUGINDIR=\"${PLUGINDIR}\"
endif
ifeq (,$(findstring -DGETTEXT_PACKAGE,${CPPFLAGS}))
CPPFLAGS += -DGETTEXT_PACKAGE=\"${PROJECT}\"
endif
ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS}))
CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\"
endif

40
SOURCE        = $(filter-out $(SOURCE_FILTER),$(OSOURCE))
41 42 43
OBJECTS       = $(addprefix ${BUILDDIR_RELEASE}/,${SOURCE:.c=.o})
OBJECTS_DEBUG = $(addprefix ${BUILDDIR_DEBUG}/,${SOURCE:.c=.o})
OBJECTS_GCOV  = $(addprefix ${BUILDDIR_GCOV}/,${SOURCE:.c=.o})
Moritz Lipp's avatar
Moritz Lipp committed
44
HEADERINST    = $(addprefix ${PROJECT}/,version.h document.h macros.h page.h types.h plugin-api.h links.h)
45

46
all: options ${PROJECT} po build-manpages
47

48
# pkg-config based version checks
49
.version-checks/%: config.mk
50
	$(QUIET)test $($(*)_VERSION_CHECK) -eq 0 || \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
51
		${PKG_CONFIG} --atleast-version $($(*)_MIN_VERSION) $($(*)_PKG_CONFIG_NAME) || ( \
NGKS's avatar
NGKS committed
52
		echo "The minimum required version of $(*) is $($(*)_MIN_VERSION)" && \
53 54 55 56
		false \
	)
	@mkdir -p .version-checks
	$(QUIET)touch $@
57

58
options:
Moritz Lipp's avatar
Moritz Lipp committed
59
	@echo ${PROJECT} build options:
60
	@echo "CFLAGS  = ${CFLAGS}"
Moritz Lipp's avatar
Moritz Lipp committed
61
	@echo "LIBS    = ${LIBS}"
62 63 64
	@echo "DFLAGS  = ${DFLAGS}"
	@echo "CC      = ${CC}"

65 66
# generated files

Moritz Lipp's avatar
Moritz Lipp committed
67
${PROJECT}/version.h: ${PROJECT}/version.h.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
68 69 70 71
	$(QUIET)sed -e 's/ZVMAJOR/${ZATHURA_VERSION_MAJOR}/' \
		-e 's/ZVMINOR/${ZATHURA_VERSION_MINOR}/' \
		-e 's/ZVREV/${ZATHURA_VERSION_REV}/' \
		-e 's/ZVAPI/${ZATHURA_API_VERSION}/' \
72 73
		-e 's/ZVABI/${ZATHURA_ABI_VERSION}/' ${PROJECT}/version.h.in > ${PROJECT}/version.h.tmp
	$(QUIET)mv ${PROJECT}/version.h.tmp ${PROJECT}/version.h
74

Sebastian Ramacher's avatar
Sebastian Ramacher committed
75
${PROJECT}/resources.%: data/zathura.gresource.xml config.mk
76 77
	$(call colorecho,GEN,$@)
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
78
	$(QUIET)$(GLIB_COMPILE_RESOURCES) --generate --c-name=zathura_resources --internal \
79
		--dependency-file=$(DEPENDDIR)/$@.dep \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
80
		--sourcedir=data --target=$@ data/zathura.gresource.xml
81

82
# common dependencies
Moritz Lipp's avatar
Moritz Lipp committed
83

84
${OBJECTS} ${OBJECTS_DEBUG} ${OBJECTS_GCOV}: config.mk \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
85
	${PROJECT}/version.h ${PROJECT}/resources.h \
Moritz Lipp's avatar
Moritz Lipp committed
86 87
	.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK

88 89
# rlease build

Moritz Lipp's avatar
Moritz Lipp committed
90
${BUILDDIR_RELEASE}/%.o: %.c
Moritz Lipp's avatar
Moritz Lipp committed
91
	$(call colorecho,CC,$<)
92
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
93
	@mkdir -p $(dir $(abspath $@))
94
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
Moritz Lipp's avatar
Moritz Lipp committed
95

96
${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT}: ${OBJECTS}
Moritz Lipp's avatar
Moritz Lipp committed
97 98 99 100
	$(call colorecho,CC,$@)
	@mkdir -p ${BUILDDIR_RELEASE}/${BINDIR}
	$(QUIET)${CC} ${SFLAGS} ${LDFLAGS} \
		-o ${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT} ${OBJECTS} ${LIBS}
101

102 103 104 105
${PROJECT}: ${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT}

release: ${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
106 107 108
run: release
	$(QUIET)./${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
109 110 111
# debug build

${BUILDDIR_DEBUG}/%.o: %.c
Moritz Lipp's avatar
Moritz Lipp committed
112
	$(call colorecho,CC,$<)
113
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
114 115
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} \
116
		-o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
Moritz Lipp's avatar
Moritz Lipp committed
117

118
${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}: ${OBJECTS_DEBUG}
Moritz Lipp's avatar
Moritz Lipp committed
119 120
	$(call colorecho,CC,$@)
	@mkdir -p ${BUILDDIR_DEBUG}/${BINDIR}
121 122
	$(QUIET)${CC} ${LDFLAGS} \
		-o ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT} ${OBJECTS_DEBUG} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
123

124
debug: ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
125

Moritz Lipp's avatar
Moritz Lipp committed
126 127 128
run-debug: debug
	$(QUIET)./${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
129
# gcov build
130

Moritz Lipp's avatar
Moritz Lipp committed
131 132
${BUILDDIR_GCOV}/%.o: %.c
	$(call colorecho,CC,$<)
133
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
134 135
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${GCOV_CFLAGS} \
136
		-o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
Moritz Lipp's avatar
Moritz Lipp committed
137

138
${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}: ${OBJECTS_GCOV}
Moritz Lipp's avatar
Moritz Lipp committed
139
	$(call colorecho,CC,$@)
Moritz Lipp's avatar
Moritz Lipp committed
140
	@mkdir -p ${BUILDDIR_GCOV}/${BINDIR}
141
	$(QUIET)${CC} ${LDFLAGS} ${GCOV_CFLAGS} ${GCOV_LDFLAGS} \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
142
		-o ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT} ${OBJECTS_GCOV} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
143

144
gcov: options ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
145 146 147 148 149 150
	$(QUIET)${MAKE} -C tests run-gcov
	$(call colorecho,LCOV,"Analyse data")
	$(QUIET)${LCOV_EXEC} ${LCOV_FLAGS}
	$(call colorecho,LCOV,"Generate report")
	$(QUIET)${GENHTML_EXEC} ${GENHTML_FLAGS}

Moritz Lipp's avatar
Moritz Lipp committed
151 152 153
run-gcov: ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}
	$(QUIET)./${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
154
# clean
Moritz Lipp's avatar
Moritz Lipp committed
155 156

clean:
Moritz Lipp's avatar
Moritz Lipp committed
157 158
	$(QUIET)rm -rf \
		${BUILDDIR} \
Moritz Lipp's avatar
Moritz Lipp committed
159
		${DEPENDDIR} \
Moritz Lipp's avatar
Moritz Lipp committed
160 161
		${TARFILE} \
		${TARDIR} \
162
		${PROJECT}.pc \
163 164
		${PROJECT}/version.h \
		${PROJECT}/version.h.tmp \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
165 166
		${PROJECT}/resources.c \
		${PROJECT}/resources.h \
Moritz Lipp's avatar
Moritz Lipp committed
167 168
		$(PROJECT).info \
		gcov \
169
		.version-checks
170 171
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
Moritz Lipp's avatar
Moritz Lipp committed
172
	$(QUIET)$(MAKE) -C doc clean
173

174
${PROJECT}.pc: ${PROJECT}.pc.in config.mk
175 176
	$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
	$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
177
	$(QUIET)echo apiversion=${ZATHURA_API_VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
178
	$(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc
179
	$(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc
180
	$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
181
	$(QUIET)echo GTK_VERSION=3 >> ${PROJECT}.pc
182
	$(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc
183

184
valgrind: debug
185
	 $(QUIET)G_SLICE=always-malloc G_DEBUG=gc-friendly ${VALGRIND} ${VALGRIND_ARGUMENTS} \
Moritz Lipp's avatar
Moritz Lipp committed
186
		 ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}
187 188

gdb: debug
Moritz Lipp's avatar
Moritz Lipp committed
189
	$(QUIET)cgdb ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}
190

191
test: ${OBJECTS}
192
	$(QUIET)$(MAKE) -C tests run
193

194
dist: clean build-manpages
195 196 197 198
	$(QUIET)tar -czf $(TARFILE) --exclude=.gitignore \
		--transform 's,^,zathura-$(VERSION)/,' \
		`git ls-files` \
		doc/_build/$(PROJECT).1 doc/_build/$(PROJECT)rc.5
Moritz Lipp's avatar
Moritz Lipp committed
199

Sebastian Ramacher's avatar
Sebastian Ramacher committed
200
doc:
201
	$(QUIET)$(MAKE) -C doc
202

203 204 205
po:
	$(QUIET)${MAKE} -C po

206 207 208
update-po:
	$(QUIET)${MAKE} -C po update-po

209
build-manpages:
210
	$(QUIET)${MAKE} -C doc man
211 212

install-manpages: build-manpages
Moritz Lipp's avatar
Moritz Lipp committed
213
	$(call colorecho,INSTALL,"man pages")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
214
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
215 216
ifneq "$(wildcard doc/_build/${PROJECT}.1)" ""
	$(QUIET)install -m 644 doc/_build/${PROJECT}.1 ${DESTDIR}${MANPREFIX}/man1
217
endif
218 219
ifneq "$(wildcard doc/_build/${PROJECT}rc.5)" ""
	$(QUIET)install -m 644 doc/_build/${PROJECT}rc.5 ${DESTDIR}${MANPREFIX}/man5
220
endif
221

222
install-headers: ${PROJECT}.pc
Moritz Lipp's avatar
Moritz Lipp committed
223
	$(call colorecho,INSTALL,"header files")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
224
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
225
	$(QUIET)install -m 644 ${HEADERINST} ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
226 227

	$(call colorecho,INSTALL,"pkgconfig file")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
228
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}/pkgconfig
229 230
	$(QUIET)install -m 644 ${PROJECT}.pc ${DESTDIR}${LIBDIR}/pkgconfig

231
install-dbus:
Moritz Lipp's avatar
Moritz Lipp committed
232
	$(call colorecho,INSTALL,"D-Bus interface definitions")
233
	$(QUIET)mkdir -m 755 -p $(DESTDIR)$(DBUSINTERFACEDIR)
234
	$(QUIET)install -m 644 data/org.pwmt.zathura.xml $(DESTDIR)$(DBUSINTERFACEDIR)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
235

Sebastian Ramacher's avatar
Sebastian Ramacher committed
236 237 238 239 240 241
install-appdata:
	$(call colorecho,INSTALL,"AppData file")
	$(QUIET)mkdir -m 755 -p $(DESTDIR)$(APPDATAPREFIX)
	$(QUIET)install -m 644 data/$(PROJECT).appdata.xml $(DESTDIR)$(APPDATAPREFIX)

install: all install-headers install-manpages install-dbus install-appdata
Moritz Lipp's avatar
Moritz Lipp committed
242
	$(call colorecho,INSTALL,"executeable file")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
243
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin
Moritz Lipp's avatar
Moritz Lipp committed
244
	$(QUIET)install -m 755 ${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT} ${DESTDIR}${PREFIX}/bin
Sebastian Ramacher's avatar
Sebastian Ramacher committed
245
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX}
Moritz Lipp's avatar
Moritz Lipp committed
246
	$(call colorecho,INSTALL,"desktop file")
247
	$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
248
	$(MAKE) -C po install
Moritz Lipp's avatar
Moritz Lipp committed
249

250
uninstall-headers:
Moritz Lipp's avatar
Moritz Lipp committed
251
	$(call colorecho,UNINSTALL,"header files")
252
	$(QUIET)rm -rf ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
253
	$(call colorecho,UNINSTALL,"pkgconfig file")
254 255
	$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc

256
uninstall: uninstall-headers
257
	$(ECHO) removing executable file
Moritz Lipp's avatar
Moritz Lipp committed
258
	$(call colorecho,UNINSTALL,"executeable")
259
	$(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
260
	$(call colorecho,UNINSTALL,"man pages")
261
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
262
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
Moritz Lipp's avatar
Moritz Lipp committed
263
	$(call colorecho,UNINSTALL,"desktop file")
264
	$(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
Moritz Lipp's avatar
Moritz Lipp committed
265
	$(call colorecho,UNINSTALL,"D-Bus interface definitions")
266
	$(QUIET)rm -f $(DESTDIR)$(DBUSINTERFACEDIR)/org.pwmt.zathura.xml
Sebastian Ramacher's avatar
Sebastian Ramacher committed
267 268
	$(call colorecho,UNINSTALL,"AppData file")
	$(QUIET)rm -f $(DESTDIR)$(APPDATAPREFIX)/$(PROJECT).appdata.xml
269
	$(MAKE) -C po uninstall
Sebastian Ramacher's avatar
Sebastian Ramacher committed
270

271 272
DEPENDS = ${DEPENDDIRS:^=${DEPENDDIR}/}$(addprefix ${DEPENDDIR}/,${OBJECTS:.o=.o.dep})
-include ${DEPENDS}
273

274 275 276
.PHONY: all options clean doc debug valgrind gdb dist doc install uninstall \
	test po install-headers uninstall-headers update-po install-manpages \
	build-manpages install-dbus