Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get 'make uninstall' to remove empty directories as well as files?

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?

like image 601
lanoxx Avatar asked Oct 22 '13 14:10

lanoxx


People also ask

How do you remove multiple empty directories?

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.

What allows you to delete empty directories?

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.

Does rmdir only remove empty directories?

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.

How do I delete multiple empty directories in Linux?

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.


1 Answers

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.

like image 52
lanoxx Avatar answered Oct 03 '22 08:10

lanoxx