# file: makewave	G. Moody	 1 May 1990
#			Last revised:   1 April 2000		WAVE 6.3
# `make' description file for WAVE (renamed to `Makefile' by ../configure)
#
# -----------------------------------------------------------------------------
# WAVE: Waveform analyzer, viewer, and editor
# Copyright (C) 2000 George B. Moody
#
# This program is free software; you can redistribute it and/or modify it 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.
#
# This program 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 General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; 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 compile and install WAVE.
# WAVE can be compiled and run only on UNIX systems, although any networked
# system with an X11 server can be used to view its output;  suitable servers
# are available for MS-DOS, the Macintosh, and VAX VMS as well as UNIX.
# In order to compile WAVE, you must have already installed the X11 Xlib
# (libX11.a), XView (libxview.a), and WFDB (libwfdb.a) libraries, and their
# associated header files (in /usr/include/X11, /usr/include/xview, and
# /usr/include/ecg respectively).  The WFDB library source is included with the
# WAVE distribution (in the `lib' directory at the same level as this one).
# Xlib and XView are freely available by anonymous FTP as parts of the X11R4
# distribution from expo.lcs.mit.edu and other sites, or from the MIT Software
# Distribution Center, MIT Room E32-300, Cambridge, MA 02139 USA; telephone
# +1-617-253-6966.  See the main help file (wave.hl0, in this directory) for
# further information.
#
# Before using this file for the first time, check that the site-specific
# variables below are appropriate for your system.  To build and install WAVE,
# just type `make' (from within this directory).

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

# WAVEVERSION is the WAVE version number.
WAVEVERSION = 6.3

# Choose directories in which to install WAVE and its ancillary files by
# editing the variables below.  You will need write permission in all of them
# in order to install WAVE successfully, and WAVE users will need read
# permission in all of them.  If the directories don't exist already, they
# will be created with appropriate permissions by the installation procedure.

# This section of site-dependent variables specifies the locations in your
# file system where the WAVE software and data files will be installed.
# You may choose a different set of locations if you prefer, but documentation
# included in this package generally assumes that you have used the defaults
# given here.  You will need write permission in all of the directories named
# in this section, and users of the software will need read permission in all
# of these directories.  Generally, you will need `root' permissions in order
# to install the software in the standard places.  To do so, uncomment the next
# line.
WFDBROOT = /usr
# If you do not have `root' permissions, a reasonable alternative to the
# standard installation is to put everything into directories called `include'
# and `local' within the current directory (or any other writeable directory).
# To use the current directory for this purpose, replace `xxx' below with the
# full pathname of the current directory, and uncomment the next line.
# WFDBROOT = xxx

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

# INCDIR should be one of the directories searched by your C compiler for
# #include <...> files.
INCDIR = $(WFDBROOT)/include

# HELPDIR specifies the directory in which the on-line help files are kept.
# The installation procedure creates a subdirectory, `wave', in HELPDIR, and
# installs several files there.
HELPDIR = $(WFDBROOT)/local/help

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

# MENUDIR specifies the directory in which the default analysis menu file is
# kept.
MENUDIR = $(WFDBROOT)/local/lib

# RESDIR specifies the directory in which X11 client resource files are kept.
RESDIR = $(WFDBROOT)/lib/X11/app-defaults

# CC is the name of your C compiler.  WAVE can be compiled with K&R C compilers
# (`cc' on most if not all UNIX systems) as well as with ANSI C compilers such
# as GNU C (`gcc').
CC = cc

# CFLAGS is the set of C compiler options.  Add the following options to CFLAGS
# as appropriate (separating them by spaces if you use more than one):
#  -g		to save symbols for debugging
#  -O		if you trust your C compiler's optimizer
# Except for `gcc', most C compilers won't let you use both -g and -O.
CFLAGS = -O -I$(INCDIR) -I/usr/openwin/include

# HELPOBJ can be set to "help.o" if you wish to recompile the XView spot help
# functions in "help.c" (recommended under Linux).
HELPOBJ = help.o
# Otherwise, use the version in libxview by uncommenting the next line:
# HELPOBJ =

# OPENWINHOME specifies the root directory of the OpenWindows hierarchy.
# This is usually /usr/openwin.
OPENWINHOME = /usr/openwin
# Need to use /usr/local on BIH SunOS systems to generate OW 3.0-compatible
# executables.
# OPENWINHOME = /usr/local
# OPENWINHOME = /usr/i486-linuxaout

# OWINCDIR is the directory in which the `xview' directory containing XView
# *.h files is found.
OWINCDIR = $(OPENWINHOME)/include

# OWLIBDIR is the directory in which the XView library is found.
OWLIBDIR = $(OPENWINHOME)/lib

# LDFLAGS is the set of loader options appended to the C compiler command line
# to specify loading the WFDB, XView, and Xlib libraries.  Unless you have
# changed the value of WFDBLIB in the `makefile' for the WFDB library, `-lwfdb'
# should be correct for the WFDB library;  the other library names are probably
# correct unless your X installation is non-standard. If you have installed
# XView 1.0.1 from the X11R4 distribution, uncomment the next line.
# LDFLAGS = -lwfdb -lxview -lX11
# If you have XView 2.0 or later, you will also need the Open Look graphics
# library (libolgx);  in this case, uncomment the next line.
LDFLAGS = -L$(OWLIBDIR) -L/usr/X11R6/lib -L$(LIBDIR) \
 -lwfdb -lxview -lolgx -lX11
# Users of Red Hat Linux 5.0 or 5.1 (not later versions), use this instead:
# LDFLAGS = -L$(OWLIBDIR) -L/usr/X11R6/lib -L$(LIBDIR) \
#  -lwfdb /usr/openwin/lib/libxview.a /usr/openwin/lib/libolgx.a -lX11
# This setting avoids incompatibilities with the shared (dynamic) libraries.
# If you use another version of Linux, or another OS, and have difficulty
# related to WAVE's Analysis commands window, try this workaround, and let
# me know if it works (or if it doesn't work).

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

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

# SETDPERMISSIONS is similarly used to make directories created during the
# installation accessible;  its value is usually identical to SETXPERMISSIONS.
SETDPERMISSIONS = chmod 755

# SETPERMISSIONS is similarly used to make installed data files accessible.
# These files should not be marked as executable.
SETPERMISSIONS = chmod 644

# STRIP is the command needed to strip the symbol table from the executable.
# Uncomment the next line to strip the symbol table for compactness.
STRIP = strip
# Uncomment the next line to retain the symbol table for debugging purposes.
# STRIP = echo

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

HFILES = wave.h bitmaps.h xvwave.h
CFILES = wave.c init.c mainpan.c modepan.c helppan.c logpan.c annpan.c edit.c \
 grid.c sig.c annot.c analyze.c scope.c search.c xvwave.c help.c
OFILES = wave.o init.o mainpan.o modepan.o helppan.o logpan.o annpan.o edit.o \
 grid.o sig.o annot.o analyze.o scope.o search.o xvwave.o $(HELPOBJ)
HELPFILES = analysis.hlp buttons.hlp editing.hlp faq.hlp intro.hlp log.hlp \
 printing.hlp resource.hlp
OTHERFILES = wave.hl0 wave.info wave.pro demo.txt Wave.res wavemenu.def \
 Makefile

# `make' or `make install':  compile and install WAVE and its help files
install:	wave wave.hlp
	test -d $(BINDIR) || \
	 ( mkdir -p $(BINDIR); $(SETDPERMISSIONS) $(BINDIR) )
	test -d $(HELPDIR)/wave || \
	 ( mkdir -p $(HELPDIR)/wave; $(SETDPERMISSIONS) $(HELPDIR)/wave )
	test -d $(MENUDIR) || \
	 ( mkdir -p $(MENUDIR); $(SETDPERMISSIONS) $(MENUDIR) )
	test -d $(RESDIR) || \
	 ( mkdir -p $(RESDIR); $(SETDPERMISSIONS) $(RESDIR) )
	sed s/WAVEVERSION/$(WAVEVERSION)/ <wave.prf | sed "s/WHEN/`date`/" | \
	 sed "s%HELPDIR%$(HELPDIR)%" >wave.pro
	$(STRIP) wave; cp wave $(BINDIR); $(SETXPERMISSIONS) $(BINDIR)/wave
	cp $(HELPFILES) wave.hlp wave.info wave.pro demo.txt $(HELPDIR)/wave
	-ln -s $(HELPDIR)/wave/wave.pro $(HELPDIR)/wave/news.hlp
	cd $(HELPDIR)/wave; $(SETPERMISSIONS) $(HELPFILES) news.hlp wave.info \
	 wave.pro demo.txt
	-cp wavemenu.def $(MENUDIR) && \
	 $(SETPERMISSIONS) $(MENUDIR)/wavemenu.def
	-cp Wave.res $(RESDIR)/Wave && $(SETPERMISSIONS) $(RESDIR)/Wave

