What's the best way to move a directory into place in a Makefile install?
I'm currently using the usual technique in my Makefile to install individual files:
install:
install -D executable ${BIN_DIR}
But I just ran across a situation where I need to move a whole directory and all files underneath it into place.
Is cp -r
the best way or is there a more linux-y/unix-y way to do this?
Yeah, it's hard to think of a more unix-ish way that cp -r
, although the -r is a relatively late addition to cp
. I can tell you the way we used to do it, and that works neatly across filesystems and such:
Let src
be the source directory you want to move, and /path/to/target
be an absolute path to the target. Then you can use:
$ tar cf - src | (cd /path/to/target; tar xf -)
My version of install(1)
(Debian) has:
-d, --directory
treat all arguments as directory names; create all components of the specified directories
-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
So if you wanted to use install(1)
consistently throughout your Makefile you could do:
install -d destdir
install srcdir/* -t destdir
-t
isn't recursive however - if srcdir
contains directories, then they won't get copied.
Linking is another viable alternative. That would allow you to keep multiple directories (representing different versions) accessible.
链接地址: http://www.djcxy.com/p/91630.html