Smake: Factor output repetitive code into new script in build-aux.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Jan 2015 00:05:44 +0000 (16:05 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Jan 2015 00:05:58 +0000 (16:05 -0800)
I planned to add another kind of icon but even without that change
this makes the code more readable.

Smake
build-aux/automake.mk
build-aux/icon-list [new file with mode: 0644]

diff --git a/Smake b/Smake
index b27456bced1c709447c3f1efec04615c3c9e220b..09f1c84e0a2c5bd9f7d8d1fbe04a397590793c5e 100644 (file)
--- a/Smake
+++ b/Smake
@@ -303,39 +303,11 @@ all: prep_ph  icons
 icons: $(ICONS) src/ui/gui/icons/icon-names.c
 
 src/ui/gui/icons/icon-names.c: $(MAKEFILE_LIST)
-       $(RM) $@
+       $(RM) -f $@
        printf '/* This is a generated file. Do not edit. */\n' >> $@
-       printf '#include "icon-names.h"\n' >> $@
-       echo >> $@
-       printf 'static const char *action_icon_name[] =' >> $@
-       printf '\n{\n' >> $@
-       for i in $(ACTION_ICONS) ; do \
-        echo $$i; \
-       done | sed -e 's%[a-zA-Z/]*/[1-9]*x[1-9]*/\([^ ]*\)\.png%\1%g' | sort -u | while read f ; do \
-        printf '  "%s", \n' $$f >> $@ ; \
-       done ; \
-       printf '};\n\n' >> $@ ; \
-       printf 'const struct icon_context action_icon_context = {\n' >> $@
-       printf '  action_icon_name,\n' >> $@
-       printf "  sizeof (action_icon_name) / sizeof (action_icon_name[0]),\n" >> $@ 
-       printf "  \"actions\"\n" >> $@
-       printf '};\n' >> $@ ; \
-       echo >> $@
-       printf 'static const char *category_icon_name[] =' >> $@
-       printf '\n{\n' >> $@
-       for i in $(CATEGORY_ICONS) ; do \
-        echo $$i; \
-       done | sed -e 's%[a-zA-Z/]*/[1-9]*x[1-9]*/\([^ ]*\)\.png%\1%g' | sort -u | while read f ; do \
-        printf '  "%s", \n' $$f >> $@ ; \
-       done ; \
-       printf '};\n\n' >> $@ ; \
-       printf 'const struct icon_context category_icon_context = {\n' >> $@
-       printf '  category_icon_name,\n' >> $@
-       printf "  sizeof (category_icon_name) / sizeof (category_icon_name[0]),\n" >> $@ 
-       printf "  \"categories\"\n" >> $@
-       printf '};\n' >> $@ ; \
-       echo >> $@
-
+       printf '#include "icon-names.h"\n\n' >> $@
+       build-aux/icon-list action actions $(ACTION_ICONS) >> $@
+       build-aux/icon-list category categories $(CATEGORY_ICONS) >> $@
 
 src/ui/gui/icons/manifest: $(MAKEFILE_LIST)
        $(RM) $@
index 06410885ac76234b42257d3e409134f5815fddf9..bfd8326ba36a89525a463a57d322e8a9353b4409 100644 (file)
@@ -1,3 +1,3 @@
 ## Process this file with automake to produce Makefile.in  -*- makefile -*-
 
-EXTRA_DIST += build-aux/svg2png
+EXTRA_DIST += build-aux/svg2png build-aux/icon-list
diff --git a/build-aux/icon-list b/build-aux/icon-list
new file mode 100644 (file)
index 0000000..3abeaa1
--- /dev/null
@@ -0,0 +1,30 @@
+#! /bin/sh
+
+id=$1
+name=$2
+shift; shift
+
+cat <<EOF
+static const char *${id}_icon_name[] =
+{
+EOF
+for i
+do
+    echo $i
+done \
+    | sed -e 's%[a-zA-Z/]*/[1-9]*x[1-9]*/\([^ ]*\)\.png%\1%g' \
+    | sort -u \
+    | while read f
+do
+    printf '  "%s", \n' $f
+done
+cat <<EOF
+};
+
+const struct icon_context ${id}_icon_context = {
+  ${id}_icon_name,
+  sizeof (${id}_icon_name) / sizeof (${id}_icon_name[0]),
+  "$name"
+};
+
+EOF