# Makefile.  Generated from Makefile.in by configure.
# ------------------------------------------------------------------
# This file is part of bzip2/libbzip2, a program and library for
# lossless, block-sorting data compression.
#
# bzip2/libbzip2 version 1.0.6 of 6 September 2010
# Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
#
# File: Makefile.in for autoconf configuration
# Contributed by Keith Marshall <keithmarshall@users.sourceforge.net>
#
# Please read the WARNING, DISCLAIMER and PATENTS sections in the 
# README file.
#
# This program is released under the terms of the license contained
# in the file LICENSE.
# ------------------------------------------------------------------

PACKAGE	   =	bzip2
VERSION	   =	1.0.6

# If building libbz2 as a shared library, we use these version tags,
SO_VER	   =	1
SO_AGE	   =    0
SO_REV	   =	6
#
# This yields a shared object library name below, following the
# normal naming rules -- most linux distributions patch Julian's
# original makefile to do something similar.
#
SO_MAJOR   :=   $(shell expr $(SO_VER) - $(SO_AGE))
SONAME	   =	libbz2.so.$(SO_MAJOR)
SOFULL     =    $(SONAME).$(SO_AGE).$(SO_REV)

# For MS-Windows hosts, Julian's original build strategy, (and that
# still adopted for building with MSVC), creates an unversioned DLL,
# exporting functions using the __stdcall (WINAPI) calling convention.
# Conversly, MinGW developers have chosen to sanitise the libbz2 ABI,
# avoiding the use of the __stdcall calling convention, in favour of
# the more GNU/Linux-alike __cdecl convention.
#
# To permit MinGW builds of libbz2.dll to co-exist, in the developer
# universe, with MSVC builds, the MinGW Project has specified a scheme
# for distribution of versioned DLLs, unambiguously named libbz2-N.dll,
# where N is an ABI version number, nominally computed as:
#
#   SO_VER - SO_AGE	(ignoring SO_REV)
#
# Unfortunately, at an early stage in the evolution of the MinGW
# versioned libbz2-N.dll, at a time when this version paradigm would
# have yielded N = 1, a libbz2-1.dll was released, which employed the
# __stdcall calling convention.  Thus, to avoid potential confusion
# with this early release, and specific to the case of libbz2-N.dll,
# the DLLVER for the __cdecl releases, as computed by the configure
# script will lead the nominal value by one, becoming effectively:
#
#   1 + SO_VER - SO_AGE
#
# Note that for cygwin, a similar scheme (SO_VER - SO_AGE) is used,
# but on that platform the extra +1 is not needed.
DLLVER	   =	1
DLLNAME    =    msys-bz2
LIBNAME    =    libbz2


# Shell used by make...
#
SHELL	   =	/bin/sh

# Where to find the sources...
#

srcdir	   =	.

# To assist in cross-compiling...
#
CC	   =	x86_64-pc-cygwin-gcc
AR	   =	x86_64-pc-cygwin-ar
RANLIB	   =	x86_64-pc-cygwin-ranlib
LN_S	   =	ln -s

OBJEXT	   =	o
EXEEXT	   =	.exe

BIGFILES   =	-D_FILE_OFFSET_BITS=64
CFLAGS	   =	-O2 -pedantic -fomit-frame-pointer -m64 $(BIGFILES)
LDFLAGS	   =	
ARFLAGS    =	cq

# Where you want it installed when you do 'make install'
#
PREFIX	   =	/usr

OBJS= blocksort.$(OBJEXT)  \
      huffman.$(OBJEXT)    \
      crctable.$(OBJEXT)   \
      randtable.$(OBJEXT)  \
      compress.$(OBJEXT)   \
      decompress.$(OBJEXT) \
      bzlib.$(OBJEXT)

# Default build goals...
#
all: all-libs bzip2$(EXEEXT) bzip2recover$(EXEEXT)
all-libs: libbz2.a 

bzip2$(EXEEXT): libbz2.a bzip2.$(OBJEXT)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ bzip2.$(OBJEXT) -L. -lbz2

bzip2recover$(EXEEXT): bzip2recover.$(OBJEXT)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

libbz2.a: $(OBJS)
	rm -f $@
	$(AR) $(ARFLAGS) $@ $(OBJS)
	$(RANLIB) $@

