# file: Makefile		G. Moody	 6 July 1983
#				Last revised:    22 May 2000	Version 10.1.4
# UNIX 'make' description file for compiling the WFDB library
#
# _____________________________________________________________________________
# wfdb: a library for reading and writing annotated waveforms(time series data)
# Copyright (C) 2000 George B. Moody
#
# This library is free software; you can redistribute it and/or modify it 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.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
# more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# 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 install the WFDB library.
# Before using it for the first time, check that the site-specific variables
# below are appropriate for your system.  To build and install the standard
# WFDB library, type `make' or `make lib' (from within this directory).  To
# build and install the alternate WFDB library (not available on all systems),
# type `make slib'.
# _____________________________________________________________________________
# file: version.def		G. Moody	24 May 2000
#				Last revised:  8 August 2002
# Each release of the WFDB Software Package is identified by a three-part
# version number, defined here:
MAJOR = 10
MINOR = 2
RELEASE = 7
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 = 2

# 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
# _____________________________________________________________________________

# file: linux-slib.def		G. Moody	31 May 2000
#                               Last revised: 17 December 2001
# This section contains settings suitable for generating an ELF-format shared
# library 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

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

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

# 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 used when compiling the shared
# library.  CFLAGS should always include CCDEFS.
CFLAGS = -fpic -g -O $(CCDEFS) `$(LWC) --cflags` -I$(INCDIR)

# WFDBLIB_BASENAME is the name, without version numbers, of the alternate
# library.  WFDBLIB_SONAME is the shared object name ("soname") of the
# alternate library; normally, this includes the base name and the major
# version number only. WFDBLIB is the complete name, including the minor
# version number.  Symbolic links from WFDBLIB to WFDBLIB_BASENAME and
# WFDBLIB_SONAME will be created as the final step in building the alternate
# library.
WFDBLIB_BASENAME = libwfdb.so
WFDBLIB_SONAME = $(WFDBLIB_BASENAME).$(MAJOR)
WFDBLIB = $(WFDBLIB_SONAME).$(MINOR)
# For a shared library, the soname is significant for proper run-time binding.
# If you change function interfaces in the library, change its soname by
# incrementing the major version number;  when you do this, set the minor
# version number to zero.  If you change the library without changing the
# function interfaces, increment the minor version number; this allows existing
# binaries to use the new version without recompilation, since the soname is
# unchanged in this case.

# BUILDLIB is the command that creates the shared 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 = gcc -shared -Wl,-soname,$(WFDBLIB_SONAME) `$(LWC) --libs` \
 -o $(WFDBLIB)

# LDCONFIG is the name of the program needed to refresh the system's cached
# index of shared libraries.
LDCONFIG = /sbin/ldconfig

# 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 755

# `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:
	cd $(LIBDIR); ln -sf $(WFDBLIB) $(WFDBLIB_BASENAME)
	cd $(LIBDIR); ln -sf $(WFDBLIB) $(WFDBLIB_SONAME)
	@$(LDCONFIG) || echo Warning: "$(LDCONFIG)" was unsuccessful

lib-post-uninstall:
	rm -f $(LIBDIR)/$(WFDBLIB_BASENAME)
	rm -f $(LIBDIR)/$(WFDBLIB_SONAME)
	@$(LDCONFIG) || echo Warning: "$(LDCONFIG)" was unsuccessful
#______________________________________________________________________________
# file: Makefile.tpl		G. Moody	 24 May 2000
#				Last revised:	18 July 2000
# This section of the Makefile should not need to be changed.

INCLUDES = $(INCDIR)/wfdb/wfdb.h $(INCDIR)/wfdb/ecgcodes.h \
 $(INCDIR)/wfdb/ecgmap.h
COMPAT_INCLUDES = $(INCDIR)/ecg/db.h $(INCDIR)/ecg/ecgcodes.h \
 $(INCDIR)/ecg/ecgmap.h
HFILES = wfdb.h ecgcodes.h ecgmap.h wfdblib.h
CFILES = wfdbinit.c annot.c signal.c calib.c wfdbio.c
OFILES = wfdbinit.o annot.o signal.o calib.o wfdbio.o
MFILES = Makefile makefile.dos

