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

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))
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 $@
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
Moritz Lipp's avatar
Moritz Lipp committed
78 79
	$(call colorecho,CC,$<)
	$(QUIET) 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
Moritz Lipp's avatar
Moritz Lipp committed
83
	$(call colorecho,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}
Moritz Lipp's avatar
Moritz Lipp committed
91
	$(call colorecho,CC,$@)
92
	$(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
93 94

clean:
95 96
	$(QUIET)rm -rf ${PROJECT} \
		${OBJECTS} \
Moritz Lipp's avatar
Moritz Lipp committed
97 98
		${TARFILE} \
		${TARDIR} \
99 100 101 102 103 104 105 106
		${DOBJECTS} \
		${PROJECT}-debug \
		.depend \
		${PROJECT}.pc \
		version.h \
		version.h.tmp \
		dbus-interface-definitions.c \
		dbus-interface-definitions.c.tmp \
107
		*gcda *gcno $(PROJECT).info gcov *.tmp \
108
		.version-checks
109 110
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
Moritz Lipp's avatar
Moritz Lipp committed
111
	$(QUIET)$(MAKE) -C doc clean
112 113

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

117
debug: ${PROJECT}-debug
Moritz Lipp's avatar
Moritz Lipp committed
118

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

129
valgrind: debug
130 131
	 $(QUIET)G_SLICE=always-malloc G_DEBUG=gc-friendly ${VALGRIND} ${VALGRIND_ARGUMENTS} \
		 ./${PROJECT}-debug
132 133

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

136
test: ${OBJECTS}
137
	$(QUIET)make -C tests run
138

139
dist: clean build-manpages
Moritz Lipp's avatar
Moritz Lipp committed
140 141 142 143 144 145 146
	$(QUIET)tar -czf $(TARFILE) `git ls-files`
	$(QUIET)rm -rf ${TARDIR}
	$(QUIET)mkdir -p ${TARDIR}
	$(QUIET)tar -xvf ${TARFILE} -C ${TARDIR}
	$(QUIET)find ${TARDIR} -name '.gitignore' -exec rm {} \;
	$(QUIET)tar -czf ${TARFILE} ${TARDIR}
	$(QUIET)rm -rf ${TARDIR}
Moritz Lipp's avatar
Moritz Lipp committed
147

Sebastian Ramacher's avatar
Sebastian Ramacher committed
148
doc:
Moritz Lipp's avatar
Moritz Lipp committed
149
	$(QUIET)make -C doc
150

151
gcov: clean
152 153
	$(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
154 155 156
	$(QUIET)lcov --directory . --capture --output-file $(PROJECT).info
	$(QUIET)genhtml --output-directory gcov $(PROJECT).info

157 158 159
po:
	$(QUIET)${MAKE} -C po

160 161 162
update-po:
	$(QUIET)${MAKE} -C po update-po

163
build-manpages:
164
	$(QUIET)${MAKE} -C doc man
165 166

install-manpages: build-manpages
Moritz Lipp's avatar
Moritz Lipp committed
167
	$(call colorecho,INSTALL,"man pages")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
168
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
169 170
ifneq "$(wildcard ./doc/_build/man/${PROJECT}.1)" ""
	$(QUIET)install -m 644 ./doc/_build/man/${PROJECT}.1 ${DESTDIR}${MANPREFIX}/man1
171
endif
172 173
ifneq "$(wildcard ./doc/_build/man/${PROJECT}rc.5)" ""
	$(QUIET)install -m 644 ./doc/_build/man/${PROJECT}rc.5 ${DESTDIR}${MANPREFIX}/man5
174
endif
175

176
install-headers: ${PROJECT}.pc
Moritz Lipp's avatar
Moritz Lipp committed
177
	$(call colorecho,INSTALL,"header files")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
178
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Sebastian Ramacher's avatar
Sebastian Ramacher committed
179
	$(QUIET)install -m 644 ${HEADERINST} ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
180 181

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

185
install-dbus:
Moritz Lipp's avatar
Moritz Lipp committed
186
	$(call colorecho,INSTALL,"D-Bus interface definitions")
187
	$(QUIET)mkdir -m 755 -p $(DESTDIR)$(DBUSINTERFACEDIR)
188
	$(QUIET)install -m 644 data/org.pwmt.zathura.xml $(DESTDIR)$(DBUSINTERFACEDIR)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
189

190
install: all install-headers install-manpages install-dbus
Moritz Lipp's avatar
Moritz Lipp committed
191
	$(call colorecho,INSTALL,"executeable file")
Sebastian Ramacher's avatar
Sebastian Ramacher committed
192
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin
193
	$(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin
Sebastian Ramacher's avatar
Sebastian Ramacher committed
194
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX}
Moritz Lipp's avatar
Moritz Lipp committed
195
	$(call colorecho,INSTALL,"desktop file")
196
	$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
197
	$(MAKE) -C po install
Moritz Lipp's avatar
Moritz Lipp committed
198

199
uninstall-headers:
Moritz Lipp's avatar
Moritz Lipp committed
200
	$(call colorecho,UNINSTALL,"header files")
201
	$(QUIET)rm -rf ${DESTDIR}${INCLUDEDIR}/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
202
	$(call colorecho,UNINSTALL,"pkgconfig file")
203 204
	$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc

205
uninstall: uninstall-headers
206
	$(ECHO) removing executable file
Moritz Lipp's avatar
Moritz Lipp committed
207
	$(call colorecho,UNINSTALL,"executeable")
208
	$(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
Moritz Lipp's avatar
Moritz Lipp committed
209
	$(call colorecho,UNINSTALL,"man pages")
210
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
211
	$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
Moritz Lipp's avatar
Moritz Lipp committed
212
	$(call colorecho,UNINSTALL,"desktop file")
213
	$(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
Moritz Lipp's avatar
Moritz Lipp committed
214
	$(call colorecho,UNINSTALL,"D-Bus interface definitions")
215
	$(QUIET)rm -f $(DESTDIR)$(DBUSINTERFACEDIR)/org.pwmt.zathura.xml
216
	$(MAKE) -C po uninstall
Sebastian Ramacher's avatar
Sebastian Ramacher committed
217

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

220 221 222
.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