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

include config.mk
Moritz Lipp's avatar
Moritz Lipp committed
4
include colors.mk
5 6 7 8 9 10 11
include common.mk

PROJECTNV     = girara
PROJECT       = girara-gtk3

SOURCE        = $(wildcard ${PROJECTNV}/*.c)
CSOURCE       = $(filter-out ${PROJECTNV}/css-definitions.c, ${SOURCE})
Moritz Lipp's avatar
Moritz Lipp committed
12

13 14 15 16 17 18 19 20
OBJECTS       = $(addprefix ${BUILDDIR_RELEASE}/,${CSOURCE:.c=.o}) \
	${BUILDDIR_RELEASE}/${PROJECTNV}/css-definitions.o
OBJECTS_DEBUG = $(addprefix ${BUILDDIR_DEBUG}/,${CSOURCE:.c=.o}) \
	${BUILDDIR_DEBUG}/${PROJECTNV}/css-definitions.o
OBJECTS_GCOV  = $(addprefix ${BUILDDIR_GCOV}/,${CSOURCE:.c=.o}) \
	${BUILDDIR_GCOV}/${PROJECTNV}/css-definitions.o

HEADERS       = $(filter-out ${PROJECTNV}/internal.h, $(wildcard ${PROJECTNV}/*.h))
21

22 23
ifneq (${WITH_LIBNOTIFY},0)
CPPFLAGS += -DWITH_LIBNOTIFY
24 25 26
LIBNOTIFY_PC_NAME = libnotify
else
LIBNOTIFY_PC_NAME =
27
endif
28

29 30
ifneq (${WITH_JSON},0)
CPPFLAGS += -DWITH_JSON
31 32 33
JSON_PC_NAME = json-c
else
JSON_PC_NAME =
34 35
endif

36
ifeq (,$(findstring -DGETTEXT_PACKAGE,${CPPFLAGS}))
37
CPPFLAGS += -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\"
38 39 40 41 42
endif
ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS}))
CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\"
endif

43 44 45 46 47 48
UNAME := $(shell uname -s)
ifeq ($(UNAME), Darwin)
SONAME_FLAG = -install_name
SHARED_FLAG = -dynamiclib
endif

49
all: ${PROJECTNV} ${BUILDDIR}/${PROJECT}.pc po
Moritz Lipp's avatar
Moritz Lipp committed
50

51
# pkg-config based version checks
52
.version-checks/%: config.mk
53
	$(QUIET)test $($(*)_VERSION_CHECK) -eq 0 || \
54
		${PKG_CONFIG} --atleast-version $($(*)_MIN_VERSION) $($(*)_PKG_CONFIG_NAME) || ( \
Sebastian Ramacher's avatar
Sebastian Ramacher committed
55
		echo "The minimum required version of $(*) is $($(*)_MIN_VERSION)" && \
56 57 58 59 60
		false \
	)
	@mkdir -p .version-checks
	$(QUIET)touch $@

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

68 69 70
# generated files

${PROJECTNV}/version.h: ${PROJECTNV}/version.h.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
71
	$(call colorecho,GEN,$@)
72 73
	$(QUIET)sed \
		-e 's,@GVMAJOR@,${GIRARA_VERSION_MAJOR},' \
74 75
		-e 's,@GVMINOR@,${GIRARA_VERSION_MINOR},' \
		-e 's,@GVREV@,${GIRARA_VERSION_REV},' \
76 77
		${PROJECTNV}/version.h.in > ${PROJECTNV}/version.h.tmp
	$(QUIET)mv ${PROJECTNV}/version.h.tmp ${PROJECTNV}/version.h
78

79
${PROJECTNV}/css-definitions.c: data/girara.css_t
Sebastian Ramacher's avatar
Sebastian Ramacher committed
80
	$(call colorecho,GEN,$@)
81 82 83 84 85 86
	$(QUIET)echo '#include "css-definitions.h"' > $@.tmp
	$(QUIET)echo 'const char* CSS_TEMPLATE =' >> $@.tmp
	$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' $< >> $@.tmp
	$(QUIET)echo ';' >> $@.tmp
	$(QUIET)mv $@.tmp $@

87
${BUILDDIR}/${PROJECT}.pc: ${PROJECTNV}.pc.in config.mk
Sebastian Ramacher's avatar
Sebastian Ramacher committed
88
	$(call colorecho,GEN,$(shell basename $@))
89
	@mkdir -p ${BUILDDIR}
90 91
	$(QUIET)sed -e 's,@PROJECT@,${PROJECT},' \
		-e 's,@VERSION@,${VERSION},' \
92 93
		-e 's,@INCLUDEDIR@,${INCLUDEDIR},' \
		-e 's,@LIBDIR@,${LIBDIR},' \
94
		-e 's,@LIBNOTIFY_PC_NAME@,${LIBNOTIFY_PC_NAME},' \
95
		-e 's,@JSON_PC_NAME@,${JSON_PC_NAME},' \
96 97
		${PROJECTNV}.pc.in > $@.tmp
	$(QUIET)mv $@.tmp $@
98 99

# release build
Moritz Lipp's avatar
Moritz Lipp committed
100

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

${BUILDDIR_RELEASE}/%.o: %.c
Moritz Lipp's avatar
Moritz Lipp committed
107
	$(call colorecho,CC,$<)
108
	@mkdir -p ${DEPENDDIR}/$(dir $@)
109 110
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $< \
111
		-MMD -MF ${DEPENDDIR}/$@.dep
112 113 114 115

${BUILDDIR_RELEASE}/${BINDIR}/lib${PROJECT}.a: ${OBJECTS}
	$(call colorecho,AR,$@)
	@mkdir -p ${BUILDDIR_RELEASE}/${BINDIR}
116
	$(QUIET)${AR} rcs $@ ${OBJECTS}
Moritz Lipp's avatar
Moritz Lipp committed
117

118 119 120 121 122
${BUILDDIR_RELEASE}/${BINDIR}/lib${PROJECT}.so.${SOVERSION}: ${OBJECTS}
	$(call colorecho,LD,$@)
	@mkdir -p ${BUILDDIR_RELEASE}/${BINDIR}
	$(QUIET)${CC} -Wl,${SONAME_FLAG},lib${PROJECT}.so.${SOMAJOR} \
		${SHARED_FLAG} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}
Moritz Lipp's avatar
Moritz Lipp committed
123

124
${PROJECT}: static shared
Moritz Lipp's avatar
Moritz Lipp committed
125
${PROJECTNV}: ${PROJECT}
126 127 128 129 130 131 132 133 134 135 136 137 138
static: ${BUILDDIR_RELEASE}/${BINDIR}/lib${PROJECT}.a
shared: ${BUILDDIR_RELEASE}/${BINDIR}/lib${PROJECT}.so.${SOVERSION}
release: ${PROJECT}

# debug build

${OBJECT_DEBUG}: config.mk \
	${PROJECTNV}/version.h \
	.version-checks/GTK \
	.version-checks/GLIB

${BUILDDIR_DEBUG}/%.o: %.c
	$(call colorecho,CC,$<)
139
	@mkdir -p ${DEPENDDIR}/$(dir $@)
140 141
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} -o $@ $< \
142
		-MMD -MF ${DEPENDDIR}/$@.dep
143

144
${BUILDDIR_DEBUG}/${BINDIR}/lib${PROJECT}.a: ${OBJECTS_DEBUG}
Moritz Lipp's avatar
Moritz Lipp committed
145
	$(call colorecho,AR,$@)
146
	@mkdir -p ${BUILDDIR_DEBUG}/${BINDIR}
147
	$(QUIET)${AR} rcs $@ ${OBJECTS_DEBUG}
148

149
${BUILDDIR_DEBUG}/${BINDIR}/lib${PROJECT}.so.${SOVERSION}: ${OBJECTS_DEBUG}
Moritz Lipp's avatar
Moritz Lipp committed
150
	$(call colorecho,LD,$@)
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	@mkdir -p ${BUILDDIR_DEBUG}/${BINDIR}
	$(QUIET)${CC} -Wl,${SONAME_FLAG},lib${PROJECT}.so.${SOMAJOR} ${SHARED_FLAG} ${LDFLAGS} -o $@ ${OBJECTS_DEBUG} ${LIBS}

${PROJECT}-debug: \
	${BUILDDIR_DEBUG}/${BINDIR}/lib${PROJECT}.a \
	${BUILDDIR_DEBUG}/${BINDIR}/lib${PROJECT}.so.${SOVERSION}
debug: ${PROJECT}-debug

# gcov build

${OBJECTS_GCOV}: config.mk \
	${PROJECTNV}/version.h \
	.version-checks/GLIB \
	.version-checks/GTK

${BUILDDIR_GCOV}/%.o: %.c
	$(call colorecho,CC,$<)
168
	@mkdir -p ${DEPENDDIR}/$(dir $@)
169 170
	@mkdir -p $(dir $(abspath $@))
	$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${GCOV_CFLAGS} \
171
		-o $@ $< -MMD -MF ${DEPENDDIR}/$@.dep
172 173 174 175

${BUILDDIR_GCOV}/${BINDIR}/lib${PROJECT}.a: ${OBJECTS_GCOV}
	$(call colorecho,AR,$@)
	@mkdir -p ${BUILDDIR_GCOV}/${BINDIR}
176
	$(QUIET)${AR} rcs $@ ${OBJECTS_GCOV}
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

${BUILDDIR_GCOV}/${BINDIR}/lib${PROJECT}.so.${SOVERSION}: ${OBJECTS_GCOV}
	$(call colorecho,LD,$@)
	@mkdir -p ${BUILDDIR_GCOV}/${BINDIR}
	$(QUIET)${CC} -Wl,${SONAME_FLAG},lib${PROJECT}.so.${SOMAJOR} ${SHARED_FLAG} \
		${GCOV_LDFLAGS} -o $@ ${OBJECTS_GCOV} ${LIBS}

${PROJECT}-gcov: ${BUILDDIR_GCOV}/${BINDIR}/lib${PROJECT}.a
gcov: ${PROJECT}-gcov

run-gcov: options gcov
	$(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}

# clean
Moritz Lipp's avatar
Moritz Lipp committed
195 196

clean:
Moritz Lipp's avatar
Moritz Lipp committed
197
	$(QUIET)rm -rf \
198 199
		${BUILDDIR} \
		${DEPENDDIR} \
Moritz Lipp's avatar
Moritz Lipp committed
200 201 202 203 204 205
		${TARFILE} \
		${GCDA} \
		${GCNO} \
		$(PROJECT).info \
		gcov \
		.version-checks \
206 207 208 209 210 211 212
		${PROJECTNV}/version.h \
		${PROJECTNV}/version.h.tmp \
		${PROJECTNV}/css-definitions.c \
		${PROJECTNV}/css-definitions.c.tmp
	$(QUIET)$(MAKE) -C tests clean
	$(QUIET)$(MAKE) -C po clean
	$(QUIET)$(MAKE) -C doc clean
Moritz Lipp's avatar
Moritz Lipp committed
213

214
# translations
215

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

219 220
update-po:
	$(QUIET)${MAKE} -C po update-po
Moritz Lipp's avatar
Moritz Lipp committed
221

222
# documentation
223

Sebastian Ramacher's avatar
Sebastian Ramacher committed
224
doc:
225
	$(QUIET)$(MAKE) -C doc
226

227
# tests
228

Sebastian Ramacher's avatar
Sebastian Ramacher committed
229
test: ${PROJECT}
230
	$(QUIET)$(MAKE) -C tests run
Moritz Lipp's avatar
Moritz Lipp committed
231

232 233
test-debug: ${PROJECT}-debug
	$(QUIET)$(MAKE) -C tests run-debug
Sebastian Ramacher's avatar
Sebastian Ramacher committed
234

235 236 237
# create taball

dist:
Moritz Lipp's avatar
Moritz Lipp committed
238 239 240
	$(QUIET)tar -czf $(TARFILE) --exclude=.gitignore \
		--transform 's,^,$(PROJECTNV)-$(VERSION)/,' \
		`git ls-files`
Moritz Lipp's avatar
Moritz Lipp committed
241

242
# install
243

244
install-static: static
Moritz Lipp's avatar
Moritz Lipp committed
245
	$(call colorecho,INSTALL,"Install static library")
246
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}
247
	$(QUIET)install -m 644 ${BUILDDIR_RELEASE}/${BINDIR}/lib${PROJECT}.a ${DESTDIR}${LIBDIR}
248 249

install-shared: shared
Moritz Lipp's avatar
Moritz Lipp committed
250
	$(call colorecho,INSTALL,"Install shared library")
251
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}
252
	$(QUIET)install -m 644 ${BUILDDIR_RELEASE}/${BINDIR}/lib${PROJECT}.so.${SOVERSION} ${DESTDIR}${LIBDIR}
253
	$(QUIET)ln -sf lib${PROJECT}.so.${SOVERSION} ${DESTDIR}${LIBDIR}/lib${PROJECT}.so.${SOMAJOR} || \
254
		echo "Failed to create lib${PROJECT}.so.${SOMAJOR}. Please check if it exists and points to the correct version of lib${PROJECT}.so."
255
	$(QUIET)ln -sf lib${PROJECT}.so.${SOVERSION} ${DESTDIR}${LIBDIR}/lib${PROJECT}.so || \
256
		echo "Failed to create lib${PROJECT}.so. Please check if it exists and points to the correct version of lib${PROJECT}.so."
257

258
install-headers: ${PROJECTNV}/version.h ${BUILDDIR}/${PROJECT}.pc
Moritz Lipp's avatar
Moritz Lipp committed
259
	$(call colorecho,INSTALL,"Install pkg-config file")
260
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}/pkgconfig
261
	$(QUIET)install -m 644 ${BUILDDIR}/${PROJECT}.pc ${DESTDIR}${LIBDIR}/pkgconfig
Moritz Lipp's avatar
Moritz Lipp committed
262
	$(call colorecho,INSTALL,"Install header files")
263
	$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/girara
264 265 266 267 268 269 270 271
	$(QUIET)install -m 644 ${HEADERS} ${DESTDIR}${INCLUDEDIR}/girara

install-po:
	$(QUIET)${MAKE} -C po install

install: install-po install-static install-shared install-headers

# uninstall
Moritz Lipp's avatar
Moritz Lipp committed
272 273

uninstall: uninstall-headers
Moritz Lipp's avatar
Moritz Lipp committed
274
	$(call colorecho,UNINSTALL,"Remove library files")
275 276
	$(QUIET)rm -f ${LIBDIR}/lib${PROJECT}.a ${LIBDIR}/lib${PROJECT}.so.${SOVERSION} \
		${LIBDIR}/lib${PROJECT}.so.${SOMAJOR} ${LIBDIR}/lib${PROJECT}.so
Moritz Lipp's avatar
Moritz Lipp committed
277
	$(QUIET)${MAKE} -C po uninstall
Sebastian Ramacher's avatar
Sebastian Ramacher committed
278

Moritz Lipp's avatar
Moritz Lipp committed
279
uninstall-headers:
Moritz Lipp's avatar
Moritz Lipp committed
280
	$(call colorecho,UNINSTALL,"Remove header files")
281
	$(QUIET)rm -rf ${DESTDIR}${INCLUDEDIR}/girara
Moritz Lipp's avatar
Moritz Lipp committed
282
	$(call colorecho,UNINSTALL,"Remove pkg-config file")
283
	$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc
Moritz Lipp's avatar
Moritz Lipp committed
284

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

288
.PHONY: all options clean debug doc test dist install install-headers uninstall \
289 290
	uninstall-headers ${PROJECT} ${PROJECT}-debug po update-po \
	static shared install-static install-shared