6

In linux the command install has these options (among others): (from the man page)

-d, --directory
          treat all arguments as directory names; create all components of the specified directories

-D     create all leading components of DEST except the last, then copy SOURCE to DEST

On the mac manage there is this option:

-d      Create directories.  Missing parent directories are created as required.

I am attempting to install a library using a makefile and am getting this error on the mac:

install: illegal option -- D

This is caused by the command install being used to copy a .h file. Would the -d option work the same? Or is there a way to do this that would work on both platforms?

2 Answers 2

5

The lowercase "d" should work. If it doesn't, you can install GNU install with Homebrew coreutils which will provide the "D" flag.

1

macOS lower-case -d is fairly different from Linux upper-case -D.

On Linux, you can do

install -D path/to/file.ext target/dir/file.ext

and it'll create target/dir if it doesn't exist yet and then copy path/to/file.ext into it.

On macOS, install -d path/to requires that path/to is a directory, and it'll create that directory and its parent directories. If you pass a path to a file like install -d my/file.ext, it'll complain install: my/file.ext exists but is not a directory. You can use install -d to create several directories in one invocation like install -d my/first/dir my/second/dir, and it'll create both directories. This is very different from install -D my/first/dir my/second/dir in Linux, where it'll copy my/first/dir to my/second/dir, creating parent directories as needed.

I think the portable (*) alternative to

install -D path/to/my/file.ext target/path/file.ext

is:

mkdir -p $(dirname target/path/file.ext)
install path/to/my/file.ext target/path/file.ext

*: On very very old operating systems, mkdir -p has bugs. That's why binutils et al use a script called mkinstalldirs instead of mkdir -p. I think nowadays mkdir -p is probably fine, but you can go looking ofr mkinstalldirs if you're curious.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .