1

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"
  • It may be easier to fix the broken Makefile. What sets $libdir to an absolute path instead of a relative one? – Chris Davies 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. –  Jul 19 '18 at 23:23
  • What ./config line did you use to generate the Makefile? – Chris Davies Jul 20 '18 at 06: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. –  Jul 22 '18 at 04: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. –  Jul 22 '18 at 04:23
  • Change the --libdir or even stop providing it, and you'll get a sane build. No editing of the Makefile required. – Chris Davies Jul 22 '18 at 12:48
  • Thanks @roaima. I believe --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:07
  • Libdir is relative to prefix, so set it to lib/64 instead of /usr/local/lib/64. Fix the cause rather than the symptom – Chris Davies Jul 22 '18 at 13:41
  • @roaima - I'm trying to fix the cause. The cause is the broken makefile that uses $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR) instead of $(LIBDIR) or $(DESTDIR)$(LIBDIR). –  Jul 22 '18 at 13:47

1 Answers1

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
slm
  • 369,824