سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

The above is excessively verbose. Here's a shorter version:

Register an uninstall-hook target, and then perform the necessary tasks, for removing the directories. In this example ${pkgdatadir} would expand to /usr/share/foo. The minus sign in front of rmdir tells make to ignore the return code (so that if the directory isn't empty, make won't fail) Note that the minus sign can be used in front of any make target command.

uninstall-hook:
    -rmdir ${pkgdatadir}/applications
    -rmdir ${pkgdatadir}

The uninstall-hook rule will be called after the uninstall target has run.

Here's more about the minus sign: What do @, - and + do as prefixes to recipe lines in Make?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top