Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ernstki/8b0ba78cce77a235e801703232602675 to your computer and use it in GitHub Desktop.

Select an option

Save ernstki/8b0ba78cce77a235e801703232602675 to your computer and use it in GitHub Desktop.
Makefile to assist in managing `/usr/local` with GNU Stow

GNU Stow doesn't like to replace (or remove) cache files like share/glib-2.0/gschemas.compiled and share/icons/hicolor/icon-theme.cache.

If another package installed those, but the package you're trying to stow has its own, you'll get an error like this:

$ sudo stow seahorse-41.0/
WARNING! stowing seahorse-41.0 would cause conflicts:
  * existing target is neither a link nor a directory: share/glib-2.0/schemas/gschemas.compiled
  * existing target is neither a link nor a directory: share/icons/hicolor/icon-theme.cache
All operations aborted.

If you try to stow -D a package you'd previously stowed, but another package replaced, say icon-theme.cache, you'll get an error like this:

$ sudo stow -D seahorse-41.0/
WARNING! unstowing seahorse-41.0 would cause conflicts:
  * existing target is neither a link nor a directory: share/icons/hicolor/icon-theme.cache
All operations aborted.

The Makefile below exists to finesse your way around this problem; store this in /usr/local/stow for convenience.

When stowing a new package that uses Glib, remove the existing cache files with make clear, then re-stow. If you need to un-stow a package and it complains, run make clear again. If you find that GLib schemata or icon caches are out of date, run make cache.

##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## License: Zero-Clause BSD - https://opensource.org/license/0bsd
## Source: https://gist.github.com/ernstki/8b0ba78cce77a235e801703232602675
##
TITLE = Stow cleanup tasks
help: # prints this help
@perl -e "$$AUTOGEN_HELP_PL" Makefile
clear: clear-schemas clear-icons # clear both GLib schema and hicolor icon caches
clear-schemas:
-sudo rm ../share/glib-2.0/schemas/gschemas.compiled
clear-icons:
-sudo rm ../share/icons/hicolor/icon-theme.cache
caches: cache
cache: cache-schemas cache-icons # fix both GLib schema and hicolor icon caches
# to fix errors like these:
# $ sudo stow seahorse-41.0/
# WARNING! stowing seahorse-41.0 would cause conflicts:
# * existing target is neither a link nor a directory: share/glib-2.0/schemas/gschemas.compiled
# * existing target is neither a link nor a directory: share/icons/hicolor/icon-theme.cache
# All operations aborted.
cache-schemas: # rebuild GLib 2.0 gschemas.compiled
cd ../share/glib-2.0/schemas && \
sudo glib-compile-schemas /usr/share/glib-2.0/schemas/
cache-icons: # rebuild hicolor icon-theme.cache
cd ../share/icons/hicolor && \
sudo gtk-update-icon-cache --ignore-theme-index .
##
## internals you can safely ignore
##
define AUTOGEN_HELP_PL
# line 39
if (-t 1) {
$$UL = "\e[0;4m"; $$BOLDBLUE = "\e[1m\e[1;34m"; $$RESET = "\e[0m";
}
$$max = 0;
@targets = ();
print "\n ", $$UL, "Makefile targets - $(TITLE)", $$RESET, "\n\n";
while (<>) {
push @targets, [$$1, $$2] if /^(\w.+):[^=].*#\s*(.*)/;
$$max = length($$1) if length($$1) > $$max;
}
foreach (@targets) {
printf " %smake %-$${max}s%s %s\n", $$BOLDBLUE, @$$_[0], $$RESET, @$$_[1];
}
print "\n";
endef
export AUTOGEN_HELP_PL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment