Makefile 7.47 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

Sebastian Ramacher's avatar
Sebastian Ramacher committed
7 8
OSOURCE    = $(filter-out css-definitions.c, $(filter-out dbus-interface-definitions.c, $(wildcard *.c))) $(wildcard synctex/*.c)
HEADER     = $(wildcard *.h) $(wildcard synctex/*.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

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
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
Sebastian Ramacher's avatar
Sebastian Ramacher committed
39 40 41 42 43 44 45
ifeq (,$(findstring -Isynctex,${CPPFLAGS}))
CPPFLAGS += -Isynctex
endif
ifeq (,$(findstring -DSYNCTEX_VERBOSE=0,${CPPFLAGS}))
CPPFLAGS += -DSYNCTEX_VERBOSE=0
endif

46

47
OBJECTS  = $(patsubst %.c, %.o,  $(SOURCE)) dbus-interface-definitions.o css-definitions.o
48
DOBJECTS = $(patsubst %.o, %.do, $(OBJECTS))
49

50
all: options ${PROJECT} po build-manpages
51

52
# pkg-config based version checks
53
.version-checks/%: config.mk
54 55 56 57 58 59 60
	$(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 $@
61

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

69
version.h: version.h.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
70 71 72 73
	$(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}/' \
74 75 76 77
		-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
78 79 80 81
	$(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
82
	$(QUIET)mv $@.tmp $@
83 84 85

css-definitions.c: data/zathura.css_t
	$(QUIET)echo '#include "css-definitions.h"' > $@.tmp
86
	$(QUIET)echo 'const char* CSS_TEMPLATE_INDEX =' >> $@.tmp
87 88 89
	$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' $< >> $@.tmp
	$(QUIET)echo ';' >> $@.tmp
	$(QUIET)mv $@.tmp $@
90

91
%.o: %.c
Moritz Lipp's avatar
Moritz Lipp committed
92
	$(call colorecho,CC,$<)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
93
	$(QUIET) mkdir -p $(shell dirname .depend/$@.dep)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
94
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
95 96

%.do: %.c
Moritz Lipp's avatar
Moritz Lipp committed
97
	$(call colorecho,CC,$<)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
98
	@mkdir -p .depend
Sebastian Ramacher's avatar
Sebastian Ramacher committed
99
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
100

101 102
${OBJECTS} ${DOBJECTS}: config.mk version.h \
	.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK
103 104

${PROJECT}: ${OBJECTS}
Moritz Lipp's avatar
Moritz Lipp committed
105
	$(call colorecho,CC,$@)
106
	$(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
107 108

clean:
109 110
	$(QUIET)rm -rf ${PROJECT} \
		${OBJECTS} \
Moritz Lipp's avatar
Moritz Lipp committed
111 112
		${TARFILE} \
		${TARDIR} \
113 114 115 116 117 118 119 120
		${DOBJECTS} \
		${PROJECT}-debug \
		.depend \
		${PROJECT}.pc \
		version.h \
		version.h.tmp \
		dbus-interface-definitions.c \
		dbus-interface-definitions.c.tmp \
121
		*gcda *gcno $(PROJECT).info gcov *.tmp \
122
		.version-checks
123 124
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
Moritz Lipp's avatar
Moritz Lipp committed
125
	$(QUIET)$(MAKE) -C doc clean
126 127

${PROJECT}-debug: ${DOBJECTS}
Moritz Lipp's avatar
Moritz Lipp committed
128
	$(call colorecho,CC,$@)
129
	$(QUIET)${CC} ${LDFLAGS} -o $@ ${DOBJECTS} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
130

131
debug: ${PROJECT}-debug
Moritz Lipp's avatar
Moritz Lipp committed
132

133
${PROJECT}.pc: ${PROJECT}.pc.in config.mk
134 135
	$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
	$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
136
	$(QUIET)echo apiversion=${ZATHURA_API_VERSION} >> ${PROJECT}.pc
Sebastian Ramacher's avatar
Sebastian Ramacher committed
137
	$(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc
138
	$(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc
139
	$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
140
	$(QUIET)echo GTK_VERSION=3 >> ${PROJECT}.pc
141
	$(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc
142

143
valgrind: debug
144 145
	 $(QUIET)G_SLICE=always-malloc G_DEBUG=gc-friendly ${VALGRIND} ${VALGRIND_ARGUMENTS} \
		 ./${PROJECT}-debug
146 147

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

150
test: ${OBJECTS}
151
	$(QUIET)make -C tests run
152

153
dist: clean build-manpages
154 155 156 157
	$(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
158

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

162
gcov: clean
163 164
	$(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
165 166 167
	$(QUIET)lcov --directory . --capture --output-file $(PROJECT).info
	$(QUIET)genhtml --output-directory gcov $(PROJECT).info

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

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

174
build-manpages:
175
	$(QUIET)${MAKE} -C doc man
176 177

install-manpages: build-manpages
Moritz Lipp's avatar
Moritz Lipp committed
178
	$(call colorecho,INSTALL,"man pages")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
179
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
180 181
ifneq "$(wildcard doc/_build/${PROJECT}.1)" ""
	$(QUIET)install -m 644 doc/_build/${PROJECT}.1 ${DESTDIR}${MANPREFIX}/man1
182
endif
183 184
ifneq "$(wildcard doc/_build/${PROJECT}rc.5)" ""
	$(QUIET)install -m 644 doc/_build/${PROJECT}rc.5 ${DESTDIR}${MANPREFIX}/man5
185
endif
186

187
install-headers: ${PROJECT}.pc
Moritz Lipp's avatar
Moritz Lipp committed
188
	$(call colorecho,INSTALL,"header files")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
189
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
190
	$(QUIET)install -m 644 ${HEADERINST} ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
191 192

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

196
install-dbus:
Moritz Lipp's avatar
Moritz Lipp committed
197
	$(call colorecho,INSTALL,"D-Bus interface definitions")
198
	$(QUIET)mkdir -m 755 -p $(DESTDIR)$(DBUSINTERFACEDIR)
199
	$(QUIET)install -m 644 data/org.pwmt.zathura.xml $(DESTDIR)$(DBUSINTERFACEDIR)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
200

201
install: all install-headers install-manpages install-dbus
Moritz Lipp's avatar
Moritz Lipp committed
202
	$(call colorecho,INSTALL,"executeable file")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
203
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin
204
	$(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin
Sebastian Ramacher's avatar
Sebastian Ramacher committed
205
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX}
Moritz Lipp's avatar
Moritz Lipp committed
206
	$(call colorecho,INSTALL,"desktop file")
207
	$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
208
	$(MAKE) -C po install
Moritz Lipp's avatar
Moritz Lipp committed
209

210
uninstall-headers:
Moritz Lipp's avatar
Moritz Lipp committed
211
	$(call colorecho,UNINSTALL,"header files")
212
	$(QUIET)rm -rf ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
213
	$(call colorecho,UNINSTALL,"pkgconfig file")
214 215
	$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc

216
uninstall: uninstall-headers
217
	$(ECHO) removing executable file
Moritz Lipp's avatar
Moritz Lipp committed
218
	$(call colorecho,UNINSTALL,"executeable")
219
	$(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
220
	$(call colorecho,UNINSTALL,"man pages")
221
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
222
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
Moritz Lipp's avatar
Moritz Lipp committed
223
	$(call colorecho,UNINSTALL,"desktop file")
224
	$(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
Moritz Lipp's avatar
Moritz Lipp committed
225
	$(call colorecho,UNINSTALL,"D-Bus interface definitions")
226
	$(QUIET)rm -f $(DESTDIR)$(DBUSINTERFACEDIR)/org.pwmt.zathura.xml
227
	$(MAKE) -C po uninstall
Sebastian Ramacher's avatar
Sebastian Ramacher committed
228

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

231 232 233
.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