Use glib-compile-resource instead of sed magic

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2017-05-30 23:10:06 +02:00
parent 8c5b4a83cf
commit 2c6ab6b092
6 changed files with 29 additions and 20 deletions

2
.gitignore vendored
View file

@ -10,7 +10,7 @@
# generated files
dbus-interface-definitions.c
css-definitions.c
css-definitions.*
zathura.1
zathurarc.5

View file

@ -85,16 +85,17 @@ ${PROJECT}/version.h: ${PROJECT}/version.h.in config.mk
-e 's/ZVABI/${ZATHURA_ABI_VERSION}/' ${PROJECT}/version.h.in > ${PROJECT}/version.h.tmp
$(QUIET)mv ${PROJECT}/version.h.tmp ${PROJECT}/version.h
${PROJECT}/css-definitions.c: data/zathura.css_t
$(QUIET)echo '#include "css-definitions.h"' > $@.tmp
$(QUIET)echo 'const char* CSS_TEMPLATE_INDEX =' >> $@.tmp
$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' $< >> $@.tmp
$(QUIET)echo ';' >> $@.tmp
$(QUIET)mv $@.tmp $@
${PROJECT}/css-definitions.%: data/zathura-css.gresource.xml config.mk
$(call colorecho,GEN,$@)
@mkdir -p ${DEPENDDIR}/$(dir $@)
$(QUIET)$(GLIB_COMPILE_RESOURCES) --generate --c-name=zathura_css --internal \
--dependency-file=$(DEPENDDIR)/$@.dep \
--sourcedir=data --target=$@ data/zathura-css.gresource.xml
# common dependencies
${OBJECTS} ${OBJECTS_DEBUG} ${OBJECTS_GCOV}: config.mk ${PROJECT}/version.h \
${OBJECTS} ${OBJECTS_DEBUG} ${OBJECTS_GCOV}: config.mk \
${PROJECT}/version.h ${PROJECT}/css-definitions.h \
.version-checks/GIRARA .version-checks/GLIB .version-checks/GTK
# rlease build

View file

@ -32,6 +32,9 @@ GTK_PKG_CONFIG_NAME = gtk+-3.0
# pkg-config binary
PKG_CONFIG ?= pkg-config
# glib-compile-resources
GLIB_COMPILE_RESOURCES ?= glib-compile-resources
# database
# To disable support for the sqlite backend set WITH_SQLITE to 0.
WITH_SQLITE ?= $(shell (${PKG_CONFIG} --atleast-version=3.5.9 sqlite3 && echo 1) || echo 0)

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/pwmt/zathura/CSS">
<file compressed="true">zathura.css_t</file>
</gresource>
</gresources>

View file

@ -1,8 +0,0 @@
/* See LICENSE file for license and copyright information */
#ifndef GIRARA_CSS_DEFINITIONS_H
#define GIRARA_CSS_DEFINITIONS_H
extern const char* CSS_TEMPLATE_INDEX;
#endif

View file

@ -251,10 +251,17 @@ init_css(zathura_t* zathura)
g_free(color);
}
char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate),
CSS_TEMPLATE_INDEX);
girara_template_set_base(csstemplate, css);
g_free(css);
GResource* css_resource = zathura_css_get_resource();
GBytes* css_data = g_resource_lookup_data(css_resource,
"/org/pwmt/zathura/CSS/zathura.css_t",
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
if (css_data != NULL) {
char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate),
g_bytes_get_data(css_data, NULL));
girara_template_set_base(csstemplate, css);
g_free(css);
g_bytes_unref(css_data);
}
}
static void