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"
$libdir
to an absolute path instead of a relative one? – Chris Davies Jul 19 '18 at 23:16Makefile.orig
. The problem is, they take the two variablesprefix
andlibdir
and turn them into 4 or 5 different variables. I tried tosed
them out a couple of years ago but I managed to break one thing or another doing so. – Jul 19 '18 at 23:23./config
line did you use to generate theMakefile
? – Chris Davies Jul 20 '18 at 06:23$prefix
. – Jul 22 '18 at 04:08config
options are here. They areno-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
. – Jul 22 '18 at 04:23--libdir
or even stop providing it, and you'll get a sane build. No editing of theMakefile
required. – Chris Davies Jul 22 '18 at 12:48--libdir
is necessary. OpenSSL puts the libs in the wrong directory. It breaks configure of other programs, and the libraries cannot be found at the RPATH. For example on Solaris the 64-bit libraries will not be located at/usr/local/lib/64
. – Jul 22 '18 at 13:07lib/64
instead of/usr/local/lib/64
. Fix the cause rather than the symptom – Chris Davies Jul 22 '18 at 13:41$(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)
instead of$(LIBDIR)
or$(DESTDIR)$(LIBDIR)
. – Jul 22 '18 at 13:47