Makefile 9 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 9 10
OSOURCE       = $(sort $(wildcard ${PROJECT}/*.c) \
                ${PROJECT}/css-definitions.c)
SOURCE_FILTER =
11

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

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

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

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

36 37 38 39 40 41 42 43 44
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
45 46
ifeq (,$(findstring -DDBUSINTERFACEDIR,${CPPFLAGS}))
ifneq ($(WITH_LOCAL_DBUS_XML),0)
47
CPPFLAGS += -DDBUSINTERFACEDIR=\"$(abspath data)\"
48 49 50 51
else
CPPFLAGS += -DDBUSINTERFACEDIR=\"${DBUSINTERFACEDIR}\"
endif
endif
52

53
SOURCE        = $(filter-out $(SOURCE_FILTER),$(OSOURCE))
54 55 56
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
57
HEADERINST    = $(addprefix ${PROJECT}/,version.h document.h macros.h page.h types.h plugin-api.h links.h)
58

59
all: options ${PROJECT} po build-manpages
60

61
# pkg-config based version checks
62
.version-checks/%: config.mk
63
	$(QUIET)test $($(*)_VERSION_CHECK) -eq 0 || \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
64
		${PKG_CONFIG} --atleast-version $($(*)_MIN_VERSION) $($(*)_PKG_CONFIG_NAME) || ( \
NGKS's avatar
NGKS committed
65
		echo "The minimum required version of $(*) is $($(*)_MIN_VERSION)" && \
66 67 68 69
		false \
	)
	@mkdir -p .version-checks
	$(QUIET)touch $@
70

71
options:
Moritz Lipp's avatar
Moritz Lipp committed
72
	@echo ${PROJECT} build options:
73
	@echo "CFLAGS  = ${CFLAGS}"
Moritz Lipp's avatar
Moritz Lipp committed
74
	@echo "LIBS    = ${LIBS}"
75 76 77
	@echo "DFLAGS  = ${DFLAGS}"
	@echo "CC      = ${CC}"

78 79
# generated files

Moritz Lipp's avatar
Moritz Lipp committed
80
${PROJECT}/version.h: ${PROJECT}/version.h.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
81 82 83 84
	$(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}/' \
85 86
		-e 's/ZVABI/${ZATHURA_ABI_VERSION}/' ${PROJECT}/version.h.in > ${PROJECT}/version.h.tmp
	$(QUIET)mv ${PROJECT}/version.h.tmp ${PROJECT}/version.h
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
		${PROJECT}/css-definitions.c \
		${PROJECT}/css-definitions.c.tmp \
		$(PROJECT).info \
		gcov \
181
		.version-checks
182 183
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
Moritz Lipp's avatar
Moritz Lipp committed
184
	$(QUIET)$(MAKE) -C doc clean
185

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

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

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

203
test: ${OBJECTS}
204
	$(QUIET)$(MAKE) -C tests run
205

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

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

215 216 217
po:
	$(QUIET)${MAKE} -C po

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

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

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

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

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

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

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

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

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

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

286 287 288
.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