# `make' or `make all':  build the WFDB library
all:	$(OFILES)
	$(BUILDLIB) $(OFILES)

# `make install':  install the WFDB library and headers
install:	$(INCLUDES) $(LIBDIR) all
	cp $(WFDBLIB) $(LIBDIR) 
	$(SETLPERMISSIONS) $(LIBDIR)/$(WFDBLIB)
	$(MAKE) lib-post-install

uninstall:
	../uninstall.sh $(INCDIR)/wfdb $(HFILES)
	../uninstall.sh $(INCDIR)
	../uninstall.sh $(LIBDIR) $(WFDBLIB)
	$(MAKE) lib-post-uninstall
	../uninstall.sh $(LIBDIR)

# `make compat':  install the includes needed for source compatibility with
# applications written for pre-version 10.0.0 versions of this library
compat:		$(INCLUDES) $(COMPAT_INCLUDES)

# `make clean':  also remove previously compiled versions of the library
clean:
	rm -f $(OFILES) libwfdb.* *~

# `make TAGS':  make an `emacs' TAGS file
TAGS:		$(HFILES) $(CFILES)
	@etags $(HFILES) $(CFILES)

# `make listing':  print a listing of WFDB library sources
listing:
	$(PRINT) README $(MFILES) $(HFILES) $(CFILES)

# Rules for creating installation directories
$(INCDIR):
	mkdir -p $(INCDIR); $(SETDPERMISSIONS) $(INCDIR)
$(INCDIR)/wfdb:	$(INCDIR)
	mkdir -p $(INCDIR)/wfdb; $(SETDPERMISSIONS) $(INCDIR)/wfdb
$(INCDIR)/ecg:	$(INCDIR)
	mkdir -p $(INCDIR)/ecg; $(SETDPERMISSIONS) $(INCDIR)/ecg
$(LIBDIR):
	mkdir -p $(LIBDIR); $(SETDPERMISSIONS) $(LIBDIR)

# Rules for installing the include files
$(INCDIR)/wfdb/wfdb.h:		$(INCDIR)/wfdb wfdb.h
	cp -p wfdb.h $(INCDIR)/wfdb; $(SETPERMISSIONS) $(INCDIR)/wfdb/wfdb.h
$(INCDIR)/wfdb/ecgcodes.h:	$(INCDIR)/wfdb ecgcodes.h
	cp -p ecgcodes.h $(INCDIR)/wfdb
	$(SETPERMISSIONS) $(INCDIR)/wfdb/ecgcodes.h
$(INCDIR)/wfdb/ecgmap.h:		$(INCDIR)/wfdb ecgmap.h
	cp -p ecgmap.h $(INCDIR)/wfdb
	$(SETPERMISSIONS) $(INCDIR)/wfdb/ecgmap.h

# Rules for installing the compatibility (pre-10.0.0) include files
$(INCDIR)/ecg/db.h:		$(INCDIR)/ecg db.h
	cp -p db.h $(INCDIR)/ecg; $(SETPERMISSIONS) $(INCDIR)/ecg/db.h
$(INCDIR)/ecg/ecgcodes.h:	$(INCDIR)/ecg $(INCDIR)/wfdb/ecgcodes.h
	ln -s $(INCDIR)/wfdb/ecgcodes.h $(INCDIR)/ecg/ecgcodes.h
$(INCDIR)/ecg/ecgmap.h:		$(INCDIR)/ecg $(INCDIR)/wfdb/ecgmap.h
	ln -s $(INCDIR)/wfdb/ecgmap.h $(INCDIR)/ecg/ecgmap.h

# Prerequisites for the library modules
wfdbinit.o:	wfdb.h wfdblib.h wfdbinit.c
annot.o:	wfdb.h ecgcodes.h ecgmap.h wfdblib.h annot.c
signal.o:	wfdb.h wfdblib.h signal.c
calib.o:	wfdb.h wfdblib.h calib.c
wfdbio.o:	wfdb.h wfdblib.h wfdbio.c
