# HG changeset patch
# User Mike Miller <mtmiller@ieee.org>
# Date 1390368497 18000
#      Wed Jan 22 00:28:17 2014 -0500
# Node ID c688cad0755c71dc5581a47da74b6f212084475b
# Parent  0187ed94862752016bc628af88a8e851043c8e3e
Build all Octave icons from SVG source file

* acinclude.m4 (OCTAVE_PROG_ICOTOOL, OCTAVE_PROG_RSVG_CONVERT): New macros.
* configure.ac: Use them. Set AMCOND_HAVE_ICON_TOOLS.
* doc/icons/Makefile.am (BUILT_PNG_ICONS): Build icons of varying sizes
from SVG source. (octave-logo.ico) Build Windows icon containing a subset
of built PNG icons.
* octave-logo.ico, octave-logo.png: Delete.

diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -158,6 +158,12 @@
 OCTAVE_PROG_PAGER
 OCTAVE_PROG_PYTHON
 
+## Programs used to generate icons file formats.
+OCTAVE_PROG_ICOTOOL
+OCTAVE_PROG_RSVG_CONVERT
+AM_CONDITIONAL([AMCOND_HAVE_ICON_TOOLS],
+  [test -n "$ICOTOOL" && test -n "$RSVG_CONVERT"])
+
 ### Default terminal font for the GUI
 case $host_os in
   mingw* | msdosmsvc)
diff --git a/doc/icons/Makefile.am b/doc/icons/Makefile.am
--- a/doc/icons/Makefile.am
+++ b/doc/icons/Makefile.am
@@ -21,14 +21,31 @@
 include $(top_srcdir)/build-aux/common.mk
 
 IMAGE_FILES = \
-  octave-logo.ico \
-  octave-logo.png \
   octave-logo.svg \
   octave-sombrero.png
 
+PNG_SIZES = \
+  512 \
+  256 \
+  128 \
+  64 \
+  48 \
+  32 \
+  24 \
+  22 \
+  16
+
+BUILT_PNG_ICONS = $(patsubst %,octave-logo-%.png,$(PNG_SIZES))
+
+WIN_PNG_ICONS = $(filter %-16.png %-32.png %-48.png %-256.png,$(BUILT_PNG_ICONS))
+
+BUILT_ICONS = \
+  $(BUILT_PNG_ICONS) \
+  octave-logo.ico
+
 image_DATA = $(IMAGE_FILES)
 
-all-local: octave.desktop
+all-local: octave.desktop $(BUILT_ICONS)
 
 octave.desktop: octave.desktop.in Makefile
 	@echo "making $@ from $<"
@@ -37,20 +54,49 @@
 	  -e "s|%OCTAVE_PREFIX%|${prefix}|"
 	mv $@-t $@
 
+$(BUILT_PNG_ICONS): octave-logo.svg
+	$(RSVG_CONVERT) -w $(lastword $(subst -, ,$(patsubst %.png,%,$@))) $< > $@-t
+	mv $@-t $@
+
+octave-logo.ico: $(WIN_PNG_ICONS)
+	$(ICOTOOL) --create --raw $^ > $@-t
+	mv $@-t $@
+
 install-data-local:
 	-if test -n "$(DESKTOP_FILE_INSTALL)"; then \
 	  $(DESKTOP_FILE_INSTALL) --dir=$(DESTDIR)$(datadir)/applications \
 	    --vendor www.octave.org octave.desktop; \
 	fi
+	for f in $(BUILT_PNG_ICONS); do \
+	  size=`echo $$f | $(SED) -n -e "s/.*-\([0-9]\+\)\.png/\1/p"`; \
+	  $(MKDIR_P) $(DESTDIR)$(datadir)/icons/hicolor/$${size}x$${size}/apps; \
+	  $(INSTALL_DATA) $$f $(DESTDIR)$(datadir)/icons/hicolor/$${size}x$${size}/apps/octave.png; \
+	done
+	$(MKDIR_P) $(DESTDIR)$(datadir)/icons/hicolor/scalable/apps
+	$(INSTALL_DATA) $(srcdir)/octave-logo.svg $(DESTDIR)$(datadir)/icons/hicolor/scalable/apps/octave.svg
 
 uninstall-local:
 	if test -n "$(DESKTOP_FILE_INSTALL)"; then \
 	  rm -f $(DESTDIR)$(datadir)/applications/www.octave.org-octave.desktop; \
 	fi
+	for f in $(BUILT_PNG_ICONS); do \
+	  size=`echo $$f | $(SED) -n -e "s/.*-\([0-9]\+\)\.png/\1/p"`; \
+	  rm -f $(DESTDIR)$(datadir)/icons/hicolor/$${size}x$${size}/apps/octave.png; \
+	done
+	rm -f $(DESTDIR)$(datadir)/icons/hicolor/scalable/apps/octave.svg
+
+if AMCOND_HAVE_ICON_TOOLS
+else
+dist-hook:
+	@echo "Packaging distribution requires icotool and rsvg-convert." ; exit 1;
+endif
 
 EXTRA_DIST = \
+  $(BUILT_ICONS) \
   $(IMAGE_FILES) \
   octave.desktop.in
 
 CLEANFILES = octave.desktop
 
+MAINTAINERCLEANFILES = $(BUILT_ICONS)
+
diff --git a/doc/icons/octave-logo.ico b/doc/icons/octave-logo.ico
deleted file mode 100644
index 563469b0a29f69e0baa986849f43fb538d552488..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
diff --git a/doc/icons/octave-logo.png b/doc/icons/octave-logo.png
deleted file mode 100644
index 87f61c8d410b57a8cc43d374ed45f495e7fa6058..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
diff --git a/m4/acinclude.m4 b/m4/acinclude.m4
--- a/m4/acinclude.m4
+++ b/m4/acinclude.m4
@@ -1945,6 +1945,13 @@
   AC_SUBST(GPERF)
 ])
 dnl
+dnl Find icotool program.
+dnl
+AC_DEFUN([OCTAVE_PROG_ICOTOOL], [
+  AC_CHECK_PROG(ICOTOOL, icotool, icotool, [])
+  AC_SUBST(ICOTOOL)
+])
+dnl
 dnl Check for makeinfo.
 dnl
 AC_DEFUN([OCTAVE_PROG_MAKEINFO], [
@@ -1999,6 +2006,13 @@
   AC_SUBST(PYTHON)
 ])
 dnl
+dnl Find rsvg-convert program.
+dnl
+AC_DEFUN([OCTAVE_PROG_RSVG_CONVERT], [
+  AC_CHECK_PROG(RSVG_CONVERT, rsvg-convert, rsvg-convert, [])
+  AC_SUBST(RSVG_CONVERT)
+])
+dnl
 dnl Find sed program.
 dnl
 # Check for a fully-functional sed program, that truncates
