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.