# file: Makefile	G. Moody	5 September 1990
#			Last revised:   28 February 2001     Version 10.1.6
# UNIX 'make' description file for the WFDB software package
#
# -----------------------------------------------------------------------------
# WFDB software for creating & using annotated waveform (time series) databases
# Copyright (C) 2001 George B. Moody
#
# These programs are free software; you can redistribute them and/or modify
# them under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# These programs are distributed in the hope that they will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# these programs; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# In addition, you can redistribute and/or modify the WFDB library (contained
# within the 'lib' directory) under the terms of the GNU Library General
# Public License as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.  For details, see
# 'lib/COPYING.LIB'.
#
# You may contact the author by e-mail (george@mit.edu) or postal mail
# (MIT Room E25-505A, Cambridge, MA 02139 USA).  For updates to this software,
# please visit PhysioNet (http://www.physionet.org/).
# _____________________________________________________________________________
#
# This file is used with the UNIX `make' command to compile, install, and
# create archives of the WFDB software package.  Before using it
# for the first time, check that the site-specific variables below are
# appropriate for your system.  To compile the package, just type `make' (from
# within this directory).  To install the package, type `make install'.  To
# create source archives, type `make tarballs';  or to make a binary archive,
# type `make bin-tarball'.  Making archives requires PGP, gzip, and GNU tar).
# file: version.def		G. Moody	24 May 2000
#				Last revised: 26 October 2002
# Each release of the WFDB Software Package is identified by a three-part
# version number, defined here:
MAJOR = 10
MINOR = 2
RELEASE = 9
VERSION = $(MAJOR).$(MINOR).$(RELEASE)

# RPMRELEASE can be incremented if changes are made between official
# releases.  It should be reset to 1 whenever the VERSION is changed.
RPMRELEASE = 1

# VDEFS is the set of C compiler options needed to set version number variables
# while compiling the WFDB Software Package.
VDEFS = -DWFDB_MAJOR=$(MAJOR) -DWFDB_MINOR=$(MINOR) -DWFDB_RELEASE=$(RELEASE)

# WAVEVERSION is the WAVE version number.
WAVEVERSION = 6.5
# _____________________________________________________________________________

# Definitions generated by 'configure'

PACKAGE = wfdb-10.2.9
LONGDATE = 27 October 2002
SHORTDATE = OCTOBER 2002
# _____________________________________________________________________________

# file: linux.def		G. Moody	31 May 2000
#				Last revised: 17 December 2001
# 'make' definitions for compiling the WFDB Software Package under Linux

# Choose a value for WFDBROOT to determine where the WFDB Software Package will
# be installed.  One of the following is usually a reasonable choice.
# Installing in /usr generally requires root permissions, but will be easiest
# for future software development (no special -I or -L options will be needed
# to compile software with the WFDB library, since the *.h files and the
# library will be installed in the standard directories).
WFDBROOT = /usr
# Installing in /usr/local usually requires root permissions.  On a multi-user
# system where it is desirable to keep the OS vendor's software separate from
# other software, this is a good choice.  Another common choice in such cases
# is /opt .
# WFDBROOT = /usr/local
# To install without root permissions, a good choice is to set WFDBROOT to the
# name of your home directory, as in the example below (change as needed).
# WFDBROOT = /home/frodo

# If the W3C's libwww library of HTTP and FTP client code is available, and
# you wish to compile a WFDB library with NETFILES support, set LWC to
# 'libwww-config' (a utility supplied with libwww).  Otherwise set LWC to ':'
# (a program that does nothing, successfully).
LWC = libwww-config

# LDLIBWWW, which is appended to LDFLAGS below, is the set of options needed
# to link with libwww.  If libwww is not installed, or if libwfdb is a shared
# library, LDLIBWWW can be empty (if there is a '#' immediately after the '='
# below, the remainder of the line is ignored, so LDLIBWWW is empty in this
# case).  Otherwise, it is generated from the output of LWC.  Note that up to
# three passes through the option list are necessary to satisfy all
# dependencies when linking to the static libwww libraries.
LDLIBWWW = # `$(LWC) --libs` `$(LWC) --libs` `$(LWC) --libs`

# BINDIR specifies the directory in which the applications will be installed;
# it should be a directory in the PATH of those who will use the applications.
BINDIR = $(WFDBROOT)/bin

# DBDIR specifies the name of a directory in which to install the contents
# of the `data' directory.
DBDIR = $(WFDBROOT)/database

# INCDIR specifies the name of a directory in which to install the WFDB
# library's #include <...> files.
INCDIR = $(WFDBROOT)/include

# INFODIR is the GNU info directory (optional, needed to `make info').
INFODIR = /usr/share/info

# LIBDIR specifies the name of a directory in which to install the WFDB
# library.
LIBDIR = $(WFDBROOT)/lib