blocksort.$(OBJEXT): blocksort.c
	@cat ${srcdir}/words0
	$(CC) $(CFLAGS) -c -o $@ $^

%.$(OBJEXT): %.c
	$(CC) $(CFLAGS) -c -o$@ $<

# Building using a shared library, for dynamic linking on GNU/Linux...
# (Invoked when configured with `--enable-shared' for a non-Win32 host).
#
# This is incorporated from Julian's original Makefile-libbz2_so.
# It is reported to work successfully on x86-Linux (Red Hat 7.2), with
# gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98); YMMV.
#
# Please refer to README, for important information regarding building
# libbz2 as a shared library, in this manner.
#
PICFLAGS = -fpic -fPIC -Wall -Winline $(CFLAGS)

all-bzip2-shared: bzip2-shared$(EXEEXT)
bzip2-shared$(EXEEXT): bzip2.c $(SOFULL)
	$(CC) $(PICFLAGS) -o $@ $^
	
$(SOFULL): $(OBJS:.$(OBJEXT)=-pic.$(OBJEXT))
	$(CC) -shared -Wl,-soname -Wl,$(SONAME) -o $@ $^
	rm -f $(SONAME); $(LN_S) $@ $(SONAME)
	rm -f $(SONAME).$(SO_AGE); $(LN_S) $@ $(SONAME).$(SO_AGE)

%-pic.$(OBJEXT): %.c
	$(CC) $(PICFLAGS) -c -o $@ $<

# Building using a shared library, for dynamic linking on MS-Windows
# and cygwin...
# (Invoked when configured with `--enable-shared' for a Win32/cygwin host)

all-dll-shared: $(LIBNAME).dll.a

$(LIBNAME).dll.a: $(DLLNAME)-$(DLLVER).dll

$(DLLNAME)-$(DLLVER).dll: libbz2.def libbz2.a
	$(CC) -shared -o $@ $(LDFLAGS) -Wl,--out-implib=$(LIBNAME).dll.a $^

libbz2.def: libbz2.def.in
	sed -e s,%DLLNAME%,$(DLLNAME), -e s,%DLLVER%,$(DLLVER), $^ > $@

# Build validation...
#
check: test
test: bzip2$(EXEEXT)
	@cat ${srcdir}/words1
	./bzip2$(EXEEXT) -1  < ${srcdir}/sample1.ref > sample1.rb2
	./bzip2$(EXEEXT) -2  < ${srcdir}/sample2.ref > sample2.rb2
	./bzip2$(EXEEXT) -3  < ${srcdir}/sample3.ref > sample3.rb2
	./bzip2$(EXEEXT) -d  < ${srcdir}/sample1.bz2 > sample1.tst
	./bzip2$(EXEEXT) -d  < ${srcdir}/sample2.bz2 > sample2.tst
	./bzip2$(EXEEXT) -ds < ${srcdir}/sample3.bz2 > sample3.tst
	cmp ${srcdir}/sample1.bz2 sample1.rb2 
	cmp ${srcdir}/sample2.bz2 sample2.rb2
	cmp ${srcdir}/sample3.bz2 sample3.rb2
	cmp sample1.tst ${srcdir}/sample1.ref
	cmp sample2.tst ${srcdir}/sample2.ref
	cmp sample3.tst ${srcdir}/sample3.ref
	@cat ${srcdir}/words3

# GNU Standard Specifications for Installation Directories...
#
prefix = $(PREFIX)
exec_prefix = ${prefix}

bindir = ${exec_prefix}/bin
datarootdir = ${prefix}/share
includedir = ${prefix}/include
libdir = ${exec_prefix}/lib

# `man' Documentation Hierarchy, in Terms of GNU Standards...
#
# FIXME: Julian's original distribution wasn't fully compliant
# with current GNU Standards; to achieve compliance, we must use
# this autotool standard definition:
#
#   mandir = ${datarootdir}/man
#
# in place of:
#
#   mandir = $(PREFIX)/man
#
# which preserves Julian's original configuration.
#
mandir = $(PREFIX)/share/man
man1dir = ${mandir}/man1

# Installation...
#
FORCE:
${bindir} ${includedir} ${libdir} ${man1dir}: FORCE
	test -d $@ || mkdir -p $@

