Fix IsPointInBox to work with wide as well as tall boxes
[geda-pcb/gde.git] / icon-theme-installer
blobe0708680cc25d89362e916448eb60c37cca1b93c
1 #!/bin/sh
3 # icon-theme-installer
4 # Copyright (C) 2006 Novell, Inc.
5 # Written by Aaron Bockover <abock@gnome.org>
6 # Licensed under the MIT/X11 license
8 # Modified by Peter Clifton to allow icons with numerals in the filename
10 # This script is meant to be invoked from within a Makefile/Makefile.am
11 # in the install-data-local and uninstall-data sections. It handles the
12 # task of properly installing icons into the icon theme. It requires a
13 # few arguments to set up its environment, and a list of files to be
14 # installed. The format of the file list is critical:
16 # <category>,<local-src-file-name>
18 # apps,music-player-banshee.svg
19 # apps,music-player-banshee-16.png
20 # apps,music-player-banshee-22.png
22 # <category> is the icon theme category, for instance, apps, devices,
23 # actions, emblems...
25 # <local-src-file-name> must have a basename in the form of:
27 # proper-theme-name[-<SIZE>].<EXTENSION>
29 # Where <SIZE> should be either nothing, which will default to scalable
30 # or \-[0-9]{2}, which will expand to <SIZE>x<SIZE>. For example:
32 # music-player-banshee-16.png
34 # The <SIZE> here is -16 and will expand to 16x16 per the icon theme spec
36 # What follows is an example Makefile.am for icon theme installation:
38 # ---------------
39 # theme=hicolor
40 # themedir=$(datadir)/icons/$(theme)
41 # theme_icons = \
42 # apps,music-player-banshee.svg \
43 # apps,music-player-banshee-16.png \
44 # apps,music-player-banshee-22.png \
45 # apps,music-player-banshee-24.png \
46 # apps,music-player-banshee-32.png
48 # install_icon_exec = $(top_srcdir)/build/icon-theme-installer -t $(theme) -s $(srcdir) -d "x$(DESTDIR)" -b $(themedir) -m "$(mkinstalldirs)" -x "$(INSTALL_DATA)"
49 # install-data-local:
50 # $(install_icon_exec) -i $(theme_icons)
52 # uninstall-hook:
53 # $(install_icon_exec) -u $(theme_icons)
55 # MAINTAINERCLEANFILES = Makefile.in
56 # EXTRA_DIST = $(wildcard *.svg *.png)
57 # ---------------
59 # Arguments to this program:
61 # -i : Install
62 # -u : Uninstall
63 # -t <theme> : Theme name (hicolor)
64 # -b <dir> : Theme installation dest directory [x$(DESTDIR)] - Always prefix
65 # this argument with x; it will be stripped but will act as a
66 # placeholder for zero $DESTDIRs (only set by packagers)
67 # -d <dir> : Theme installation directory [$(hicolordir)]
68 # -s <dir> : Source directory [$(srcdir)]
69 # -m <exec> : Command to exec for directory creation [$(mkinstalldirs)]
70 # -x <exec> : Command to exec for single file installation [$(INSTALL_DATA)]
71 # <remainging> : All remainging should be category,filename pairs
73 while getopts "iut:b:d:s:m:x:" flag; do
74 case "$flag" in
75 i) INSTALL=yes ;;
76 u) UNINSTALL=yes ;;
77 t) THEME_NAME=$OPTARG ;;
78 d) INSTALL_DEST_DIR="`echo $OPTARG | sed 's;^x;;'`" ;;
79 b) INSTALL_BASE_DIR=$OPTARG ;;
80 s) SRC_DIR=$OPTARG ;;
81 m) MKINSTALLDIRS_EXEC=$OPTARG ;;
82 x) INSTALL_DATA_EXEC=$OPTARG ;;
83 esac
84 done
86 shift `expr $OPTIND - 1`
88 if test "x$INSTALL" = "xyes" -a "x$UNINSTALL" = "xyes"; then
89 echo "Cannot pass both -i and -u"
90 exit 1
91 elif test "x$INSTALL" = "x" -a "x$UNINSTALL" = "x"; then
92 echo "Must path either -i or -u"
93 exit 1
96 if test -z "$THEME_NAME"; then
97 echo "Theme name required (-t hicolor)"
98 exit 1
101 if test -z "$INSTALL_BASE_DIR"; then
102 echo "Base theme directory required [-d \$(hicolordir)]"
103 exit 1
106 if test ! -x `echo "$MKINSTALLDIRS_EXEC" | cut -f1 -d' '`; then
107 echo "Cannot find '$MKINSTALLDIRS_EXEC'; You probably want to pass -m \$(mkinstalldirs)"
108 exit 1
111 if test ! -x `echo "$INSTALL_DATA_EXEC" | cut -f1 -d' '`; then
112 echo "Cannot find '$INSTALL_DATA_EXEC'; You probably want to pass -x \$(INSTALL_DATA)"
113 exit 1
116 if test -z "$SRC_DIR"; then
117 SRC_DIR=.
120 for icon in $@; do
121 size=`echo $icon | sed -n 's/.*-\([0-9]*\).*/\1/p'`
122 category=`echo $icon | cut -d, -f1`
123 build_name=`echo $icon | cut -d, -f2`
124 install_name=`echo $build_name | sed 's/-[0-9]\+//g'`
125 install_name=`basename $install_name`
127 if test -z $size; then
128 size=scalable;
129 else
130 size=${size}x${size};
133 install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$size/$category
134 install_path=$install_dir/$install_name
136 if test "x$INSTALL" = "xyes"; then
137 echo "Installing $size $install_name into $THEME_NAME icon theme"
139 $MKINSTALLDIRS_EXEC $install_dir || {
140 echo "Failed to create directory $install_dir"
141 exit 1
144 $INSTALL_DATA_EXEC $SRC_DIR/$build_name $install_path || {
145 echo "Failed to install $SRC_DIR/$build_name into $install_path"
146 exit 1
149 if test ! -e $install_path; then
150 echo "Failed to install $SRC_DIR/$build_name into $install_path"
151 exit 1
153 else
154 if test -e $install_path; then
155 echo "Removing $size $install_name from $THEME_NAME icon theme"
157 rm $install_path || {
158 echo "Failed to remove $install_path"
159 exit 1
163 done
165 if test "x$INSTALL" = "xyes"; then
166 gtk_update_icon_cache_bin="`(which gtk-update-icon-cache || echo /opt/gnome/bin/gtk-update-icon-cache)2>/dev/null`"
167 gtk_update_icon_cache_bin="${GTK_UPDATE_ICON_CACHE_BIN:-$gtk_update_icon_cache_bin}"
169 gtk_update_icon_cache="$gtk_update_icon_cache_bin -f -t $INSTALL_BASE_DIR"
171 if test -z "$INSTALL_DEST_DIR"; then
172 if test -x $gtk_update_icon_cache_bin; then
173 echo "Updating GTK icon cache"
174 $gtk_update_icon_cache
175 else
176 echo "*** Icon cache not updated. Could not execute $gtk_update_icon_cache_bin"
178 else
179 echo "*** Icon cache not updated. After install, run this:"
180 echo "*** $gtk_update_icon_cache"