Why $(INSTALL_BIN) and $(INSTALL_DATA) always remove softlink when installation files in Makefile

不羁的心 提交于 2021-01-28 13:35:40

问题


In OpenWrt package Makefile, at install section, the following code will remove the softlink from a lib* file and copy instance to $(1)

In Build/Compile Section, we built out 3 libs under ${PKG_BUILD_DIR}

${PKG_BUILD_DIR}/libapi.so          //  ->  libapi.so.1.0
${PKG_BUILD_DIR}/libapi.so.1.0      //  ->  libapi.so.1.0.1
${PKG_BUILD_DIR}/libapi.so.1.0.1

In Build/Installdev and Package/api/install Section, if $(INSTALL_BIN)/$(INSTALL_DATA) is used to copy these 3 libs from ${PKG_BUILD_DIR} to $(1)/usr/lib/, the softlik will be removed.

define Package/api/install
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/libapi.so  $(1)/usr/lib/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/libapi.so.1.0  $(1)/usr/lib/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/libapi.so.1.0.1  $(1)/usr/lib/
endef

The only way I have to use is $(CP) or "cp -f"

But I'm not sure that $(CP) will keep the -m0755 flags to these libs since I need the libs can be excutable on the target board.

define Package/api/install
    $(CP) $(PKG_BUILD_DIR)/libapi.so*  $(1)/usr/lib/
endef

How can let $(INSTALL_BIN) keeps softlink ?

Logs and varibales

INSTALL_BIN  = install -m0755
INSTALL_DATA = install -m0644
CP           = cp -fpR

回答1:


You are right that the install utility always dereferences symlinks (see this question).

To copy files while preserving everything (symlinks, hard links, mode, etc) you can use cp -a.

You can also use tar:

tar c -C source_dir file1 ... fileN | tar xv -C dest_dir

Be aware that both cp -a and tar will preserve user and group and that those files must probably be owned by root:root at the destination. You may have to add a chown afterwards.



来源:https://stackoverflow.com/questions/62713502/why-install-bin-and-install-data-always-remove-softlink-when-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!