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"