# PSPDIR specifies the name of a directory in which to install the PostScript
# prolog (*.pro) files from the 'app' directory.
PSPDIR = $(WFDBROOT)/lib/ps

# CC is the name of your C compiler.
CC = gcc

# CCDEFS is the set of C compiler options needed to set preprocessor variables
# while compiling the WFDB Software Package.  CCDEFS should always include
# VDEFS.
CCDEFS = $(VDEFS)

# CFLAGS is the set of C compiler options.  CFLAGS should always include
# CCDEFS.
CFLAGS = -g -O $(CCDEFS) `$(LWC) --cflags` -I$(INCDIR)

# LDFLAGS is appended to the C compiler command line to specify loading the
# WFDB library.
LDFLAGS = -L$(LIBDIR) -lwfdb $(LDLIBWWW)

# WFDBLIB is the name of the standard WFDB library.  In order to access it via
# `-lwfdb', WFDBLIB should be `libwfdb.a'.
WFDBLIB = libwfdb.a

# BUILDLIB is the command that creates the static WFDB library once its
# components have been compiled separately;  the list of *.o files that
# make up the library will be appended to BUILDLIB.
BUILDLIB = $(AR) $(ARFLAGS) $(WFDBLIB)

# PRINT is the name of the program used to produce listings (including any
# options for the desired formatting).
PRINT = lpr

# SETPERMISSIONS is the command needed to make the installed files accessible
# to those who will use them.  The value given below makes them readable by
# everyone, and writeable by the owner only.  (If you perform the installation
# as `root', `root' is the owner of the installed files.)
SETPERMISSIONS = chmod 644

# SETDPERMISSIONS is similarly used to make directories created during the
# installation accessible.
SETDPERMISSIONS = chmod 755

# SETLPERMISSIONS is the command needed to make the WFDB library usable by
# programs linked to it.
SETLPERMISSIONS = chmod 644

# SETXPERMISSIONS is the command needed to make the applications accessible.
SETXPERMISSIONS = chmod 755

# STRIP is the command used to compact the compiled binaries by removing their
# symbol tables.
STRIP = strip
# To retain the symbol tables for debugging, comment out the previous line, and
# uncomment the next line.
# STRIP = :

# `make' (with no target specified) will be equivalent to `make all'.
make-all:	all

# `make lib-post-install' should be run after installing the WFDB library.
lib-post-install:
	ranlib $(LIBDIR)/$(WFDBLIB)

lib-post-uninstall:
	echo "Nothing to be done for lib-post-uninstall"
# _____________________________________________________________________________
# file: Makefile.tpl		G. Moody	24 May 2000
#				Last revised:  8 August 2002
# This section of the Makefile should not need to be changed.

# ARCH specifies the type of CPU and the operating system (e.g., 'i686-Linux').
# This symbol is used only to generate a name for the binary archive;  it
# does not affect how the software is compiled.
ARCH=`uname -m`-`uname -s`

# 'make' or 'make all': compile the WFDB applications without installing them
# (requires installation of the WFDB library and includes)
all:		config.cache
	cd lib;	     $(MAKE) install
	cd wave;     $(MAKE) all
	cd waverc;   $(MAKE) all
	cd app;      $(MAKE) all
	cd psd;      $(MAKE) all
	cd examples; $(MAKE) all
	cd convert;  $(MAKE) all

# 'make install': compile and install the WFDB software package
install:	config.cache
	cd lib;	     $(MAKE) install
	cd wave;     $(MAKE) install
	cd waverc;   $(MAKE) install
	cd app;      $(MAKE) install
	cd psd;      $(MAKE) install
	cd convert;  $(MAKE) install
	cd data;     $(MAKE) install
	test -d doc && ( cd doc; $(MAKE) install )

uninstall:	config.cache
	cd lib;	     $(MAKE) uninstall
	cd wave;     $(MAKE) uninstall
	cd waverc;   $(MAKE) uninstall
	cd app;      $(MAKE) uninstall
	cd psd;      $(MAKE) uninstall
	cd convert;  $(MAKE) uninstall
	cd data;     $(MAKE) uninstall
	test -d doc && ( cd doc; $(MAKE) uninstall )
	./uninstall.sh $(WFDBROOT)

# 'make clean': remove binaries, other cruft from source directories
clean:
	cd app;      $(MAKE) clean
	cd checkpkg; $(MAKE) clean
	cd convert;  $(MAKE) clean
	cd data;     $(MAKE) clean
	cd examples; $(MAKE) clean
	cd fortran;  $(MAKE) clean
	cd lib;      $(MAKE) clean
	cd psd;      $(MAKE) clean
	cd wave;     $(MAKE) clean
	cd waverc;   $(MAKE) clean
	cd wview;    $(MAKE) -f clean
	test -d doc && ( cd doc; $(MAKE) clean )
	rm -f *~ conf/*~ conf/prompt config.cache */*.exe $(PACKAGE)-*.spec