install: all ${bindir} ${includedir} ${libdir} ${man1dir}
	cp -f bzip2$(EXEEXT) ${bindir}/bzip2$(EXEEXT)
	cp -f bzip2$(EXEEXT) ${bindir}/bunzip2$(EXEEXT)
	cp -f bzip2$(EXEEXT) ${bindir}/bzcat$(EXEEXT)
	cp -f bzip2recover$(EXEEXT) ${bindir}/bzip2recover$(EXEEXT)
	if test -f $(DLLNAME)-$(DLLVER).dll; \
	then \
	  cp -f $(DLLNAME)-$(DLLVER).dll ${bindir}/$(DLLNAME)-$(DLLVER).dll; \
	  chmod a+rx ${bindir}/$(DLLNAME)-$(DLLVER).dll; \
	fi
	chmod a+x ${bindir}/bzip2$(EXEEXT)
	chmod a+x ${bindir}/bunzip2$(EXEEXT)
	chmod a+x ${bindir}/bzcat$(EXEEXT)
	chmod a+x ${bindir}/bzip2recover$(EXEEXT)
	cp -f ${srcdir}/bzlib.h ${includedir}
	chmod a+r ${includedir}/bzlib.h
	cp -f libbz2.a ${libdir}
	if test -f $(LIBNAME).dll.a; \
	then \
	  cp -f $(LIBNAME).dll.a ${libdir}/$(LIBNAME).dll.a; \
	  chmod a+r ${libdir}/$(LIBNAME).dll.a; \
	fi
	chmod a+r ${libdir}/libbz2.a
	if test -f $(SOFULL); \
	then \
	  cp -f $(SOFULL) ${libdir}; \
	  cd ${libdir}; rm -f $(SO_NAME).$(SO_AGE) $(SONAME); \
	  $(LN_S) $(SOFULL) $(SONAME).$(SO_AGE); \
	  $(LN_S) $(SOFULL) $(SONAME); \
	  chmod a+r $(SOFULL); \
	fi
	cp -f ${srcdir}/bzgrep ${bindir}/bzgrep
	cd ${bindir}; $(LN_S) -f bzgrep bzegrep
	cd ${bindir}; $(LN_S) -f bzgrep bzfgrep
	chmod a+x ${bindir}/bzgrep
	cp -f ${srcdir}/bzmore ${bindir}/bzmore
	cd ${bindir}; $(LN_S) -f bzmore bzless
	chmod a+x ${bindir}/bzmore
	cp -f ${srcdir}/bzdiff ${bindir}/bzdiff
	cd ${bindir}; $(LN_S) -f bzdiff bzcmp
	chmod a+x ${bindir}/bzdiff
	cd ${srcdir}; cp -f bzip2.1 bzgrep.1 bzmore.1 bzdiff.1 ${man1dir}
	chmod a+r ${man1dir}/bzip2.1
	chmod a+r ${man1dir}/bzgrep.1
	chmod a+r ${man1dir}/bzmore.1
	chmod a+r ${man1dir}/bzdiff.1
	echo ".so man1/bzgrep.1" > ${man1dir}/bzegrep.1
	echo ".so man1/bzgrep.1" > ${man1dir}/bzfgrep.1
	echo ".so man1/bzmore.1" > ${man1dir}/bzless.1
	echo ".so man1/bzdiff.1" > ${man1dir}/bzcmp.1

ldconfig:
	ldconfig -n ${libdir}

# Housekeeping...
#
clean: 
	cmp > /dev/null 2>&1 ${srcdir}/libbz2.def libbz2.def \
	  || rm -f libbz2.def
	rm -f *.$(OBJEXT) libbz2*.a $(DLLNAME)*.dll  \
	bzip2$(EXEEXT) bzip2recover$(EXEEXT) \
	sample1.rb2 sample2.rb2 sample3.rb2 \
	sample1.tst sample2.tst sample3.tst

distclean: clean
	rm -f config.status config.log Makefile

# NOTE: Julian's original Makefile had these in `distclean'.
# Since they are `distributables', that might have surprised
# users expecting GNU standard behaviour; they rightfully
# belong in `maintainer-clean'.
#
maintainer-clean: clean
	rm -f manual.ps manual.html manual.pdf