# `make help':  show help text
help:
	@echo "*************************************************************"
	@echo "To print the WAVE manual, type 'make manual'."
	@echo "If you have a PostScript Printer, you may also wish to print"
	@echo "the WAVE User's Guide, by typing 'make guide'."
	@echo "*************************************************************"
	@echo
	@echo -n "Press <Return> to view the manual on-screen: "
	@read x
	@echo
	@soelim wave.hl0 | more
	@echo
	@echo "*************************************************************"
	@echo "To print the WAVE manual, type 'make manual'."
	@echo "If you have a PostScript Printer, you may also wish to print"
	@echo "the WAVE User's Guide, by typing 'make guide'."
	@echo "*************************************************************"

wave:		$(OFILES)
	$(CC) -o wave $(OFILES) $(LDFLAGS)

wave-static:	$(OFILES)
	$(CC) -o wave-static $(OFILES) -static $(LDFLAGS)

soelim:		soelim.c
	$(CC) -o soelim -O soelim.c

wave.hlp:	soelim wave.hl0 $(HELPFILES)
	./soelim wave.hl0 >wave.hlp

wave.pro:
	sed s/WAVEVERSION/$(WAVEVERSION)/ <wave.prf | sed "s/WHEN/`date`/" | \
	 sed "s%WAVEPRO%$(HELPDIR)/wave/wave.pro%" >wave.pro

# `make manual': print the on-line manual
manual:
	./soelim wave.hl0 | $(PRINT)

# `make guide': print the WAVE User's Guide
guide:
	cd ../../manuals/wavguide; make guide

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

# `make clean':  remove intermediate and backup files
clean:
	rm -f soelim wave wave-static *.o *~ wave.hlp wave.pro

# `make listing':  print a listing of WAVE sources
listing:	wave.hlp wave.pro
	$(PRINT) README REGCARD $(HFILES) $(CFILES) $(HELPFILES) $(OTHERFILES)

# Dependencies and special rules for compilation of the modules of `wave'
wave.o:		wave.h wave.c
	$(CC) -c $(CFLAGS) -DHELPDIR=\"$(HELPDIR)\" wave.c
init.o:		wave.h xvwave.h init.c
mainpan.o:	wave.h xvwave.h mainpan.c Makefile
	$(CC) -c $(CFLAGS) -DWAVEVERSION=\"$(WAVEVERSION)\" mainpan.c
modepan.o:	wave.h xvwave.h modepan.c
helppan.o:	wave.h xvwave.h helppan.c
	$(CC) -c $(CFLAGS) -DWAVEVERSION=\"$(WAVEVERSION)\" helppan.c
logpan.o:	wave.h xvwave.h logpan.c
annpan.o:	wave.h xvwave.h annpan.c
edit.o:		wave.h xvwave.h edit.c
grid.o:		wave.h xvwave.h grid.c
search.o:	wave.h xvwave.h search.c
sig.o:		wave.h xvwave.h sig.c
annot.o:	wave.h xvwave.h annot.c
	$(CC) -c $(CFLAGS) -DWAVEVERSION=\"$(WAVEVERSION)\" annot.c
analyze.o:	wave.h xvwave.h analyze.c
	$(CC) -c $(CFLAGS) -DMENUDIR=\"$(MENUDIR)\" analyze.c
scope.o:	wave.h xvwave.h scope.c
xvwave.o:	wave.h xvwave.h bitmaps.h xvwave.c
	$(CC) -c $(CFLAGS) -DRESDIR=\"$(RESDIR)\" xvwave.c
help.o:		help.c
	$(CC) -c $(CFLAGS) -w help.c
