# vim: ft=make ts=4 sw=4 noet
.DEFAULT_GOAL := all
NAME    = bzip2
VERSION = 1.0.8
GARTYPE = v2

MASTER_SITES = https://sourceware.org/pub/bzip2/
DISTFILES   += $(DISTNAME).tar.gz
LICENSE = LICENSE

PACKAGES             += OZSWbzip2
SPKG_DESC_OZSWbzip2   = bzip2 compression utility and library
CATALOGNAME_OZSWbzip2 = bzip2

# bzip2 has no autoconf configure
CONFIGURE_SCRIPTS =

# bzip2 Makefile uses PREFIX= directly; patch in DESTDIR support.
# Build with -fPIC so objects can be used for both static and shared library.
BUILD_OVERRIDE_VARS   += PREFIX CFLAGS
BUILD_OVERRIDE_VAR_PREFIX = $(prefix)
BUILD_OVERRIDE_VAR_CFLAGS = $(CFLAGS) -fPIC

INSTALL_OVERRIDE_VARS   += PREFIX
INSTALL_OVERRIDE_VAR_PREFIX = $(prefix)

# Keep libbz2.a alongside the shared lib
MERGE_EXCLUDE_STATICLIBS =

post-extract:
	gsed -i 's|/man/|/share/man/|g' $(WORKSRC)/Makefile
	gsed -i 's|$$(PREFIX)/|$$(DESTDIR)$$(PREFIX)/|g' $(WORKSRC)/Makefile
	@$(MAKECOOKIE)

post-configure:
	@$(MAKECOOKIE)

post-build:
	$(MAKE) -C $(WORKSRC) -f Makefile-libbz2_so \
	    CC="$(CC)" CCFLAGS="$(CFLAGS) -fPIC"
	@$(MAKECOOKIE)

post-install:
	install -m 755 $(WORKSRC)/libbz2.so.$(VERSION) $(DESTDIR)$(libdir)/libbz2.so.$(VERSION)
	ln -sf libbz2.so.$(VERSION) $(DESTDIR)$(libdir)/libbz2.so.1.0
	ln -sf libbz2.so.$(VERSION) $(DESTDIR)$(libdir)/libbz2.so
	@$(MAKECOOKIE)

include gar/category.mk
