Makefile 9.19 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 8 9 10
# source files
OSOURCE    = $(sort $(wildcard ${PROJECT}/*.c) \
						 ${PROJECT}/css-definitions.c \
						 ${PROJECT}/dbus-interface-definitions.c)
11

12
ifneq (${WITH_SQLITE},0)
13 14 15
INCS     += $(SQLITE_INC)
LIBS     += $(SQLITE_LIB)
SOURCE    = $(OSOURCE)
16
CPPFLAGS += -DWITH_SQLITE
17
else
18
SOURCE    = $(filter-out ${PROJECT}/database-sqlite.c,$(OSOURCE))
19 20
endif

21
ifneq ($(WITH_MAGIC),0)
22 23
INCS     += $(MAGIC_INC)
LIBS     += $(MAGIC_LIB)
24 25 26
CPPFLAGS += -DWITH_MAGIC
endif

27 28 29 30
ifneq ($(WITH_SYNCTEX),0)
INCS     += $(SYNCTEX_INC)
LIBS     += $(SYNCTEX_LIB)
CPPFLAGS += -DWITH_SYNCTEX
31 32
endif

33 34 35 36
ifneq ($(wildcard ${VALGRIND_SUPPRESSION_FILE}),)
VALGRIND_ARGUMENTS += --suppressions=${VALGRIND_SUPPRESSION_FILE}
endif

37 38 39 40 41 42 43 44 45 46
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

47 48 49
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
50
HEADERINST    = $(addprefix ${PROJECT}/,version.h document.h macros.h page.h types.h plugin-api.h links.h)
51

52
all: options ${PROJECT} po build-manpages
53

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

64
options:
Moritz Lipp's avatar
Moritz Lipp committed
65
	@echo ${PROJECT} build options:
66
	@echo "CFLAGS  = ${CFLAGS}"
Moritz Lipp's avatar
Moritz Lipp committed
67
	@echo "LIBS    = ${LIBS}"
68 69 70
	@echo "DFLAGS  = ${DFLAGS}"
	@echo "CC      = ${CC}"

71 72
# generated files

Moritz Lipp's avatar
Moritz Lipp committed
73
${PROJECT}/version.h: ${PROJECT}/version.h.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
74 75 76 77
	$(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}/' \
78 79
		-e 's/ZVABI/${ZATHURA_ABI_VERSION}/' ${PROJECT}/version.h.in > ${PROJECT}/version.h.tmp
	$(QUIET)mv ${PROJECT}/version.h.tmp ${PROJECT}/version.h
80

Moritz Lipp's avatar
Moritz Lipp committed
81
${PROJECT}/dbus-interface-definitions.c: data/org.pwmt.zathura.xml
82 83 84 85
	$(QUIET)echo '#include "dbus-interface-definitions.h"' > $@.tmp
	$(QUIET)echo 'const char* DBUS_INTERFACE_XML =' >> $@.tmp
	$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' data/org.pwmt.zathura.xml >> $@.tmp
	$(QUIET)echo ';' >> $@.tmp
Sebastian Ramacher's avatar
Sebastian Ramacher committed
86
	$(QUIET)mv $@.tmp $@
87

Moritz Lipp's avatar
Moritz Lipp committed
88
${PROJECT}/css-definitions.c: data/zathura.css_t
89
	$(QUIET)echo '#include "css-definitions.h"' > $@.tmp
90
	$(QUIET)echo 'const char* CSS_TEMPLATE_INDEX =' >> $@.tmp
91 92 93
	$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' $< >> $@.tmp
	$(QUIET)echo ';' >> $@.tmp
	$(QUIET)mv $@.tmp $@
94

95
# common dependencies
Moritz Lipp's avatar
Moritz Lipp committed
96

97
${OBJECTS} ${OBJECTS_DEBUG} ${OBJECTS_GCOV}: config.mk ${PROJECT}/version.h \
Moritz Lipp's avatar
Moritz Lipp committed
98 99
	.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK

100 101
# rlease build

Moritz Lipp's avatar
Moritz Lipp committed
102
${BUILDDIR_RELEASE}/%.o: %.c
Moritz Lipp's avatar
Moritz Lipp committed
103
	$(call colorecho,CC,$<)
104
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
105
	@mkdir -p $(dir $(abspath $@))
106
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
Moritz Lipp's avatar
Moritz Lipp committed
107

108
${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT}: ${OBJECTS}
Moritz Lipp's avatar
Moritz Lipp committed
109 110 111 112
	$(call colorecho,CC,$@)
	@mkdir -p ${BUILDDIR_RELEASE}/${BINDIR}
	$(QUIET)${CC} ${SFLAGS} ${LDFLAGS} \
		-o ${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT} ${OBJECTS} ${LIBS}
113

114 115 116 117
${PROJECT}: ${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT}

release: ${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
118 119 120
run: release
	$(QUIET)./${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
121 122 123
# debug build

${BUILDDIR_DEBUG}/%.o: %.c
Moritz Lipp's avatar
Moritz Lipp committed
124
	$(call colorecho,CC,$<)
125
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
126 127
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} \
128
		-o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
Moritz Lipp's avatar
Moritz Lipp committed
129

130
${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}: ${OBJECTS_DEBUG}
Moritz Lipp's avatar
Moritz Lipp committed
131 132
	$(call colorecho,CC,$@)
	@mkdir -p ${BUILDDIR_DEBUG}/${BINDIR}
133 134
	$(QUIET)${CC} ${LDFLAGS} \
		-o ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT} ${OBJECTS_DEBUG} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
135

136
debug: ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
137

Moritz Lipp's avatar
Moritz Lipp committed
138 139 140
run-debug: debug
	$(QUIET)./${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
141
# gcov build
142

Moritz Lipp's avatar
Moritz Lipp committed
143 144
${BUILDDIR_GCOV}/%.o: %.c
	$(call colorecho,CC,$<)
145
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
146 147
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${GCOV_CFLAGS} \
148
		-o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
Moritz Lipp's avatar
Moritz Lipp committed
149

150
${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}: ${OBJECTS_GCOV}
Moritz Lipp's avatar
Moritz Lipp committed
151
	$(call colorecho,CC,$@)
Moritz Lipp's avatar
Moritz Lipp committed
152
	@mkdir -p ${BUILDDIR_GCOV}/${BINDIR}
153
	$(QUIET)${CC} ${LDFLAGS} ${GCOV_CFLAGS} ${GCOV_LDFLAGS} \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
154
		-o ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT} ${OBJECTS_GCOV} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
155

156
gcov: options ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
157 158 159 160 161 162
	$(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
163 164 165
run-gcov: ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}
	$(QUIET)./${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
166
# clean
Moritz Lipp's avatar
Moritz Lipp committed
167 168

clean:
Moritz Lipp's avatar
Moritz Lipp committed
169 170
	$(QUIET)rm -rf \
		${BUILDDIR} \
Moritz Lipp's avatar
Moritz Lipp committed
171
		${DEPENDDIR} \
Moritz Lipp's avatar
Moritz Lipp committed
172 173
		${TARFILE} \
		${TARDIR} \
174
		${PROJECT}.pc \
175 176
		${PROJECT}/version.h \
		${PROJECT}/version.h.tmp \
Moritz Lipp's avatar
Moritz Lipp committed
177 178 179 180 181 182
		${PROJECT}/dbus-interface-definitions.c \
		${PROJECT}/dbus-interface-definitions.c.tmp \
		${PROJECT}/css-definitions.c \
		${PROJECT}/css-definitions.c.tmp \
		$(PROJECT).info \
		gcov \
183
		.version-checks
184 185
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
Moritz Lipp's avatar
Moritz Lipp committed
186
	$(QUIET)$(MAKE) -C doc clean
187

188
${PROJECT}.pc: ${PROJECT}.pc.in config.mk
189 190
	$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
	$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
191
	$(QUIET)echo apiversion=${ZATHURA_API_VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
192
	$(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc
193
	$(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc
194
	$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
195
	$(QUIET)echo GTK_VERSION=3 >> ${PROJECT}.pc
196
	$(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc
197

198
valgrind: debug
199
	 $(QUIET)G_SLICE=always-malloc G_DEBUG=gc-friendly ${VALGRIND} ${VALGRIND_ARGUMENTS} \
Moritz Lipp's avatar
Moritz Lipp committed
200
		 ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}
201 202

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

205
test: ${OBJECTS}
206
	$(QUIET)$(MAKE) -C tests run
207

208
dist: clean build-manpages
209 210 211 212
	$(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
213

Sebastian Ramacher's avatar
Sebastian Ramacher committed
214
doc:
215
	$(QUIET)$(MAKE) -C doc
216

217 218 219
po:
	$(QUIET)${MAKE} -C po

220 221 222
update-po:
	$(QUIET)${MAKE} -C po update-po

223
build-manpages:
224
	$(QUIET)${MAKE} -C doc man
225 226

install-manpages: build-manpages
Moritz Lipp's avatar
Moritz Lipp committed
227
	$(call colorecho,INSTALL,"man pages")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
228
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
229 230
ifneq "$(wildcard doc/_build/${PROJECT}.1)" ""
	$(QUIET)install -m 644 doc/_build/${PROJECT}.1 ${DESTDIR}${MANPREFIX}/man1
231
endif
232 233
ifneq "$(wildcard doc/_build/${PROJECT}rc.5)" ""
	$(QUIET)install -m 644 doc/_build/${PROJECT}rc.5 ${DESTDIR}${MANPREFIX}/man5
234
endif
235

236
install-headers: ${PROJECT}.pc
Moritz Lipp's avatar
Moritz Lipp committed
237
	$(call colorecho,INSTALL,"header files")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
238
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
239
	$(QUIET)install -m 644 ${HEADERINST} ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
240 241

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

245
install-dbus:
Moritz Lipp's avatar
Moritz Lipp committed
246
	$(call colorecho,INSTALL,"D-Bus interface definitions")
247
	$(QUIET)mkdir -m 755 -p $(DESTDIR)$(DBUSINTERFACEDIR)
248
	$(QUIET)install -m 644 data/org.pwmt.zathura.xml $(DESTDIR)$(DBUSINTERFACEDIR)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
249

Sebastian Ramacher's avatar
Sebastian Ramacher committed
250 251 252 253 254 255
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
256
	$(call colorecho,INSTALL,"executeable file")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
257
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin
Moritz Lipp's avatar
Moritz Lipp committed
258
	$(QUIET)install -m 755 ${BUILDDIR_RELEASE}/${BINDIR}/${PROJECT} ${DESTDIR}${PREFIX}/bin
Sebastian Ramacher's avatar
Sebastian Ramacher committed
259
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX}
Moritz Lipp's avatar
Moritz Lipp committed
260
	$(call colorecho,INSTALL,"desktop file")
261
	$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
262
	$(MAKE) -C po install
Moritz Lipp's avatar
Moritz Lipp committed
263

264
uninstall-headers:
Moritz Lipp's avatar
Moritz Lipp committed
265
	$(call colorecho,UNINSTALL,"header files")
266
	$(QUIET)rm -rf ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
267
	$(call colorecho,UNINSTALL,"pkgconfig file")
268 269
	$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc

270
uninstall: uninstall-headers
271
	$(ECHO) removing executable file
Moritz Lipp's avatar
Moritz Lipp committed
272
	$(call colorecho,UNINSTALL,"executeable")
273
	$(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
274
	$(call colorecho,UNINSTALL,"man pages")
275
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
276
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
Moritz Lipp's avatar
Moritz Lipp committed
277
	$(call colorecho,UNINSTALL,"desktop file")
278
	$(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
Moritz Lipp's avatar
Moritz Lipp committed
279
	$(call colorecho,UNINSTALL,"D-Bus interface definitions")
280
	$(QUIET)rm -f $(DESTDIR)$(DBUSINTERFACEDIR)/org.pwmt.zathura.xml
Sebastian Ramacher's avatar
Sebastian Ramacher committed
281 282
	$(call colorecho,UNINSTALL,"AppData file")
	$(QUIET)rm -f $(DESTDIR)$(APPDATAPREFIX)/$(PROJECT).appdata.xml
283
	$(MAKE) -C po uninstall
Sebastian Ramacher's avatar
Sebastian Ramacher committed
284

285 286
DEPENDS = ${DEPENDDIRS:^=${DEPENDDIR}/}$(addprefix ${DEPENDDIR}/,${OBJECTS:.o=.o.dep})
-include ${DEPENDS}
287

288 289 290
.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