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.

authored by jraygauthier and committed by Franz Pletz ddc401ed d7e79dca

+135
+74
pkgs/build-support/icon-conv-tools/bin/extractWinRscIconsToStdFreeDesktopDir.sh
···
··· 1 + #!/bin/sh 2 + 3 + # The file from which to extract *.ico files or a particular *.ico file. 4 + # (e.g.: './KeePass.exe', './myLibrary.dll', './my/path/to/app.ico'). 5 + # As you notived, the utility can extract icons from a windows executable or 6 + # dll. 7 + rscFile=$1 8 + 9 + # A regexp that can extract the image size from the file name. Because we 10 + # use 'icotool', this value should usually be set to something like 11 + # '[^\.]+\.exe_[0-9]+_[0-9]+_[0-9]+_[0-9]+_([0-9]+x[0-9]+)x[0-9]+\.png'. 12 + # A reg expression may be written at some point that relegate this to 13 + # an implementation detail. 14 + sizeRegex=$2 15 + 16 + # A regexp replace expression that will be used with 'sizeRegex' to create 17 + # a proper size directory (e.g.: '48x48'). Usually this is left to '\1'. 18 + sizeReplaceExp=$3 19 + 20 + # A regexp that can extract the name of the target image from the file name 21 + # of the image (usually png) extracted from the *.ico file(s). A good 22 + # default is '([^\.]+).+' which gets the basename without extension. 23 + nameRegex=$4 24 + 25 + # A regexp replace expression that will be used alongside 'nameRegex' to create 26 + # a icon file name. Note that you usually put directly you icon name here 27 + # without any extension (e.g.: 'my-app'). But in case you've got something 28 + # fancy, it will usually be '\1'. 29 + nameReplaceExp=$5 30 + 31 + # The 32 + # out=./myOut 33 + out=$6 34 + 35 + # An optional temp dir. 36 + if [ "" != "$7" ]; then 37 + tmp=$7 38 + isOwnerOfTmpDir=false 39 + else 40 + tmp=`mktemp -d` 41 + isOwnerOfTmpDir=true 42 + fi 43 + 44 + rm -rf $tmp/png $tmp/ico 45 + mkdir -p $tmp/png $tmp/ico 46 + 47 + # Extract the ressource file's extension. 48 + rscFileExt=`echo "$rscFile" | sed -re 's/.+\.(.+)$/\1/'` 49 + 50 + if [ "ico" = "$rscFileExt" ]; then 51 + cp -p $rscFile $tmp/ico 52 + else 53 + wrestool -x --output=$tmp/ico -t14 $rscFile 54 + fi 55 + 56 + icotool --icon -x --palette-size=0 -o $tmp/png $tmp/ico/*.ico 57 + 58 + mkdir -p $out 59 + 60 + for i in $tmp/png/*.png; do 61 + fn=`basename "$i"` 62 + size=$(echo $fn | sed -re 's/'${sizeRegex}'/'${sizeReplaceExp}'/') 63 + name=$(echo $fn | sed -re 's/'${nameRegex}'/'${nameReplaceExp}'/') 64 + targetDir=$out/share/icons/hicolor/$size/apps 65 + targetFile=$targetDir/$name.png 66 + mkdir -p $targetDir 67 + mv $i $targetFile 68 + done 69 + 70 + rm -rf "$tmp/png" "$tmp/ico" 71 + 72 + if $isOwnerOfTmpDir; then 73 + rm -rf "$tmp" 74 + fi
+28
pkgs/build-support/icon-conv-tools/bin/icoFileToHiColorTheme
···
··· 1 + #!/bin/sh 2 + 3 + SCRIPT_DIR=`cd "$(dirname $0)" && pwd` 4 + 5 + # The '*.ico' file that needs to be converted (e.g.: "./my/path/to/file.ico"). 6 + icoFile="$1" 7 + 8 + # The desired name of created icon files without extension. (e.g.: "my-app"). 9 + targetIconName="$2" 10 + 11 + # The output directory where the free desktop hierarchy will be created. 12 + # (e.g.: "./path/to/my/out" or usually in nix "$out"). Note that the 13 + # whole directory hierarchy to the icon will be created in the specified 14 + # output directory (e.g.: "$out/share/icons/hicolor/48x48/apps/my-app.png"). 15 + out="$3" 16 + 17 + # An optional temp directory location (e.g.: ./tmp). If not specified 18 + # a random '/tmp' directory will be created. 19 + tmp="$4" 20 + 21 + $SCRIPT_DIR/extractWinRscIconsToStdFreeDesktopDir.sh \ 22 + "$icoFile" \ 23 + '[^\.]+_[0-9]+_([0-9]+x[0-9]+)x[0-9]+\.png' \ 24 + '\1' \ 25 + '([^\.]+).+' \ 26 + "$targetIconName" \ 27 + "$out" \ 28 + "$tmp"
+31
pkgs/build-support/icon-conv-tools/default.nix
···
··· 1 + { stdenv, icoutils }: 2 + 3 + stdenv.mkDerivation { 4 + name = "icon-conv-tools-0.0.0"; 5 + 6 + src = ./.; 7 + 8 + buildInputs = [ icoutils ]; 9 + 10 + patchPhase = '' 11 + substituteInPlace "./bin/extractWinRscIconsToStdFreeDesktopDir.sh" \ 12 + --replace "icotool" "${icoutils}/bin/icotool" \ 13 + --replace "wrestool" "${icoutils}/bin/wrestool" 14 + ''; 15 + 16 + buildPhase = '' 17 + mkdir -p "$out/bin" 18 + cp -p "./bin/"* "$out/bin" 19 + ''; 20 + 21 + installPhase = "true"; 22 + 23 + dontPatchELF = true; 24 + dontStrip = true; 25 + 26 + meta = { 27 + description = "Tools for icon conversion specific to nix package manager"; 28 + maintainers = with stdenv.lib.maintainers; [ jraygauthier ]; 29 + }; 30 + 31 + }
+2
pkgs/top-level/all-packages.nix
··· 328 329 useOldCXXAbi = makeSetupHook { } ../build-support/setup-hooks/use-old-cxx-abi.sh; 330 331 332 ### TOOLS 333
··· 328 329 useOldCXXAbi = makeSetupHook { } ../build-support/setup-hooks/use-old-cxx-abi.sh; 330 331 + iconConvTools = callPackage ../build-support/icon-conv-tools {}; 332 + 333 334 ### TOOLS 335