summary refs log tree commit diff
path: root/pkgs/build-support/icon-conv-tools
diff options
context:
space:
mode:
authorjraygauthier <jraygauthier@users.noreply.github.com>2016-04-25 07:16:47 -0400
committerFranz Pletz <fpletz@fnordicwalking.de>2016-04-25 13:16:47 +0200
commitddc401ed0a8c768ee784aff3d50dc97f8ba8e279 (patch)
treecd9af50a93133d671bf857e435746f951b8d60b2 /pkgs/build-support/icon-conv-tools
parentd7e79dcacf06c0f6f14af8fdead4db74dd9a83af (diff)
downloadnixpkgs-ddc401ed0a8c768ee784aff3d50dc97f8ba8e279.tar
nixpkgs-ddc401ed0a8c768ee784aff3d50dc97f8ba8e279.tar.gz
nixpkgs-ddc401ed0a8c768ee784aff3d50dc97f8ba8e279.tar.bz2
nixpkgs-ddc401ed0a8c768ee784aff3d50dc97f8ba8e279.tar.lz
nixpkgs-ddc401ed0a8c768ee784aff3d50dc97f8ba8e279.tar.xz
nixpkgs-ddc401ed0a8c768ee784aff3d50dc97f8ba8e279.tar.zst
nixpkgs-ddc401ed0a8c768ee784aff3d50dc97f8ba8e279.zip
icon-conv-tools: init at 0.0.0 (#13905)
A nix specific set of tools for converting icon files
that are not in a freedesktop ready format.

I plan on using these tools for both `keepass` and
`retroarch` packages. It may benifit many other packages.
Diffstat (limited to 'pkgs/build-support/icon-conv-tools')
-rwxr-xr-xpkgs/build-support/icon-conv-tools/bin/extractWinRscIconsToStdFreeDesktopDir.sh74
-rwxr-xr-xpkgs/build-support/icon-conv-tools/bin/icoFileToHiColorTheme28
-rw-r--r--pkgs/build-support/icon-conv-tools/default.nix31
3 files changed, 133 insertions, 0 deletions
diff --git a/pkgs/build-support/icon-conv-tools/bin/extractWinRscIconsToStdFreeDesktopDir.sh b/pkgs/build-support/icon-conv-tools/bin/extractWinRscIconsToStdFreeDesktopDir.sh
new file mode 100755
index 00000000000..994adbd91da
--- /dev/null
+++ b/pkgs/build-support/icon-conv-tools/bin/extractWinRscIconsToStdFreeDesktopDir.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+# The file from which to extract *.ico files or a particular *.ico file.
+# (e.g.: './KeePass.exe', './myLibrary.dll', './my/path/to/app.ico'). 
+# As you notived, the utility can extract icons from a windows executable or
+# dll.
+rscFile=$1
+
+# A regexp that can extract the image size from the file name. Because we
+# use 'icotool', this value should usually be set to something like
+# '[^\.]+\.exe_[0-9]+_[0-9]+_[0-9]+_[0-9]+_([0-9]+x[0-9]+)x[0-9]+\.png'.
+# A reg expression may be written at some point that relegate this to
+# an implementation detail.
+sizeRegex=$2
+
+# A regexp replace expression that will be used with 'sizeRegex' to create
+# a proper size directory (e.g.: '48x48'). Usually this is left to '\1'.
+sizeReplaceExp=$3
+
+# A regexp that can extract the name of the target image from the file name
+# of the image (usually png) extracted from the *.ico file(s). A good
+# default is '([^\.]+).+' which gets the basename without extension.
+nameRegex=$4
+
+# A regexp replace expression that will be used alongside 'nameRegex' to create
+# a icon file name. Note that you usually put directly you icon name here
+# without any extension (e.g.: 'my-app'). But in case you've got something
+# fancy, it will usually be '\1'.
+nameReplaceExp=$5
+
+# The 
+# out=./myOut
+out=$6
+
+# An optional temp dir.
+if [ "" != "$7" ]; then
+  tmp=$7
+  isOwnerOfTmpDir=false
+else
+  tmp=`mktemp -d`
+  isOwnerOfTmpDir=true
+fi
+
+rm -rf $tmp/png $tmp/ico
+mkdir -p $tmp/png $tmp/ico
+
+# Extract the ressource file's extension.
+rscFileExt=`echo "$rscFile" | sed -re 's/.+\.(.+)$/\1/'`
+
+if [ "ico" = "$rscFileExt" ]; then
+  cp -p $rscFile $tmp/ico
+else
+  wrestool -x --output=$tmp/ico -t14 $rscFile
+fi
+    
+icotool --icon -x --palette-size=0 -o $tmp/png $tmp/ico/*.ico
+
+mkdir -p $out
+
+for i in $tmp/png/*.png; do
+  fn=`basename "$i"`
+  size=$(echo $fn | sed -re 's/'${sizeRegex}'/'${sizeReplaceExp}'/')
+  name=$(echo $fn | sed -re 's/'${nameRegex}'/'${nameReplaceExp}'/')
+  targetDir=$out/share/icons/hicolor/$size/apps
+  targetFile=$targetDir/$name.png
+  mkdir -p $targetDir
+  mv $i $targetFile
+done
+
+rm -rf "$tmp/png" "$tmp/ico"
+
+if $isOwnerOfTmpDir; then
+  rm -rf "$tmp"
+fi
diff --git a/pkgs/build-support/icon-conv-tools/bin/icoFileToHiColorTheme b/pkgs/build-support/icon-conv-tools/bin/icoFileToHiColorTheme
new file mode 100755
index 00000000000..192f3bb54c2
--- /dev/null
+++ b/pkgs/build-support/icon-conv-tools/bin/icoFileToHiColorTheme
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+SCRIPT_DIR=`cd "$(dirname $0)" && pwd`
+
+# The '*.ico' file that needs to be converted (e.g.: "./my/path/to/file.ico").
+icoFile="$1"
+
+# The desired name of created icon files without extension. (e.g.: "my-app").
+targetIconName="$2"
+
+# The output directory where the free desktop hierarchy will be created.
+# (e.g.: "./path/to/my/out" or usually in nix "$out"). Note that the
+# whole directory hierarchy to the icon will be created in the specified
+# output directory (e.g.: "$out/share/icons/hicolor/48x48/apps/my-app.png").
+out="$3"
+
+# An optional temp directory location (e.g.: ./tmp). If not specified
+# a random '/tmp' directory will be created.
+tmp="$4"
+
+$SCRIPT_DIR/extractWinRscIconsToStdFreeDesktopDir.sh \
+  "$icoFile" \
+  '[^\.]+_[0-9]+_([0-9]+x[0-9]+)x[0-9]+\.png' \
+  '\1' \
+  '([^\.]+).+' \
+  "$targetIconName" \
+  "$out" \
+  "$tmp"
diff --git a/pkgs/build-support/icon-conv-tools/default.nix b/pkgs/build-support/icon-conv-tools/default.nix
new file mode 100644
index 00000000000..739ec485159
--- /dev/null
+++ b/pkgs/build-support/icon-conv-tools/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, icoutils }:
+
+stdenv.mkDerivation {
+  name = "icon-conv-tools-0.0.0";
+
+  src = ./.;
+
+  buildInputs = [ icoutils ];
+
+  patchPhase = ''
+    substituteInPlace "./bin/extractWinRscIconsToStdFreeDesktopDir.sh" \
+      --replace "icotool" "${icoutils}/bin/icotool" \
+      --replace "wrestool" "${icoutils}/bin/wrestool"
+  '';
+
+  buildPhase = ''
+    mkdir -p "$out/bin"
+    cp -p "./bin/"* "$out/bin"
+  '';
+
+  installPhase = "true";
+  
+  dontPatchELF = true;
+  dontStrip = true;
+
+  meta = {
+    description = "Tools for icon conversion specific to nix package manager";
+    maintainers = with stdenv.lib.maintainers; [ jraygauthier ];
+  };
+
+}
\ No newline at end of file