When I uninstall an application using make uninstall
it leaves over some empty directories which make install
had created, e.g. such as /usr/share/foo/
and its subdirectories such as /usr/share/foo/applications
, etc.
I found via Google, that automake's generated uninstall
target does not automatically delete empty directories because it does not know if the the application owns the directories (e.g. it created it during make install
), or borrowed it (e.g. the directory existed during make install
).
Currently none of my make files has a definitive uninstall
target, make implicitly seems to know which files it has to remove. How can I teach it to also remove the folders in question?
Delete Empty Files in a Directory First, search all the empty files in the given directory and then, delete all those files. This particular part of the command, find . -type f -empty -print, will find all the empty files in the given directory recursively. Then, we add the -delete option to delete all those files.
rmdir is a command-line utility for deleting empty directories. It is useful when you want to delete a directory only if it is empty, without needing to check whether the directory is empty or not.
There are two ways to remove directories in Linux: the rm and rmdir commands. The TL;DR of both commands is that rm deletes directories that may contain content such as files and subdirectories, while rmdir ONLY deletes empty directories.
The rm command in Linux removes files and directories. Note: To remove multiple files or directories using the rm command, add multiple file or directory names, separated by blank spaces. The different rm command options include: - f : Forces the removal of all files or directories.
Here is the solution, I just had to register an uninstall-hook
target like this, and then perform the necessary tasks, for removing the directories. In this example ${pkgdatadir}
would expand to /usr/share/foo
. The if-then is necesseary as otherwise the make distcheck
target would fail.
uninstall-hook:
if test -d ${pkgdatadir}/applications; then rmdir ${pkgdatadir}/applications; fi
if test -d ${pkgdatadir}; then rmdir ${pkgdatadir}; fi
The uninstall-hook
rule will be called after the uninstall target has run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With