1

This question already has an answer here:

I'm trying to work around a makefile issue where libraries are installed in the wrong place. Someone else wrote the makefile and it is not easy to fix. I'm trying to move the libraries after they have been installed. The installation includes permissions, symlinks on the BSDs, Linux and Solaris.

Given a prefix of /usr/local and libdir of /usr/local/lib/64/, the makefile is placing artifacts with libdir under prefix instead of treating libdir as an absolute path. Here's part of the copying that goes on:

cp libcrypto.pc /usr/local//usr/local/lib/64/pkgconfig
chmod 644 /usr/local//usr/local/lib/64/pkgconfig/libcrypto.pc
cp libssl.pc /usr/local//usr/local/lib/64/pkgconfig
chmod 644 /usr/local//usr/local/lib/64/pkgconfig/libssl.pc
cp openssl.pc /usr/local//usr/local/lib/64/pkgconfig
chmod 644 /usr/local//usr/local/lib/64/pkgconfig/openssl.pc

I thought it would be relatively easy to take /usr/local//usr/local/* and move the entire artifact tree to /usr/local but it is turning out to be trickier than I thought.

I've tried several suggestions to move the directory, including How to move all files and folders via mv command and Move files and folders recursively on Linux. Each has suffered small problems, like relocating to /usr/local/lib/64/64/pkgconfig/openssl.pc and not preserving symlinks.

Looking at the Linux mv(1) man page I'm not even sure there are any guarantees on preserving permission and symlinks present in a directory. The Posix mv command talks a little about permissions but it is in the context of writing to the destination directory.

I also tried stripping path components with ${filename:$prefix} but it caused problems with symlinks. ${filename:$prefix} is probably not Posix but I do have Bash.

My question is, is it even possible to do it portably on the BSDs, Linux, OS X and Solaris? If so, then how should I be doing it?


Here's the code I have cobbled together but it feels like it is wrong:

# Fix OpenSSL's broken directory structure
path="$PREFIX/$LIBDIR"
while [ $(echo "$path" | cut -c1-3) != "lib" ]
do
    echo "PATH: $path"
    path=${path#*/}
done
echo "PATH: $path"

Here is the output:

PATH: /usr/local//usr/local/lib/64
PATH: usr/local//usr/local/lib/64
PATH: local//usr/local/lib/64
PATH: /usr/local/lib/64
PATH: usr/local/lib/64
PATH: local/lib/64
PATH: lib/64

Followed by:

cd "$PREFIX/$PREFIX"
mv "$path" "$PREFIX"
rm -rf "$PREFIX/$PREFIX"

marked as duplicate by user56041, Community Jul 22 '18 at 4:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It may be easier to fix the broken Makefile. What sets $libdir to an absolute path instead of a relative one? – roaima Jul 19 '18 at 23:16
  • @roaima - OpenSSL uses a template file called Makefile.orig. The problem is, they take the two variables prefix and libdir and turn them into 4 or 5 different variables. I tried to sed them out a couple of years ago but I managed to break one thing or another doing so. – user56041 Jul 19 '18 at 23:23
  • What ./config line did you use to generate the Makefile? – roaima Jul 20 '18 at 6:23
  • Thanks @roaima - I took your suggestion and revistied patching the makefile. It was easier to patch this time so I took that route. Also see Fix OpenSSL library paths. OpenSSL is the only project I know that forces folks to put the libraries under $prefix. – user56041 Jul 22 '18 at 4:08
  • @roaima - To answer your question the config options are here. They are no-ssl2 no-ssl3 no-comp shared -DNDEBUG enable-ec_nistp_64_gcc_128 --prefix="/usr/local" --libdir="/usr/local/lib/64" -Wl,-L/usr/local/lib64 -m64 -Wl,-R,/usr/local/lib64 -Wl,--enable-new-dtags. – user56041 Jul 22 '18 at 4:23
2

I think my suggestion would be to leave it in place and just create a link in /usr/local/lib/ that links to this directory /usr/local/lib/64/.

For example:

$ tree usr/
usr/
└── local
    ├── lib
    │   └── 64 -> ../usr/local/lib/64
    └── usr
        └── local
            └── lib
                └── 64
                    └── pkgconfig

I made it like this:

$ cd /usr/local/lib/
$ ln -s ../usr/local/lib/64 64

This somewhat normalizes the tree so this works:

$ ls usr/local/lib/64/
pkgconfig
  • This is the problem I am hitting now: Merging folders with mv? It looks like @gjs has an insightful solution. I wish OpenSSL would do this stuff correctly from the start. It would save so many man-hours later. – user56041 Jul 19 '18 at 22:46
  • @jww I had that favorited and upvoted 😀 – slm Jul 19 '18 at 22:57
  • 1
    I closed this question as a dup of the answer in Merging folders with mv? I ended up going back to Makefile patching because I could not get the tar trick to work with sudo. Thanks again for your help. – user56041 Jul 22 '18 at 4:12
  • @jww - sure thing, thanks for letting me know. – slm Jul 22 '18 at 4:14