Building and Installing BZip2 with shared library dylib on MacOS

Viewed 428

'Trying to build/install BZip2 on MacOS (10.13.4 - High Sierra), but all the instructions I've been able to find [including from the README] have me at the following:

wget -c https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
tar -zxf bzip2-1.0.8.tar.gz
cd bzip2-1.0.8
sudo make install PREFIX=/usr/local

This installs the package without the shared library file with .dylib extension in the ./lib directory. The included instructions in the package are for Linux environment.

How do I install the shared libraries?

1 Answers

It turns out that doing this requires an update to the Makefile.

The package [bzip2 v1.0.8] comes with a Makefile-libbz2_so file that is for creating shared library files for Linux. To do same for MacOS a seperate Makefile is required.

Below are the updated instructions which worked. Follow the link for Makefile-libbz2_dylib for contents of the Makefile.

# Download BZip2
wget -c https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz

# Extract and enter directory
tar -zxf bzip2-1.0.8.tar.gz
cd bzip2-1.0.8

# create variable
export PREFIX="/usr/local"

# install - change PREFIX is required
sudo make install PREFIX=$PREFIX

# Make dynamic libraries for MACOS
wget -c https://gist.githubusercontent.com/obihill/3278c17bcee41c0c8b59a41ada8c0d35/raw/3bf890e2ad40d0af358e153395c228326f0b44d5/Makefile-libbz2_dylib
make -f Makefile-libbz2_dylib

# Do below only if your PREFIX is not /usr/local
# Create symlinks for bin
sudo ln -s $PREFIX/bin/bunzip2 /usr/local/bin/
sudo ln -s $PREFIX/bin/bzcat /usr/local/bin/
sudo ln -s $PREFIX/bin/bzcmp /usr/local/bin/
sudo ln -s $PREFIX/bin/bzdiff /usr/local/bin/
sudo ln -s $PREFIX/bin/bzegrep /usr/local/bin/
sudo ln -s $PREFIX/bin/bzfgrep /usr/local/bin/
sudo ln -s $PREFIX/bin/bzgrep /usr/local/bin/
sudo ln -s $PREFIX/bin/bzip2 /usr/local/bin/
sudo ln -s $PREFIX/bin/bzip2recover /usr/local/bin/
sudo ln -s $PREFIX/bin/bzless /usr/local/bin/
sudo ln -s $PREFIX/bin/bzmore /usr/local/bin/

# Create symlinks for lib
sudo ln -s $PREFIX/lib/libbz2.a /usr/local/lib/
sudo ln -s $PREFIX/lib/libbz2.dylib /usr/local/lib/

# Create symlinks for include
sudo ln -s $PREFIX/include/bzlib.h /usr/local/include/

If you don't have wget on your Mac, you can find instructions to set it up on this community post.

Inspiration for Makefile from here and here.

Related