简体   繁体   English

如何在Linux中的Makefile中创建目录链接?

[英]How to create link to directory in makefile in Linux?

I have makefile containing code below. 我的makefile包含下面的代码。

ddd :
    @mkdir -p /full/path_new/to/new_dir
    @ln -fs /full/path_old/to/old_dir/private /full/path_new/to/new_dir/private

Linux ln command creates link in both directory taget and parent. Linux ln命令在目录标记和父目录中创建链接。 It means I have: 这意味着我有:

/full/path_new/to/new_dir:
private -> /full/path_old/to/old_dir/private

but also old one gets link 但也有旧的链接

/full/path_old/to/old_dir/private
private -> /full/path_old/to/old_dir/private

It cause I have something like 因为我有类似的东西

/full/path_old/to/old_dir/private/private/private/private (...) endless

How should I use ln command to have link in new_dir only? 我应该如何使用ln命令在new_dir中仅具有链接?

You need to remove the existing link before you create it: 您需要先删除现有链接,然后再创建它:

ddd :
        @mkdir -p /full/path_new/to/new_dir
        @rm -f /full/path_new/to/new_dir/private
        @ln -fs /full/path_old/to/old_dir/private /full/path_new/to/new_dir/private

Assuming a clean slate, the proper way to do this would be to create a target which knows which dependency it is creating, and avoid creating it if it alread exists. 假设情况良好,执行此操作的正确方法是创建一个目标,该目标知道正在创建的依赖项,并避免创建已存在的依赖项。

ddd: /full/path_new/to/new_dir/private
/full/path_new/to/new_dir/private:
    mkdir -p /full/path_new/to/new_dir
    ln -s /full/path/to/old_dir/private /full/path_new/to/new_dir

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM