0

I have makefile containing code below.

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. 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?

  • As an aside, putting `@` on everything you do is insane. Run with `make -s` or specify `.SILENT: ddd` instead. – tripleee Jun 12 '15 at 15:05

2 Answers2

1

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
MadScientist
  • 92,819
  • 9
  • 109
  • 136
0

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
tripleee
  • 175,061
  • 34
  • 275
  • 318