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

3
include config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
4
include common.mk
Moritz Lipp's avatar
Moritz Lipp committed
5

Sebastian Ramacher's avatar
Sebastian Ramacher committed
6
PROJECT    = zathura
7
OSOURCE    = $(filter-out dbus-interface-definitions.c, $(wildcard *.c))
Sebastian Ramacher's avatar
Sebastian Ramacher committed
8
HEADER     = $(wildcard *.h)
Moritz Lipp's avatar
Moritz Lipp committed
9
HEADERINST = version.h document.h macros.h page.h types.h plugin-api.h links.h
10

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

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

Moritz Lipp's avatar
Moritz Lipp committed
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
41
OBJECTS  = $(patsubst %.c, %.o,  $(SOURCE)) dbus-interface-definitions.o
DOBJECTS = $(patsubst %.o, %.do, $(OBJECTS))
Sebastian Ramacher's avatar
Sebastian Ramacher committed
42

43
all: options ${PROJECT} po build-manpages
44

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

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

62
version.h: version.h.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
63
64
65
66
	$(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}/' \
67
68
69
70
		-e 's/ZVABI/${ZATHURA_ABI_VERSION}/' version.h.in > version.h.tmp
	$(QUIET)mv version.h.tmp version.h

dbus-interface-definitions.c: data/org.pwmt.zathura.xml
71
72
	$(QUIET)echo '#include "dbus-interface-definitions.h"' > dbus-interface-definitions.c.tmp
	$(QUIET)echo 'const char* DBUS_INTERFACE_XML =' >> dbus-interface-definitions.c.tmp
73
	$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' data/org.pwmt.zathura.xml >> dbus-interface-definitions.c.tmp
74
	$(QUIET)echo ';' >> dbus-interface-definitions.c.tmp
75
	$(QUIET)mv dbus-interface-definitions.c.tmp dbus-interface-definitions.c
76

77
%.o: %.c
Sebastian Ramacher's avatar
Sebastian Ramacher committed
78
	$(ECHO) CC $<
Sebastian Ramacher's avatar
Sebastian Ramacher committed
79
	@mkdir -p .depend
Sebastian Ramacher's avatar
Sebastian Ramacher committed
80
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
81
82

%.do: %.c
Sebastian Ramacher's avatar
Sebastian Ramacher committed
83
	$(ECHO) CC $<
Sebastian Ramacher's avatar
Sebastian Ramacher committed
84
	@mkdir -p .depend
Sebastian Ramacher's avatar
Sebastian Ramacher committed
85
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
86

87
88
${OBJECTS} ${DOBJECTS}: config.mk version.h \
	.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK
89
90

${PROJECT}: ${OBJECTS}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
91
92
	$(ECHO) CC -o $@
	$(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
93
94

clean:
95
96
97
98
99
100
101
102
103
104
105
	$(QUIET)rm -rf ${PROJECT} \
		${OBJECTS} \
		${PROJECT}-${VERSION}.tar.gz \
		${DOBJECTS} \
		${PROJECT}-debug \
		.depend \
		${PROJECT}.pc \
		version.h \
		version.h.tmp \
		dbus-interface-definitions.c \
		dbus-interface-definitions.c.tmp \
106
		*gcda *gcno $(PROJECT).info gcov *.tmp \
107
		.version-checks
108
109
110
ifneq "$(wildcard ${RSTTOMAN})" ""
	$(QUIET)rm -f zathura.1 zathurarc.5
endif
111
112
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
Moritz Lipp's avatar
Moritz Lipp committed
113
	$(QUIET)$(MAKE) -C doc clean
114
115

${PROJECT}-debug: ${DOBJECTS}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
116
117
	$(ECHO) CC -o $@
	$(QUIET)${CC} ${LDFLAGS} -o $@ ${DOBJECTS} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
118

119
debug: ${PROJECT}-debug
Moritz Lipp's avatar
Moritz Lipp committed
120

121
${PROJECT}.pc: ${PROJECT}.pc.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
122
123
	$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
	$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
124
	$(QUIET)echo apiversion=${ZATHURA_API_VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
125
	$(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc
126
	$(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc
127
	$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
128
	$(QUIET)echo GTK_VERSION=3 >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
129
	$(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc
130

Moritz Lipp's avatar
Moritz Lipp committed
131
valgrind: debug
Moritz Lipp's avatar
Moritz Lipp committed
132
133
	 $(QUIET)G_SLICE=always-malloc G_DEBUG=gc-friendly ${VALGRIND} ${VALGRIND_ARGUMENTS} \
		 ./${PROJECT}-debug
134
135

gdb: debug
Moritz Lipp's avatar
Moritz Lipp committed
136
	$(QUIET)cgdb ${PROJECT}-debug
137

138
test: ${OBJECTS}
139
	$(QUIET)make -C tests run
Moritz Lipp's avatar
Moritz Lipp committed
140

141
dist: clean build-manpages
Sebastian Ramacher's avatar
Sebastian Ramacher committed
142
	$(QUIET)mkdir -p ${PROJECT}-${VERSION}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
143
	$(QUIET)mkdir -p ${PROJECT}-${VERSION}/tests
144
	$(QUIET)mkdir -p ${PROJECT}-${VERSION}/po
Sebastian Ramacher's avatar
Sebastian Ramacher committed
145
	$(QUIET)cp LICENSE Makefile config.mk common.mk README AUTHORS Doxyfile \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
146
			${PROJECT}.1.rst ${PROJECT}rc.5.rst ${OSOURCE} ${HEADER} ${PROJECT}.pc.in \
147
			${PROJECT}.desktop version.h.in \
148
			${PROJECT}.1 ${PROJECT}rc.5 \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
149
			${PROJECT}-${VERSION}
150
	$(QUIET)cp -r data ${PROJECT}-${VERSION}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
151
	$(QUIET)cp tests/Makefile tests/config.mk tests/*.c \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
152
			${PROJECT}-${VERSION}/tests
153
	$(QUIET)cp po/Makefile po/*.po ${PROJECT}-${VERSION}/po
Sebastian Ramacher's avatar
Sebastian Ramacher committed
154
155
156
	$(QUIET)tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION}
	$(QUIET)gzip ${PROJECT}-${VERSION}.tar
	$(QUIET)rm -rf ${PROJECT}-${VERSION}
Moritz Lipp's avatar
Moritz Lipp committed
157

Sebastian Ramacher's avatar
Sebastian Ramacher committed
158
doc:
Moritz Lipp's avatar
Moritz Lipp committed
159
	$(QUIET)make -C doc
Moritz Lipp's avatar
Moritz Lipp committed
160

161
gcov: clean
162
163
	$(QUIET)CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage" LDFLAGS="${LDFLAGS} -fprofile-arcs" ${MAKE} $(PROJECT)
	$(QUIET)CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage" LDFLAGS="${LDFLAGS} -fprofile-arcs" ${MAKE} -C tests run
164
165
166
	$(QUIET)lcov --directory . --capture --output-file $(PROJECT).info
	$(QUIET)genhtml --output-directory gcov $(PROJECT).info

167
168
169
po:
	$(QUIET)${MAKE} -C po

170
171
172
update-po:
	$(QUIET)${MAKE} -C po update-po

173
174
175
ifneq "$(wildcard ${RSTTOMAN})" ""
%.1 %.5: config.mk
	$(QUIET)sed "s/VERSION/${VERSION}/g" < $@.rst > $@.tmp
176
177
	$(QUIET)${RSTTOMAN} $@.tmp > $@.out.tmp
	$(QUIET)mv $@.out.tmp $@
178
179
180
181
182
183
	$(QUIET)rm $@.tmp

${PROJECT}.1: ${PROJECT}.1.rst
${PROJECT}rc.5: ${PROJECT}rc.5.rst

build-manpages: ${PROJECT}.1 ${PROJECT}rc.5
184
185
186
else
build-manpages:
endif
187
188
189

install-manpages: build-manpages
	$(ECHO) installing manual pages
Sebastian Ramacher's avatar
Sebastian Ramacher committed
190
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
191
ifneq "$(wildcard ${PROJECT}.1)" ""
192
	$(QUIET)install -m 644 ${PROJECT}.1 ${DESTDIR}${MANPREFIX}/man1
193
194
endif
ifneq "$(wildcard ${PROJECT}rc.5)" ""
195
	$(QUIET)install -m 644 ${PROJECT}rc.5 ${DESTDIR}${MANPREFIX}/man5
196
endif
197

198
199
install-headers: ${PROJECT}.pc
	$(ECHO) installing header files
Sebastian Ramacher's avatar
Sebastian Ramacher committed
200
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
201
	$(QUIET)install -m 644 ${HEADERINST} ${DESTDIR}${INCLUDEDIR}/${PROJECT}
202
	$(ECHO) installing pkgconfig file
Sebastian Ramacher's avatar
Sebastian Ramacher committed
203
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}/pkgconfig
204
205
	$(QUIET)install -m 644 ${PROJECT}.pc ${DESTDIR}${LIBDIR}/pkgconfig

206
207
208
install-dbus:
	$(ECHO) installing D-Bus interface definitions
	$(QUIET)mkdir -m 755 -p $(DESTDIR)$(DBUSINTERFACEDIR)
209
	$(QUIET)install -m 644 data/org.pwmt.zathura.xml $(DESTDIR)$(DBUSINTERFACEDIR)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
210

211
install: all install-headers install-manpages install-dbus
Sebastian Ramacher's avatar
Sebastian Ramacher committed
212
	$(ECHO) installing executable file
Sebastian Ramacher's avatar
Sebastian Ramacher committed
213
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin
Sebastian Ramacher's avatar
Sebastian Ramacher committed
214
	$(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin
Sebastian Ramacher's avatar
Sebastian Ramacher committed
215
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX}
216
217
	$(ECHO) installing desktop file
	$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
218
	$(MAKE) -C po install
Moritz Lipp's avatar
Moritz Lipp committed
219

220
221
222
223
224
225
uninstall-headers:
	$(ECHO) removing header files
	$(QUIET)rm -rf ${DESTDIR}${INCLUDEDIR}/${PROJECT}
	$(ECHO) removing pkgconfig file
	$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc

226
uninstall: uninstall-headers
Sebastian Ramacher's avatar
Sebastian Ramacher committed
227
228
	$(ECHO) removing executable file
	$(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
229
	$(ECHO) removing manual pages
Sebastian Ramacher's avatar
Sebastian Ramacher committed
230
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
231
232
233
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
	$(ECHO) removing desktop file
	$(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
234
235
	$(ECHO) removing D-Bus interface definitions
	$(QUIET)rm -f $(DESTDIR)$(DBUSINTERFACEDIR)/org.pwmt.zathura.xml
236
	$(MAKE) -C po uninstall
Sebastian Ramacher's avatar
Sebastian Ramacher committed
237

Sebastian Ramacher's avatar
Sebastian Ramacher committed
238
-include $(wildcard .depend/*.dep)
239

240
241
242
.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