# file: Makefile-dos-gcc	G. Moody	23 April 1997
#				Last revised:	 23 May 1997
# GCC-DOS `make' description file for DB Software Package
#
# Copyright(C) Massachusetts Institute of Technology 1997. All rights reserved.
#
# *****************************************************************************

# The default settings in this file are suitable for cross-compiling MS-DOS
# binaries using `gcc-dos' under Linux.  `gcc-dos' is a freely available
# version of the GNU C/C++ compiler, set up as a cross-compiler in this case;
# it may be obtained from ftp://sunsite.unc.edu/pub/Linux/devel/msdos (get
# gcc-2.7.2.go32.tar.gz).  A native MS-DOS version is also freely available.
# The binaries produced by gcc-dos are 32-bit executables that require at least
# a 386SX and DPMI services (such as those provided by MS-Windows in a DOS box,
# or by standalone DPMI servers such as 386Max and QDPMI).  If your MS-DOS
# system is a 286 or older PC, or one that has no extended or expanded memory,
# you will probably have to use one of the older commercial compilers such as
# Turbo C or Microsoft C to make 16-bit versions of these programs.

# For information about a native MS-DOS `gcc' and about free DPMI servers,
# visit http://www.delorie.com/djgpp/).  A page about how to make gcc-dos may
# be found at http://www.delorie.com/djgpp/faq/cross/gcc270-unix-to-dos.html.

# If you want to compile Linux, Solaris, or SunOS binaries, see Makefile-linux,
# Makefile-solaris, or Makefile-sunos in this directory for pre-edited versions
# of this file.  If you are using some other version of UNIX, refer to any of
# those other versions for instructions.

# *****************************************************************************

# This file can be used with the UNIX `make' command to cross-compile MS-DOS
# binaries of the DB Software Package.  It works by spawning inferior `make'
# processes in each of the subdirectories listed in the SUBDIRS variable below.
# If you prefer, you can follow the instructions given in `Makefile-gcc-dos' in
# each of the subdirectories, rather than doing everything at once using this
# file.

# Before using this file for the first time, check that the site-specific
# variables below are appropriate for your system.  To cross-compile the DB
# Software Package, just type `make -f Makefile-gcc-dos' from within this
# directory.  On an otherwise lightly loaded 100 MHz Pentium PC with 16 Mb of
# RAM, this process takes about 2 or 3 minutes, depending on which options you
# choose below.

# To remove local copies of the object files, type `make clean'.

# Before using the applications under MS-DOS, you must set the DB environment
# variable.  At the end of the installation, `make' prints instructions for
# doing so.

# Other software that may be useful
# ---------------------------------

# If you have a Web browser such as Netscape or Mosaic, you can read the
# ECG Database Programmer's Guide, the ECG Database Applications Guide, and
# the WAVE User's Guide in hypertext form.  Your system need not be connected
# to a network in order to use a Web browser for this purpose.  If you don't
# have a Web browser, get one!  (See `SOURCES', in this directory.)

# If you have already installed GNU emacs (or GNU info and makeinfo), you can
# install a (different) hypertext version of the ECG Database Programmer's
# Guide on-line.  If you have TeX, you can print your own copies of it.  (All
# three versions -- HTML, GNU info, and printed text -- are produced from the
# same TeXinfo source, in the `doc' directory.) Sources for GNU emacs, info,
# makeinfo, and TeX are freely available;  see `SOURCES'.

# Several programs included here (`pschart', `psfd', and `plotstm') generate
# PostScript output.  If you have a PostScript printer, you need nothing else
# (specifically, you do not need Adobe TranScript software in order to use
# these programs).  If you do not have a PostScript printer, you may wish to
# investigate GNU ghostscript; see `SOURCES'.  The combination of `pschart' and
# ghostscript is an adequate solution for occasional data visualization needs,
# since ghostscript also supports screen output under both MS-DOS and
# MS-Windows, among other possibilities.

