Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 270
Lolindrath Avatar asked Jan 06 '09 16:01

Lolindrath


People also ask

Can Makefile target be a directory?

Yes, a Makefile can have a directory as target. Your problem could be that the cd doesn't do what you want: it does cd and the git clone is carried out in the original directory (the one you cd ed from, not the one you cd ed to). This is because for every command in the Makefile an extra shell is created.

How do I change the installation directory in Linux?

The installation path is a standard location and cannot be changed. If you have another drive that has space, you can move any amount of your files to that drive by mounting your big directories at partitions on that drive (this is easiest to do when you are first installing Ubuntu).

How do I create a Makefile folder?

To use this makefile, simply cd to the directory and type “ makepp ”. Makepp will attempt to build the first target in the makefile, which is my_program . (If you don't want it to build the first target, then you have to supply a the name of the target you actually want to build on the command line.)

What the difference between make and install?

make follows the instructions of the Makefile and converts source code into binary for the computer to read. make install installs the program by copying the binaries into the correct places as defined by ./configure and the Makefile. Some Makefiles do extra cleaning and compiling in this step.


2 Answers

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 -)
like image 54
Charlie Martin Avatar answered Sep 21 '22 20:09

Charlie Martin


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.

like image 45
Martin Carpenter Avatar answered Sep 21 '22 20:09

Martin Carpenter