如何在QT5的qmake中通过`make uninstall`运行自定义命令?

8

我有一个QT项目,运行make install时会将一个服务安装到系统中。以下是.pro文件的相关部分:

init.path = /etc/init.d/
init.files = myservicename

updaterc.path = /etc/init.d/
updaterc.extra = chmod 755 $$init.files; \
                 update-rc.d $$init.files defaults 97 03; \
                 service $$init.files start

INSTALLS += target ... init updaterc

这将正确安装服务并启动它。

然而,当我运行make uninstall时,虽然已安装的文件被正确删除,但服务仍然保留安装并运行。我希望在运行make uninstall时停止和卸载该服务。

停止和卸载服务的命令如下:

sudo service myservicename stop
sudo update-rc.d -f myservicename remove

但我不知道如何将上述命令集成到.pro文件中,以便qmake可以理解并在Makefile中创建相关规则。
我找到的唯一文档是这个:http://doc.qt.io/qt-5/qmake-advanced-usage.html,但它没有关于卸载的说明。
1个回答

8
尝试使用“.uninstall”命令。
mytarget2.path = ~/Documents/inst
mytarget2.target = test.txt
mytarget2.commands = @echo "custom command"
mytarget2.uninstall = @echo "uninstall" 
INSTALLS += mytarget2

它会生成这个makefile:

   ####### Install

install_mytarget2: first FORCE
    @test -d $(INSTALL_ROOT)/Users/mac/Documents/inst || mkdir -p $(INSTALL_ROOT)/Users/mac/Documents/inst
    @echo custom command

uninstall_mytarget2: FORCE
    @echo uninstall
    -$(DEL_DIR) $(INSTALL_ROOT)/Users/mac/Documents/inst/ 


install:  install_mytarget2  FORCE

uninstall: uninstall_mytarget2   FORCE

FORCE:

是的,“卸载”命令很有帮助,似乎解决了问题。我会等到悬赏结束,以防其他人有更好的想法,否则这个悬赏就归你了。非常感谢你的帮助。 - user000001

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接