# Two other programs included here, `view' for MS-DOS and `wview' for
# MS-Windows, provide interactive means of visualizing signals and annotations.
# Both of these programs must be compiled using commercial compilers, however
# (`view' needs the Microsoft C graphics library, and `wview' requires the
# MS-Windows resource and help compilers).  The sources for `view' and for an
# auxiliary program (`vsetup') are provided if you wish to recompile them or
# attempt a port to gcc-dos.

# A much more capable visualization program, which also supports annotation
# editing and control of external analysis programs, is `wave', an X Window
# System application that is not included in this package.  You can run WAVE on
# a 386 or later PC under the free Linux operating system (see `SOURCES' for
# information about WAVE and Linux.)

# For maximum portability, all of this software has been written in a version
# of C that can be compiled by ANSI/ISO C compilers as well as the older (K&R)
# C compilers that are still standard on many UNIX systems. The main DB library
# header file (db.h) contains conditionally compiled ANSI/ISO C function
# prototypes for compilers such as gcc-dos that support their use.

# Finally, if you have an MS-DOS PC, either Microsoft or Turbo C/C++, and a
# Microstar Laboratories DAP-1200 or DAP-2400 analog interface card (see
# `SOURCES'), you can compile `app/sample.c' (under MS-DOS only).  This program
# converts digital signals from DB records on CD-ROMs or other media to analog
# signals, and can also digitize analog signals to make new DB records (which
# can be used under MS-DOS, UNIX, and other operating systems).  The DB
# Software Package does not include an equivalent UNIX-based application.

# Version numbers
# ---------------

# Each release of the DB Software Package is identified by a three-part version
# number, defined in this section.

# The major version number is incremented, and the minor version and release
# numbers are set to zero, whenever changes have been made that are
# incompatible with previous versions of the DB library.  An example of such a
# change would be adding a new member to a data structure.  These changes are
# infrequent (version 1 of the DB library appeared in 1980).  Existing
# applications usually do not require modification, but they must be recompiled
# if they are to used with a new major version of the library.  The file
# `OLDNEWS' in this directory contains information about differences between
# recent major versions.
MAJOR = 9

# The minor version number is incremented, and the release number is set to
# zero, when compatible changes are made to the DB library. For example,
# existing library functions may be modified internally, or new functions may
# be added to the library, without changing how the existing functions are
# used.  In this case, existing applications can be re-linked to the new
# library without re-compiling them.  In environments such as SunOS, Solaris,
# SVR4, Linux, and at least some versions of HP-UX, it is not even necessary to
# re-link applications explicitly, if they have been linked with shared
# (dynamically-linked) libraries.  In these environments, the version number is
# significant for proper run-time binding of the shared library.  The file
# `NEWS' in this directory contains information about differences between
# minor versions of the current major version.
MINOR = 7

# The release number is incremented when components of the DB Software Package
# other than the DB library have changed.  For example, new applications may
# be added, or new options may be added to existing applications.  The file
# `NEWNEWS' in this directory contains information about differences between
# releases of the current minor version.
RELEASE = 1

# The full version number is used during installation, so that you can be
# warned if you try to install an old version over a new one.  It is also
# available to applications by invoking the DB library function `dberror'
# before any DB library errors have occurred.
VERSION = $(MAJOR).$(MINOR).$(RELEASE)

# Site-specific variables
# -----------------------

# The first group of site-specific variables specifies what portions of the DB
# Software Package are to be cross-compiled.  As distributed, this file
# contains settings that will cross-compile everything that can be
# cross-compiled.

# SUBDIRS specifies the list of (sub)directories in which to run `make'.  This
# list must begin with `lib' (which contains the DB library), but the others
# are optional and may be listed in any order:
#	app		the standard application programs
#	convert		programs for converting DB files to and from AHA format
#	examples	programs from the ECG Database Programmer's Guide
#	microdb		a 1-minute sample from the MIT-BIH Arrhythmia Database
#	psd		programs for power spectral density estimation
#	udb		miscellaneous header files for local and piped records
SUBDIRS = lib app convert examples microdb psd udb

