From 3c0cbf57e8eacad16309f323d595aeb2d9351417 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 22 Jun 2018 01:54:04 +0200 Subject: Fix icons and speed up building MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- .gitignore | 3 + Makefile | 87 ++++++----------- conv.c | 180 +++++++++++++++++++++++++++++++++++ scalable/actions/paint-order-mfs.svg | 2 +- scalable/actions/paint-order-smf.svg | 2 +- 5 files changed, 212 insertions(+), 62 deletions(-) create mode 100644 conv.c diff --git a/.gitignore b/.gitignore index f9f093d..e59bfcd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *\#* /*x*/ *.theme +conv +*.o +*.su diff --git a/Makefile b/Makefile index 2782e46..e24f50d 100644 --- a/Makefile +++ b/Makefile @@ -3168,6 +3168,8 @@ ALL_PNG_ICONS = $(foreach S,$(SIZES),$(foreach I,$(ICONS),$(S)x$(S)/$(I).png)) all: index.theme $(ALL_PNG_ICONS) +all-fast: index.theme all-fast-icons + index.theme: Makefile set -e;\ printf '%s\n' \ @@ -3213,68 +3215,34 @@ index.theme: Makefile done;\ done >> index.theme -8x8/%.png: scalable/%.svg - mkdir -p -- $(@D) - s="$$(printf '%s\n' $@ | cut -d x -f 1)";\ - if test -L $<; then\ - ln -sf "$$(readlink $< | sed 's/\.svg$$/\.png/')" $@;\ - else\ - rsvg-convert -w $$s -h $$s -f png $< > $@;\ - fi +all-fast-icons: $(ICONS:=.x) + +%.x: conv + ./conv scalable/$*.svg $(SIZES) + +conv: conv.c + $(CC) -o $@ $< $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) + +8x8/%.png: scalable/%.svg conv + ./conv $@ -16x16/%.png: scalable/%.svg - mkdir -p -- $(@D) - s="$$(printf '%s\n' $@ | cut -d x -f 1)";\ - if test -L $<; then\ - ln -sf "$$(readlink $< | sed 's/\.svg$$/\.png/')" $@;\ - else\ - rsvg-convert -w $$s -h $$s -f png $< > $@;\ - fi +16x16/%.png: scalable/%.svg conv + ./conv $@ -22x22/%.png: scalable/%.svg - mkdir -p -- $(@D) - s="$$(printf '%s\n' $@ | cut -d x -f 1)";\ - if test -L $<; then\ - ln -sf "$$(readlink $< | sed 's/\.svg$$/\.png/')" $@;\ - else\ - rsvg-convert -w $$s -h $$s -f png $< > $@;\ - fi +22x22/%.png: scalable/%.svg conv + ./conv $@ -24x24/%.png: scalable/%.svg - mkdir -p -- $(@D) - s="$$(printf '%s\n' $@ | cut -d x -f 1)";\ - if test -L $<; then\ - ln -sf "$$(readlink $< | sed 's/\.svg$$/\.png/')" $@;\ - else\ - rsvg-convert -w $$s -h $$s -f png $< > $@;\ - fi +24x24/%.png: scalable/%.svg conv + ./conv $@ -32x32/%.png: scalable/%.svg - mkdir -p -- $(@D) - s="$$(printf '%s\n' $@ | cut -d x -f 1)";\ - if test -L $<; then\ - ln -sf "$$(readlink $< | sed 's/\.svg$$/\.png/')" $@;\ - else\ - rsvg-convert -w $$s -h $$s -f png $< > $@;\ - fi +32x32/%.png: scalable/%.svg conv + ./conv $@ -36x36/%.png: scalable/%.svg - mkdir -p -- $(@D) - s="$$(printf '%s\n' $@ | cut -d x -f 1)";\ - if test -L $<; then\ - ln -sf "$$(readlink $< | sed 's/\.svg$$/\.png/')" $@;\ - else\ - rsvg-convert -w $$s -h $$s -f png $< > $@;\ - fi +36x36/%.png: scalable/%.svg conv + ./conv $@ -48x48/%.png: scalable/%.svg - mkdir -p -- $(@D) - s="$$(printf '%s\n' $@ | cut -d x -f 1)";\ - if test -L $<; then\ - ln -sf "$$(readlink $< | sed 's/\.svg$$/\.png/')" $@;\ - else\ - rsvg-convert -w $$s -h $$s -f png $< > $@;\ - fi +48x48/%.png: scalable/%.svg conv + ./conv $@ install: index.theme $(ALL_PNG_ICONS) mkdir -p -- "$(DESTDIR)$(ICONPREFIX)" @@ -3298,8 +3266,7 @@ uninstall: rm -rf -- "$(DESTDIR)$(ICONPREFIX)/simple" clean: - -rm -f -- index.theme - -rm -f -- $(foreach S,$(SIZES),$(foreach I,$(ICONS),$(S)x$(S)/$(I).png)) - -rmdir -- $(foreach S,$(SIZES),$(foreach D,$(DIRS),$(S)x$(S)/$(D)) $(S)x$(S)) + -rm -f -- index.theme *.o *.su conv + -for s in $(SIZES); do printf "$${s}x$${s}\n"; done | xargs rm -rf -- -.PHONY: all install uninstall clean +.PHONY: all all-fast all-fast-icons install uninstall clean diff --git a/conv.c b/conv.c new file mode 100644 index 0000000..7c5480e --- /dev/null +++ b/conv.c @@ -0,0 +1,180 @@ +#include +#include +#include +#include +#include +#include +#include + +static char *argv0; + + +static int +single(int argc, char *argv[]) +{ + char size[10], target[4096], source[4096]; + char *p; + ssize_t r; + int fd; + + p = strchr(argv[0], 'x'); + if (!p) + return 1; + *p = '\0'; + stpcpy(size, argv[0]); + *p = 'x'; + + p = strchr(p, '/'); + if (!p) + return 1; + p = stpcpy(stpcpy(source, "scalable"), p); + if (strcmp(&p[-4], ".png")) + return 1; + stpcpy(&p[-4], ".svg"); + + for (p = argv[0]; (p = strchr(p, '/')); p++) { + *p = '\0'; + if (mkdir(argv[0], 0777) && errno != EEXIST) { + fprintf(stderr, "%s: mkdir %s 0777: %s\n", argv0, argv[0], strerror(errno)); + return 1; + } + *p = '/'; + } + + r = readlink(source, target, sizeof(target) - 1); + if (r >= 0) + target[r] = 0; + if (r >= 0 && (r >= sizeof(target) - 1 || r < 4 || strcmp(&target[r - 4], ".svg"))) { + return 1; + } else if (r < 0 && errno == EINVAL) { + fd = open(argv[0], O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (fd < 0) { + fprintf(stderr, "%s: open %s O_WRONLY|O_CREAT|O_TRUNC 0666: %s\n", argv0, argv[0], strerror(errno)); + return 1; + } + if (fd != STDOUT_FILENO) { + if (dup2(fd, STDOUT_FILENO) != STDOUT_FILENO) + fprintf(stderr, "%s: dup2 %i 1: %s\n", argv0, fd, strerror(errno)); + close(fd); + } + execlp("rsvg-convert", "rsvg-convert", "-w", size, "-h", size, "-f", "png", source, NULL); + fprintf(stderr, "%s: execvp rsvg-convert: %s\n", argv0, strerror(errno)); + return 1; + } else if (r < 0) { + fprintf(stderr, "%s: readlink %s: %s\n", argv0, source, strerror(errno)); + return 1; + } else { + stpcpy(&target[r - 4], ".png"); + if (symlink(target, argv[0])) { + if (errno == EEXIST) { + unlink(argv[0]); + if (!symlink(target, argv[0])) + return 0; + } + fprintf(stderr, "%s: symlink %s %s: %s\n", argv0, target, argv[0], strerror(errno)); + return 1; + } + return 0; + } +} + + +static int +multi(int argc, char *argv[]) +{ + char *source, output[4096], target[4096]; + char *p, *q; + pid_t pid; + int status, fd, i; + ssize_t r; + + source = *argv++, argc--; + + q = strchr(source, '/'); + if (!q) + return 1; + + for (i = 0; i < argc; i++) { + stpcpy(stpcpy(stpcpy(stpcpy(output, argv[i]), "x"), argv[i]), q); + for (p = output; (p = strchr(p, '/')); p++) { + *p = '\0'; + if (mkdir(output, 0777) && errno != EEXIST) { + fprintf(stderr, "%s: mkdir %s 0777: %s\n", argv0, output, strerror(errno)); + return 1; + } + *p = '/'; + } + } + + r = readlink(source, target, sizeof(target) - 1); + if (r >= 0) + target[r] = 0; + if (r >= 0 && (r >= sizeof(target) - 1 || r < 4 || strcmp(&target[r - 4], ".svg"))) { + return 1; + } else if (r < 0 && errno == EINVAL) { + p = stpcpy(stpcpy(stpcpy(stpcpy(output, argv[0]), "x"), argv[0]), q); + stpcpy(&p[-4], ".png"); + for (; *argv; argv++, argc--) { + pid = argc == 1 ? 0 : fork(); + if (pid == -1) { + fprintf(stderr, "%s: fork: %s\n", argv0, strerror(errno)); + return 1; + } + if (pid) { + p = stpcpy(stpcpy(stpcpy(stpcpy(output, argv[1]), "x"), argv[1]), q); + stpcpy(&p[-4], ".png"); + if (waitpid(pid, &status, 0) != pid) { + fprintf(stderr, "%s: waitpid rsvg-convert: %s\n", argv0, strerror(errno)); + return 1; + } + if (status) + return 1; + continue; + } + fd = open(output, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (fd < 0) { + fprintf(stderr, "%s: open %s O_WRONLY|O_CREAT|O_TRUNC 0666: %s\n", argv0, output, strerror(errno)); + return 1; + } + if (fd != STDOUT_FILENO) { + if (dup2(fd, STDOUT_FILENO) != STDOUT_FILENO) + fprintf(stderr, "%s: dup2 %i 1: %s\n", argv0, fd, strerror(errno)); + close(fd); + } + execlp("rsvg-convert", "rsvg-convert", "-w", *argv, "-h", *argv, "-f", "png", source, NULL); + fprintf(stderr, "%s: execvp rsvg-convert: %s\n", argv0, strerror(errno)); + return 1; + } + } else if (r < 0) { + fprintf(stderr, "%s: readlink %s: %s\n", argv0, source, strerror(errno)); + return 1; + } else { + stpcpy(&target[r - 4], ".png"); + for (; *argv; argv++) { + p = stpcpy(stpcpy(stpcpy(stpcpy(output, *argv), "x"), *argv), q); + stpcpy(&p[-4], ".png"); + if (symlink(target, output)) { + if (errno == EEXIST) { + unlink(output); + if (!symlink(target, output)) + continue; + } + fprintf(stderr, "%s: symlink %s %s: %s\n", argv0, target, output, strerror(errno)); + return 1; + } + } + return 0; + } +} + + +int +main(int argc, char *argv[]) +{ + argv0 = *argv++, argc--; + if (argc == 1) + return single(argc, argv); + if (argc > 1) + return multi(argc, argv); + return 1; +} diff --git a/scalable/actions/paint-order-mfs.svg b/scalable/actions/paint-order-mfs.svg index c11aefb..bde4305 100644 --- a/scalable/actions/paint-order-mfs.svg +++ b/scalable/actions/paint-order-mfs.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/scalable/actions/paint-order-smf.svg b/scalable/actions/paint-order-smf.svg index b453412..ae5692c 100644 --- a/scalable/actions/paint-order-smf.svg +++ b/scalable/actions/paint-order-smf.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file -- cgit v1.2.3-70-g09d2