Makefile 9.74 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
Sebastian Ramacher's avatar
Sebastian Ramacher committed
5
include common.mk
Moritz Lipp's avatar
Moritz Lipp committed
6

Sebastian Ramacher's avatar
Sebastian Ramacher committed
7
OSOURCE    = $(filter-out ${PROJECT}/css-definitions.c, $(filter-out ${PROJECT}/dbus-interface-definitions.c, $(sort $(wildcard ${PROJECT}/*.c))))
8

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

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

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

Moritz Lipp's avatar
Moritz Lipp committed
30
31
32
33
ifneq ($(wildcard ${VALGRIND_SUPPRESSION_FILE}),)
VALGRIND_ARGUMENTS += --suppressions=${VALGRIND_SUPPRESSION_FILE}
endif

34
35
36
37
38
39
40
41
42
43
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

Moritz Lipp's avatar
Moritz Lipp committed
44
45
46
47
48
49
50
51
52
53
OBJECTS       = $(addprefix ${BUILDDIR_RELEASE}/,${SOURCE:.c=.o}) \
	${BUILDDIR_RELEASE}/${PROJECT}/css-definitions.o \
	${BUILDDIR_RELEASE}/${PROJECT}/dbus-interface-definitions.o
OBJECTS_DEBUG = $(addprefix ${BUILDDIR_DEBUG}/,${SOURCE:.c=.o}) \
	${BUILDDIR_DEBUG}/${PROJECT}/css-definitions.o \
	${BUILDDIR_DEBUG}/${PROJECT}/dbus-interface-definitions.o
OBJECTS_GCOV  = $(addprefix ${BUILDDIR_GCOV}/,${SOURCE:.c=.o}) \
	${BUILDDIR_GCOV}/${PROJECT}/css-definitions.o \
	${BUILDDIR_GCOV}/${PROJECT}/dbus-interface-definitions.o
HEADER        = $(wildcard ${PROJECT}/*.h) $(wildcard synctex/*.h)
Moritz Lipp's avatar
Moritz Lipp committed
54
HEADERINST    = $(addprefix ${PROJECT}/,version.h document.h macros.h page.h types.h plugin-api.h links.h)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
55

56
all: options ${PROJECT} po build-manpages
57

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

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

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

Moritz Lipp's avatar
Moritz Lipp committed
83
${PROJECT}/dbus-interface-definitions.c: data/org.pwmt.zathura.xml
84
85
86
87
	$(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
88
	$(QUIET)mv $@.tmp $@
89

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

Moritz Lipp's avatar
Moritz Lipp committed
97
98
99
100
101
102
# release build

${OBJECTS}: config.mk ${PROJECT}/version.h \
	.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK

${BUILDDIR_RELEASE}/%.o: %.c
Moritz Lipp's avatar
Moritz Lipp committed
103
	$(call colorecho,CC,$<)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
104
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
105
	@mkdir -p $(dir $(abspath $@))
Sebastian Ramacher's avatar
Sebastian Ramacher committed
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
124
125
126
# debug build

${OBJECTS_DEBUG}: config.mk ${PROJECT}/version.h \
	.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK

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

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

139
debug: ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
140

Moritz Lipp's avatar
Moritz Lipp committed
141
142
143
run-debug: debug
	$(QUIET)./${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
144
# gcov build
145

Moritz Lipp's avatar
Moritz Lipp committed
146
${OBJECTS_GCOV}: config.mk ${PROJECT}/version.h \
147
	.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK
148

Moritz Lipp's avatar
Moritz Lipp committed
149
150
${BUILDDIR_GCOV}/%.o: %.c
	$(call colorecho,CC,$<)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
151
	@mkdir -p ${DEPENDDIR}/$(dir $@)
Moritz Lipp's avatar
Moritz Lipp committed
152
153
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${GCOV_CFLAGS} \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
154
		-o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
Moritz Lipp's avatar
Moritz Lipp committed
155

156
${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}: ${OBJECTS_GCOV}
Moritz Lipp's avatar
Moritz Lipp committed
157
	$(call colorecho,CC,$@)
Moritz Lipp's avatar
Moritz Lipp committed
158
	@mkdir -p ${BUILDDIR_GCOV}/${BINDIR}
Moritz Lipp's avatar
Moritz Lipp committed
159
160
	$(QUIET)${CC} ${LDFLAGS} ${GCOV_CFLAGS} ${GCOV_LDFLAGS} \
		-o ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT} ${OBJECTS_GCOv} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
161

162
gcov: options ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
163
164
165
166
167
168
	$(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
169
170
171
run-gcov: ${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}
	$(QUIET)./${BUILDDIR_GCOV}/${BINDIR}/${PROJECT}

Moritz Lipp's avatar
Moritz Lipp committed
172
# clean
Moritz Lipp's avatar
Moritz Lipp committed
173
174

clean:
Moritz Lipp's avatar
Moritz Lipp committed
175
176
	$(QUIET)rm -rf \
		${BUILDDIR} \
Moritz Lipp's avatar
Moritz Lipp committed
177
		${DEPENDDIR} \
Moritz Lipp's avatar
Moritz Lipp committed
178
179
		${TARFILE} \
		${TARDIR} \
180
		${PROJECT}.pc \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
181
182
		${PROJECT}/version.h \
		${PROJECT}/version.h.tmp \
Moritz Lipp's avatar
Moritz Lipp committed
183
184
185
186
187
188
		${PROJECT}/dbus-interface-definitions.c \
		${PROJECT}/dbus-interface-definitions.c.tmp \
		${PROJECT}/css-definitions.c \
		${PROJECT}/css-definitions.c.tmp \
		$(PROJECT).info \
		gcov \
189
		.version-checks
190
191
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
Moritz Lipp's avatar
Moritz Lipp committed
192
	$(QUIET)$(MAKE) -C doc clean
193

194
${PROJECT}.pc: ${PROJECT}.pc.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
195
196
	$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
	$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
197
	$(QUIET)echo apiversion=${ZATHURA_API_VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
198
	$(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc
199
	$(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc
200
	$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
201
	$(QUIET)echo GTK_VERSION=3 >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
202
	$(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc
203

Moritz Lipp's avatar
Moritz Lipp committed
204
valgrind: debug
Moritz Lipp's avatar
Moritz Lipp committed
205
	 $(QUIET)G_SLICE=always-malloc G_DEBUG=gc-friendly ${VALGRIND} ${VALGRIND_ARGUMENTS} \
Moritz Lipp's avatar
Moritz Lipp committed
206
		 ${BUILDDIR_DEBUG}/${BINDIR}/${PROJECT}
207
208

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

211
test: ${OBJECTS}
212
	$(QUIET)$(MAKE) -C tests run
Moritz Lipp's avatar
Moritz Lipp committed
213

214
dist: clean build-manpages
215
216
217
218
	$(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
219

Sebastian Ramacher's avatar
Sebastian Ramacher committed
220
doc:
221
	$(QUIET)$(MAKE) -C doc
Moritz Lipp's avatar
Moritz Lipp committed
222

223
224
225
po:
	$(QUIET)${MAKE} -C po

226
227
228
update-po:
	$(QUIET)${MAKE} -C po update-po

229
build-manpages:
230
	$(QUIET)${MAKE} -C doc man
231
232

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

242
install-headers: ${PROJECT}.pc
Moritz Lipp's avatar
Moritz Lipp committed
243
	$(call colorecho,INSTALL,"header files")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
244
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
245
	$(QUIET)install -m 644 ${HEADERINST} ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
246
247

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

251
install-dbus:
Moritz Lipp's avatar
Moritz Lipp committed
252
	$(call colorecho,INSTALL,"D-Bus interface definitions")
253
	$(QUIET)mkdir -m 755 -p $(DESTDIR)$(DBUSINTERFACEDIR)
254
	$(QUIET)install -m 644 data/org.pwmt.zathura.xml $(DESTDIR)$(DBUSINTERFACEDIR)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
255

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

270
uninstall-headers:
Moritz Lipp's avatar
Moritz Lipp committed
271
	$(call colorecho,UNINSTALL,"header files")
272
	$(QUIET)rm -rf ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
273
	$(call colorecho,UNINSTALL,"pkgconfig file")
274
275
	$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc

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

Sebastian Ramacher's avatar
Sebastian Ramacher committed
291
292
DEPENDS = ${DEPENDDIRS:^=${DEPENDDIR}/}$(addprefix ${DEPENDDIR}/,${OBJECTS:.o=.o.dep})
-include ${DEPENDS}
293

294
295
296
.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