# LIBTARGETS specifies the list of `make' targets within the `lib' directory.
# This list should always include `dblib' (to build and install the standard
# DB library).
LIBTARGETS = dblib

# APPTARGETS specifies the list of `make' targets within the `app' directory.
# This list should always include `standard' (to build and install the standard
# set of applications), and it may also include:
#	scripts		(to create an MS-DOS batch file and a data file for
#			 setting the DB path, see below)
APPTARGETS = standard scripts

#..............................................................................

# This section contains variables that specify where to find database records
# on CD-ROMs.  If you have no CD-ROM databases, skip this section.

# By indicating below that you plan to use a CD-ROM, you instruct `make' to
# insert the appropriate directory names for that CD-ROM into a list of
# directories that are searched by the DB software.  You can modify this
# list at any time by editing this file and typing `make scripts' (it is not
# necessary to re-compile).  It is harmless to include directories for a
# CD-ROM that you don't have, or that is not always on-line.

# Set CDMOUNTPOINT to the standard mount point (root directory) for CD-ROMs on
# your system.  (If you wish to use more than one mount point for CD-ROMs to
# be read by DB applications, replace each occurrence of $(CDROOT) in the
# following lines by the appropriate mount point).  If your CD-ROM drive is
# the d: drive, the following value is probably correct:
CDMOUNTPOINT=d:

# If you plan to use MIMIC Database CD-ROMs, set CDM to the name of the root
# directory (mount point) for the CD-ROM filesystem, and uncomment the
# next 2 lines:
CDM = $(CDMOUNTPOINT)
CDR0 = ;$(CDM)/mimicdb;$(CDM)/mimicdb/%3r
# (The DB library replaces `%3r' in the line above by the first 3 characters of
# the record name at run time.  This is needed because of the organization of
# the MIMIC Database CD-ROMs, with each record in its own directory.)
# If you plan to use MIMIC Database CD-ROMs on two or more CD-ROM drives, add
# the `mimicdb' directories from each such drive to CDR0 above, with a `;'
# between directory names.  CDR0 must begin with `;'.
# Otherwise, uncomment the next line:
# CDR0 =

# If you plan to use the MIT-BIH Arrhythmia Database CD-ROM, set CDB to the
# name of the root directory for the CD-ROM (not necessarily the same as CDM,
# if you have two or more CD-ROM drives), and uncomment the next 2 lines:
CDB = $(CDM)
CDR1 = ;$(CDB)/mitdb;$(CDB)/cudb;$(CDB)/nstdb;$(CDB)/stdb;$(CDB)/vfdb;$(CDB)/afdb;$(CDB)/cdb;$(CDB)/svdb;$(CDB)/ltdb;$(CDB)/odb;$(CDB)/udb
# Otherwise, uncomment the next line:
# CDR1 =

# If you plan to use the European ST-T Database CD-ROM, set CDE to the name of
# the root directory for the CD-ROM, and uncomment the next 2 lines:
CDE = $(CDM)
CDR2 = ;$(CDE)/edb;$(CDE)/valedb
# Otherwise, uncomment the next line:
# CDR2 =

# If you plan to use the MIT-BIH Polysomnographic Database CD-ROM, set CDP to
# the name of the root directory for the CD-ROM, and uncomment the next 2
# lines:
CDP = $(CDM)
CDR3 = ;$(CDP)/slpdb
# Otherwise, uncomment the next line:
# CDR3 =

# If you plan to use the MGH/MF Waveform Database CD-ROMs on a single CD-ROM
# drive, set CDMG to the name of the root directory for the CD-ROMs, and
# uncomment the next 2 lines:
CDMG = $(CDM)
CDR4 = ;$(CDMG)/mghdb
# If you plan to use the MGH/MF Waveform Database CD-ROMs on two or more CD-ROM
# drives, add the `mghdb' directories from each such drive to CDR4 above,
# with a `;' between directory names.  CDR4 must begin with `;'.
# Otherwise, uncomment the next line:
# CDR4 =