# 'make config.cache': check configuration
config.cache:
	exec ./configure
	@echo "(Ignore any error that may appear on the next line.)"
	@false	# force an immediate exit from `make'

conf/prompt:
	echo -n >echo.out
	-test -s echo.out && ln -sf prompt-c conf/prompt
	-test -s echo.out || ln -sf prompt-n conf/prompt
	rm echo.out

# 'make test' or 'make test-all': compile the WFDB applications without
# installing them (installs the dynamically-linked WFDB library and includes
# into subdirectories of $(HOME)/wfdb-test)
test test-all: $(HOME)/wfdb-test/include $(HOME)/wfdb-test/lib
	$(MAKE) WFDBROOT=$(HOME)/wfdb-test all

# 'make test-install': compile and install the WFDB software package into
# subdirectories of $(HOME)/wfdb-test
test-install: $(TESTDIRS)
	$(MAKE) WFDBROOT=$(HOME)/wfdb-test install

# 'make check': test currently installed version of the WFDB software package
check:		config.cache conf/prompt
	cd checkpkg; $(MAKE) all

# Create directories for test installation if necessary.
TESTDIRS = $(HOME)/wfdb-test/bin $(HOME)/wfdb-test/database \
 $(HOME)/wfdb-test/help $(HOME)/wfdb-test/include $(HOME)/wfdb-test/lib

$(HOME)/wfdb-test:
	mkdir -p $(HOME)/wfdb-test; $(SETDPERMISSIONS) $(HOME)/wfdb-test
$(HOME)/wfdb-test/bin:		$(HOME)/wfdb-test
	mkdir -p $(HOME)/wfdb-test/bin; \
	 $(SETDPERMISSIONS) $(HOME)/wfdb-test/bin
$(HOME)/wfdb-test/database:	$(HOME)/wfdb-test
	mkdir -p $(HOME)/wfdb-test/database; \
	 $(SETDPERMISSIONS) $(HOME)/wfdb-test/database
$(HOME)/wfdb-test/help:		$(HOME)/wfdb-test
	mkdir -p $(HOME)/wfdb-test/help; \
	 $(SETDPERMISSIONS) $(HOME)/wfdb-test/help
$(HOME)/wfdb-test/include:	$(HOME)/wfdb-test
	mkdir -p $(HOME)/wfdb-test/include; \
	 $(SETDPERMISSIONS) $(HOME)/wfdb-test/include
$(HOME)/wfdb-test/lib:		$(HOME)/wfdb-test
	mkdir -p $(HOME)/wfdb-test/lib; \
	 $(SETDPERMISSIONS) $(HOME)/wfdb-test/lib

# 'make tarballs': clean up the source directories, then make a pair of gzipped
# tar source archives of the WFDB software package (with and without the
# documentation), and check that the MANIFEST (list of files in the package)
# is correct.
tarballs:	clean
	cd lib; $(SETPERMISSIONS) *.h
	cd ..; tar --create --file $(PACKAGE).tar.gz --verbose --gzip \
          '--exclude=$(PACKAGE)/*CVS' $(PACKAGE) | sed s+${PACKAGE}/++ | \
	  tee $(PACKAGE)-MANIFEST
	cd ..; tar --create --file $(PACKAGE)-no-docs.tar.gz \
	  --verbose --gzip \
          '--exclude=$(PACKAGE)/*doc' \
	  '--exclude=$(PACKAGE)/*CVS' $(PACKAGE)
	./check-manifest $(PACKAGE)

# 'make bin-tarball': make a gzipped tar archive of the WFDB software package
# binaries and other installed files
bin-tarball:	test-install
	cd $(HOME)/wfdb-test;  tar cfvz ../$(PACKAGE)-$(ARCH).tar.gz .

# 'make doc-tarball': make a gzipped tar archive of formatted documents
# (requires many freely-available utilities that are not part of this
# package;  see doc/Makefile.top for details)
doc-tarball:
	cd doc; $(MAKE) tarball

# 'make rpms': make source and binary RPMs
RPMROOT=/usr/src/redhat

rpms:		tarballs
	cp -p ../$(PACKAGE).tar.gz $(RPMROOT)/SOURCES
	sed s/VERSION/$(VERSION)/ <wfdb.spec | \
	 sed s/RPMRELEASE/$(RPMRELEASE)/ >$(PACKAGE)-$(RPMRELEASE).spec
	cp -p $(PACKAGE)-$(RPMRELEASE).spec $(RPMROOT)/SPECS
	rpm -ba $(PACKAGE)-$(RPMRELEASE).spec
	mv $(RPMROOT)/RPMS/*/$(PACKAGE)-$(RPMRELEASE).*.rpm ..
	mv $(RPMROOT)/SRPMS/$(PACKAGE)-$(RPMRELEASE).src.rpm ..
	rm -f $(PACKAGE)-$(RPMRELEASE).spec
