suse-bzip2/Makefile: add Mac OS X support
authorTorsten Maehne <torsten.maehne@gmx.de>
Mon, 27 Aug 2012 09:28:30 +0000 (11:28 +0200)
committerJoey Hess <joey@kitenet.net>
Mon, 27 Aug 2012 15:35:07 +0000 (11:35 -0400)
This commit changes the  suse-bzip2 Makefile to compile a dynamic
libbz2.dylib on Mac OS X and ensures that zgz sets DYLD_LIBRARY_PATH
on Mac OS X to swap in a different library.

The suse-bzip2 Makefile was only able to handle the compilation of
shared object libraries like they are used on Linux. Mac OS X uses
dynamic libraries, which require different compiler and linker switches.

MacPorts checks all binaries installed by a port for broken linkage.
This requires that the install_name for libbz2 is set in the suse-bzip2
Makefile to its pristine-tar install location (based on PREFIX).

Signed-off-by: Philipp A. Hartmann <philipp.hartmann@offis.de>
(cherry picked from commit 295dda0608a979d11b7acfb565745b7f507a27a1)

.gitignore
pit/suse-bzip2/Makefile

index 75874f4d10046ad51862b31d5ca7e0419a241b44..dbad2106a107247a61ff28588814087149fe564e 100644 (file)
@@ -2,6 +2,7 @@
 *.sho
 *.so
 *.so.*
+*.dylib
 zgz/zgz
 pit/suse-bzip2/bzip2
 Makefile
index 49600373f73a3685694f66865ffed2cb60ee24f9..3e413197302b96cf972266c5aefd73adc08deb2a 100644 (file)
@@ -16,6 +16,10 @@ somajor=1.0
 sominor=$(somajor).4
 SHELL=/bin/sh
 
+# Determine the operating system name to decide whether to build a
+# shared object library libbz2.so or a dynamic library libbz2.dylib.
+UNAME_S := $(shell uname -s)
+
 # To assist in cross-compiling
 CC=gcc
 AR=ar
@@ -39,7 +43,20 @@ OBJS= blocksort.o  \
 
 all: libbz2.a bzip2
 
-bzip2: libbz2.so bzip2.o
+ifeq ("$(UNAME_S)","Darwin")
+soext=dylib
+soext_major=$(somajor).$(soext)
+soext_minor=$(sominor).$(soext)
+LDDLFLAGS=-dynamiclib \
+          -Wl,-headerpad_max_install_names,-undefined,dynamic_lookup,-compatibility_version,$(somajor),-current_version,$(sominor),-install_name,$(PREFIX)/lib/zgz/suse-bzip2/libbz2.$(soext_minor)
+else
+soext=so
+soext_major=$(soext).$(somajor)
+soext_minor=$(soext).$(sominor)
+LDDLFLAGS=-shared -Wl,-soname,libbz2.$(soext_major)
+endif
+
+bzip2: libbz2.$(soext) bzip2.o
        $(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
 
 bzip2recover: bzip2recover.o
@@ -54,15 +71,14 @@ libbz2.a: $(OBJS)
                $(RANLIB) libbz2.a ; \
        fi
 
-libbz2.so: libbz2.so.$(somajor)
-       ln -sf $^ $@
+libbz2.$(soext): libbz2.$(soext_major)
+       ln -sf $< $@
 
-libbz2.so.$(somajor): libbz2.so.$(sominor)
-       ln -sf $^ $@
+libbz2.$(soext_major): libbz2.$(soext_minor)
+       ln -sf $< $@
 
-libbz2.so.$(sominor): $(OBJS:%.o=%.sho)
-       $(CC) -o libbz2.so.$(sominor) -shared \
-         -Wl,-soname,libbz2.so.$(somajor) $^ -lc
+libbz2.$(soext_minor): $(OBJS:%.o=%.sho)
+       $(CC)  $(LDDLFLAGS) -o $@ $^ -lc
 
 %.sho: %.c
        $(CC) $(CFLAGS) -D_REENTRANT -fPIC -o $@ -c $<
@@ -71,19 +87,28 @@ libbz2.so.$(sominor): $(OBJS:%.o=%.sho)
        $(CC) $(CFLAGS) -D_REENTRANT -o $@ -c $<
 
 check: test
+
+ifeq ("${UNAME_S}", "Darwin")
+# On Mac OS X, $DYLD_LIBRARY_PATH needs to be set to test libbz2.dylib.
+LD_PATH_VAR=DYLD_LIBRARY_PATH
+else
+# On all other (Unix-like) systems, set $LD_LIBRARY_PATH to test libbz2.so.
+LD_PATH_VAR=LD_LIBRARY_PATH
+endif
+
 test: bzip2
        @cat words1
-       LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH \
+       $(LD_PATH_VAR)=.:$$$(LD_PATH_VAR) \
        ./bzip2 -1  < sample1.ref > sample1.rb2
-       LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH \
+       $(LD_PATH_VAR)=.:$$$(LD_PATH_VAR) \
        ./bzip2 -2  < sample2.ref > sample2.rb2
-       LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH \
+       $(LD_PATH_VAR)=.:$$$(LD_PATH_VAR) \
        ./bzip2 -3  < sample3.ref > sample3.rb2
-       LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH \
+       $(LD_PATH_VAR)=.:$$$(LD_PATH_VAR) \
        ./bzip2 -d  < sample1.bz2 > sample1.tst
-       LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH \
+       $(LD_PATH_VAR)=.:$$$(LD_PATH_VAR) \
        ./bzip2 -d  < sample2.bz2 > sample2.tst
-       LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH \
+       $(LD_PATH_VAR)=.:$$$(LD_PATH_VAR) \
        ./bzip2 -ds < sample3.bz2 > sample3.tst
        cmp sample1.bz2 sample1.rb2 
        cmp sample2.bz2 sample2.rb2
@@ -136,9 +161,10 @@ install: bzip2 bzip2recover libbz2.a
        echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1
 
 clean: 
-       rm -f *.o *.sho libbz2.a libbz2.so* bzip2 bzip2recover \
-       sample1.rb2 sample2.rb2 sample3.rb2 \
-       sample1.tst sample2.tst sample3.tst
+       rm -f *.o *.sho libbz2.a libbz2.so* libbz2.*.dylib \
+             bzip2 bzip2recover \
+             sample1.rb2 sample2.rb2 sample3.rb2 \
+             sample1.tst sample2.tst sample3.tst
 
 
 distclean: clean