# If you plan to use the sample records included on either the `Samples of
# Physiologic Databases' or the `Software for Physiologic Databases with
# Samples' CD-ROMs available from MIT, uncomment the next 2 lines:
CDS = $(CDM)
CDR5 = ;$(CDS)/database;$(CDS)/database/%3r
# See the comments about the MIMIC Database above for an explanation of `%3r'.
# Otherwise, uncomment the next line:
# CDR5 =

# Add additional lines for any other compatible CD-ROM databases here, and
# be sure to include them in CDRDB below.
CDR6 = 
CDR7 =
CDR8 =
CDR9 =

# List all of the CDRn variables defined above in CDRDB, in the order you wish
# them to be searched.
CDRDB = $(CDR0)$(CDR1)$(CDR2)$(CDR3)$(CDR4)$(CDR5)$(CDR6)$(CDR7)$(CDR8)$(CDR9)

#..............................................................................

# If you plan to use the AHA Database for Evaluation of Ventricular Arrhythmia
# Detectors, edit ADB to include the name of the directory or directories in
# which it is (or will be) installed.  You may also include the names of any
# directories that will contain other databases for use with this software.
# ADB must begin with `;';  if you specify more than one directory, place a `;'
# before each directory name.  As noted in the previous section, you can type
# `make scripts' at any time if you wish to change the list of directories.
ADB = ;c:/ahadb
# If you do not plan to use the AHA Database, or any others not listed in the
# previous section, uncomment the next line:
# ADB =

#..............................................................................

# This section of site-dependent variables specifies the locations in your file
# system where the DB software and data files will be installed.  If you have a
# dual-boot Linux/MS-DOS (or Linux/MS-Windows) PC, you may wish to install
# everything directly into your DOS/Windows partition; if so, set INSTALL to
# the mount point for that partition (and make sure that it is mounted and
# writeable before you begin cross-compiling).  Otherwise, you may use any
# desired directory for INSTALL, and then copy the binaries to DOS manually
# after running `make'.
INSTALL = /usr/local/dos

# If your system supports the `mkdir -p' command to create a directory (and its
# ancestors, if necessary), and you wish to have `make' create the directories
# named in this section as needed, uncomment the next line:
MAKEDIRS = makedirs
# Otherwise, make the directories manually, and uncomment the next line:
# MAKEDIRS =

# 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.
# Note that programs in `examples', if compiled, are left in that directory
# and are NOT copied to BINDIR.
BINDIR = $(INSTALL)/bin

# DBDIR specifies the name of a directory in which to install the contents
# of the `microdb' and `udb' directories.
DBDIR = $(INSTALL)/database

# DDBDIR specifies the MS-DOS name of the directory corresponding to DBDIR.
# (Forward slashes are OK here.)
DDBDIR = c:/database

# DBPATH specifies, in the format used by the Bourne shell's PATH variable,
# a list of directories to be searched in order to find DB files (see the
# section titled `The Database Path' in the ECG Database Programmer's Guide).
# DBPATH is used to construct the C-shell script `cshsetdb' and the Bourne (or
# Korn) shell script `setdb', which are installed in BINDIR.  Each user's
# `.cshrc' or `.profile' should read the appropriate script in order to set
# the DB environment variable.
#
# If you decide to change DBPATH after installing the software, simply edit
# its value below and type `make scripts' (it is not necessary to recompile).
# Note that the first component of DBPATH is empty;  this is recommended in
# order that user-created DB files (which generally go into the user's current
# directory) can be read.
DBPATH = ;$(DDBDIR)$(CDRDB)$(ADB)

