【问题标题】:How can I get 'make uninstall' to remove empty directories as well as files?如何获得“make uninstall”以删除空目录和文件?
【发布时间】:2013-10-31 12:40:16
【问题描述】:

当我使用make uninstall 卸载应用程序时,它会留下一些由make install 创建的空目录,例如如/usr/share/foo/及其子目录如/usr/share/foo/applications

我通过 Google 发现,automake 生成的 uninstall 目标不会自动删除空目录,因为它不知道应用程序是否拥有这些目录(例如,它在 make install 期间创建了它) ,或借用它(例如,该目录在make install 期间存在)。

目前我的 make 文件都没有明确的uninstall 目标,make 似乎隐含地知道它必须删除哪些文件。我怎样才能教它也删除有问题的文件夹?

【问题讨论】:

    标签: uninstallation automake


    【解决方案1】:

    这是解决方案,我只需要像这样注册一个uninstall-hook 目标,然后执行必要的任务来删除目录。在此示例中,${pkgdatadir} 将扩展为 /usr/share/foo。 if-then 是必要的,否则 make distcheck 目标将失败。

    uninstall-hook:
        if test -d ${pkgdatadir}/applications; then rmdir ${pkgdatadir}/applications; fi
        if test -d ${pkgdatadir}; then rmdir ${pkgdatadir}; fi
    

    卸载目标运行后将调用uninstall-hook 规则。

    【讨论】:

    • 不清楚您在哪里注册了卸载挂钩。您是否将此段附加到 Makefile 中?请详细说明...
    • 添加到我的Makefile.am文件中,位置无所谓,在最后的某处添加即可。
    • 我相信这些应该是$(DESTDIR)$(pkgdatadir) 等。我怀疑当 DESTDIR 为非空时此解决方案将不起作用。
    【解决方案2】:

    以上内容过于冗长。这是一个较短的版本:

    注册一个卸载挂钩目标,然后执行必要的任务,以删除目录。在此示例中,${pkgdatadir} 将扩展为 /usr/share/foo。 rmdir前面的减号告诉make忽略返回码(这样如果目录不为空,make就不会失败)注意,减号可以用在任何make target命令的前面。

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

    卸载目标运行后将调用uninstall-hook 规则。

    这里有更多关于减号的信息:What do @, - and + do as prefixes to recipe lines in Make?

    【讨论】:

    • 原谅我的无知...这是configure.acMakefile.am吗?
    • 进入Makefile.am
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 2020-02-04
    • 2015-11-05
    • 1970-01-01
    • 2010-12-11
    • 2021-01-06
    相关资源
    最近更新 更多