# Distribution...
#
DISTNAME = $(PACKAGE)-$(VERSION)
#
# FIXME: this method of creating a source distribution works fine
# on systems which fully support symbolic links between directories;
# it cannot be used reliably, on MS-Windows hosts running MSYS.
#
dist: manual
	rm -f $(DISTNAME) $(DISTNAME)$(SNAPSHOT).*
	$(LN_S) -f ${srcdir} $(DISTNAME)
	tar cvf $(DISTNAME)$(SNAPSHOT).tar \
	   $(DISTNAME)/aclocal.m4 \
	   $(DISTNAME)/configure \
	   $(DISTNAME)/configure.ac \
	   $(DISTNAME)/Makefile.in \
	   $(DISTNAME)/blocksort.c \
	   $(DISTNAME)/huffman.c \
	   $(DISTNAME)/crctable.c \
	   $(DISTNAME)/randtable.c \
	   $(DISTNAME)/compress.c \
	   $(DISTNAME)/decompress.c \
	   $(DISTNAME)/bzlib.c \
	   $(DISTNAME)/bzip2.c \
	   $(DISTNAME)/bzip2recover.c \
	   $(DISTNAME)/bzlib.h \
	   $(DISTNAME)/bzlib_private.h \
	   $(DISTNAME)/LICENSE \
	   $(DISTNAME)/bzip2.1 \
	   $(DISTNAME)/bzip2.1.preformatted \
	   $(DISTNAME)/bzip2.txt \
	   $(DISTNAME)/words0 \
	   $(DISTNAME)/words1 \
	   $(DISTNAME)/words2 \
	   $(DISTNAME)/words3 \
	   $(DISTNAME)/sample1.ref \
	   $(DISTNAME)/sample2.ref \
	   $(DISTNAME)/sample3.ref \
	   $(DISTNAME)/sample1.bz2 \
	   $(DISTNAME)/sample2.bz2 \
	   $(DISTNAME)/sample3.bz2 \
	   $(DISTNAME)/dlltest.c \
	   $(DISTNAME)/manual.html \
	   $(DISTNAME)/manual.pdf \
	   $(DISTNAME)/manual.ps \
	   $(DISTNAME)/README \
	   $(DISTNAME)/README.COMPILATION.PROBLEMS \
	   $(DISTNAME)/README.XML.STUFF \
	   $(DISTNAME)/CHANGES \
	   $(DISTNAME)/libbz2.def \
	   $(DISTNAME)/libbz2.def.in \
	   $(DISTNAME)/libbz2.dsp \
	   $(DISTNAME)/dlltest.dsp \
	   $(DISTNAME)/makefile.msc \
	   $(DISTNAME)/unzcrash.c \
	   $(DISTNAME)/spewG.c \
	   $(DISTNAME)/mk251.c \
	   $(DISTNAME)/bzdiff \
	   $(DISTNAME)/bzdiff.1 \
	   $(DISTNAME)/bzmore \
	   $(DISTNAME)/bzmore.1 \
	   $(DISTNAME)/bzgrep \
	   $(DISTNAME)/bzgrep.1 \
	   $(DISTNAME)/Makefile-libbz2_so \
	   $(DISTNAME)/bz-common.xsl \
	   $(DISTNAME)/bz-fo.xsl \
	   $(DISTNAME)/bz-html.xsl \
	   $(DISTNAME)/bzip.css \
	   $(DISTNAME)/entities.xml \
	   $(DISTNAME)/manual.xml \
	   $(DISTNAME)/format.pl \
	   $(DISTNAME)/xmlproc.sh
	gzip -v $(DISTNAME)$(SNAPSHOT).tar
	rm -f $(DISTNAME)

# For rebuilding the manual from sources on Julian's SuSE 9.1 box
#
MANUAL_SRCS  =  bz-common.xsl bz-fo.xsl bz-html.xsl bzip.css \
		entities.xml manual.xml 

manual: manual.html manual.ps manual.pdf

manual.ps: $(MANUAL_SRCS)
	${srcdir}/xmlproc.sh -ps manual.xml

manual.pdf: $(MANUAL_SRCS)
	${srcdir}/xmlproc.sh -pdf manual.xml

manual.html: $(MANUAL_SRCS)
	${srcdir}/xmlproc.sh -html manual.xml

# Makefile: end of file