# INCDIR specifies the directory under which the DB library #include files are
# to be installed.  The installation process creates a subdirectory called
# `ecg' within INCDIR; it does not write anything else into INCDIR itself.  If
# INCDIR is not normally searched by your C compiler for #include <...> files,
# you will need to use the compiler option -I$(INCDIR) whenever compiling
# programs that use these headers.
INCDIR = $(INSTALL)/include

# LIBDIR should be one of the directories searched by CC's loader for -l...
# libraries.
LIBDIR = $(INSTALL)/lib

# PAPERDEF specifies the default paper size assumed by `pschart' and `psfd'.
# PAPERDEF is specified as a command-line definition for the C compiler.
# Uncomment one of the following, or see the sources in the `app' directory
# for other choices:
PAPERDEF=-DPTYPE='\"letter\"'	# US standard, 8.5 x 11 inches (216 x 279 mm) 
# PAPERDEF=-DPTYPE='\"A4\"'	# European standard, 210 x 297 mm

# PSPDIR specifies the directory in which PostScript prolog files are kept.
PSPDIR = $(INSTALL)/lib/ps

#.............................................................................

# This section of site-specific variables specifies names of and options for
# system programs that are needed during the DB software installation.

# CCDIR is the directory containing the cross-compiler and the binary
# file utilities for MSDOS.
CCDIR = /usr/lib/gcc-lib/i386-go32-msdos/2.7.2

# CC is the name of the cross-compiler.
CC = $(CCDIR)/gcc

# CCDEFS is the set of C compiler options needed to set preprocessor variables
# while compiling the DB Software Package.  You should include definitions of
# the major, minor, and release numbers, and of MSDOS, as shown below.  Other
# definitions are needed only for various versions of UNIX and should be
# omitted here.
CCDEFS = -DDB_MAJOR=$(MAJOR) -DDB_MINOR=$(MINOR) -DDB_RELEASE=$(RELEASE) -DMSDOS

# CFDB is the set of C compiler options to be used when compiling the DB
# library.  CFDB should always include CCDEFS.  Add the following options to
# CFDB as appropriate (separating them by spaces if you use more than one):
#   -g		  to save symbols for debugging
#   -O		  to use the optimizer
#   -I$(INCDIR)   needed if INCDIR is not in the normal search path for
#		   `#include' files;  harmless otherwise
# `gcc-dos' is able to accept both -g and -O simultaneously; using a debugger
# on optimized code can be tricky, though, and you may prefer to compile with
# -g and not -O if you need to use a symbolic debugger.  For normal use,
# optimized code is preferable (the gcc optimizer is solid and effective).
CFDB = -O -I$(INCDIR) $(CCDEFS)

# CFAPP is the list of C compiler options used when compiling programs in the
# `app', `convert', and `example' directories.  Add the following options to
# CFAPP as appropriate (separating them by spaces if you use more than one):
#   -g		  to save symbols for debugging
#   -O		  to use the optimizer
#   -I$(INCDIR)   needed if INCDIR is not in the normal search path for
#		   `#include' files;  harmless otherwise
#   -L$(LIBDIR)   needed if LIBDIR is not in the normal library search path;
#		   harmless if LIBDIR is in the normal library search path
# As noted above, gcc-dos allows you to use both -g and -O if you wish.
CFAPP = -O -I$(INCDIR) $(CCDEFS) -L$(LIBDIR)

# DBLIB is the name of the standard DB library.  In order to access it via
# `-ldb', DBLIB should be `libdb.a'.
DBLIB = libdb.a

# LDFLAGS is appended to the C compiler command line when compiling programs in
# the `app', `convert', `example' and `psd' directories, to specify loading the
# DB library.  Unless you have changed the value of DBLIB above, `-ldb' should
# be correct.
LDFLAGS = -ldb

# MAKE is the name of the `make' utility itself, in this case with an option
# to use the special gcc-dos Makefiles by default when running a recursive
# make.
MAKE = make -f Makefile-dos-gcc

# STRIP is the command used to compact the compiled binaries by removing their
# symbol tables.  The next line is commented out because $(CCDIR)/strip fails.
#STRIP = $(CCDIR)/strip
# To retain the symbol tables for debugging, comment out the previous line, and
# uncomment the next line.
STRIP = :

# It should not be necessary to modify anything below this line.
# -----------------------------------------------------------------------------

# Build and install everything
install:	$(MAKEDIRS) $(SUBDIRS)
	@echo
	@echo "The DB Software Package, version $(VERSION), has been"
	@echo "successfully compiled for MS-DOS.  Before using this software,"
	@echo "copy the contents of $(BINDIR) to a directory in your MS-DOS"
	@echo "PATH (and copy the other directories within $(INSTALL) to"
	@echo "same-named directories at the same level as the copy of"
	@echo "$(BINDIR)).  From MS-DOS, run"
	@echo "    dossetdb"
	@echo "to set the environment variables DB and DBCAL, or add"
	@echo "    call dossetdb"
	@echo "to your autoexec.bat to do so automatically whenever you"
	@echo "reboot MS-DOS."

# Clean up temporaries, binaries, etc.
clean:
	rm -f *~
	cd lib; $(MAKE) clean
	cd app; $(MAKE) clean
	cd convert; $(MAKE) clean
	cd examples; $(MAKE) clean
	cd psd; $(MAKE) clean

# Make destination directories as needed
makedirs:
	test -d $(BINDIR) || mkdir -p $(BINDIR)
	test -d $(DBDIR)  || mkdir -p $(DBDIR)
	test -d $(INCDIR) || mkdir -p $(INCDIR)
	test -d $(LIBDIR) || mkdir -p $(LIBDIR)
	test -d $(PSPDIR) || mkdir -p $(PSPDIR)


# Rules for targets in `lib'
lib:	$(LIBTARGETS)

dblib:
	cd lib; $(MAKE) clean
	cd lib; $(MAKE) CC=$(CC) "CFLAGS=$(CFDB)" INCDIR=$(INCDIR) \
	 LIBDIR=$(LIBDIR) DBLIB=$(DBLIB) RANLIB=$(RANLIB) install

# Rules for targets in `app'
app:	$(APPTARGETS)

standard:
	cd app; $(MAKE) CC=$(CC) "CFLAGS=$(CFAPP) $(PAPERDEF)" \
	 "LDFLAGS=$(LDFLAGS)" BINDIR=$(BINDIR) PSPDIR=$(PSPDIR) \
	 STRIP=$(STRIP) install

scripts:
	echo "$(DBPATH)" >$(DBDIR)/dbpath.dos
	echo "set DB=@$(DDBDIR)/dbpath.dos@" >$(BINDIR)/dossetdb.bat
	echo "set DBCAL=dbcal" >>$(BINDIR)/dossetdb.bat

# Rules for targets in `convert'
convert:	makeconvert
makeconvert:
	cd convert; $(MAKE) CC=$(CC) "CFLAGS=$(CFAPP)" "LDFLAGS=$(LDFLAGS)" \
	 BINDIR=$(BINDIR) STRIP=$(STRIP) install


# Rules for targets in `examples'
examples:	makeexamples
makeexamples:
	cd examples; $(MAKE) CC=$(CC) "CFLAGS=$(CFAPP)" "LDFLAGS=$(LDFLAGS)" \
	 compile


# Rules for targets in `microdb'
microdb:	makemicrodb
makemicrodb:
	cd microdb; $(MAKE) DBDIR=$(DBDIR) install


# Rules for targets in `psd'
psd:	makepsd
makepsd:
	cd psd; $(MAKE) CC=$(CC) "CFLAGS=$(CFAPP)" "BINDIR=$(BINDIR)" \
	 STRIP=$(STRIP) install


# Rules for targets in `udb'
udb:		makeudb
makeudb:
	cd udb; $(MAKE) DBDIR=$(DBDIR) install
