# Makefile - dependencies for the Gnuroscan system.
# Copyright (c) 1995, 1998 Matthew Belmonte
#
# 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.
#
# If you find this program useful, please send mail to Matthew Belmonte.
# <mkb4@Cornell.edu>.  If you base a publication on data processed by this
# program, please notify Matthew Belmonte and include the following citation
# in your publication:
#
#	Matthew Belmonte, `A Software System for Analysis of
#	Steady-State Evoked Potentials', Association for Computing
#	Machinery SIGBIO Newsletter 17:1:9-14 (April 1997).
#
#set these constants appropriately for your system:
#C compiler
CC = /usr/bin/cc
#
#archiver
AR = /usr/bin/ar
#
#ranlib (for SVR4 this is a no-op - i.e., /bin/touch)
RANLIB = /usr/bin/ranlib
#
#C compiler flags
CFLAGS = -O2 -I/usr/local/include/nr -DLINUX -DNOFLOATS -DM_I86
#
#installation directory
INSTALLDIR = /usr/local/bin/gnuroscan
#
#source code for Numerical Recipes in C
RECIPES = /usr/local/pkg/numerical_recipes
#
#Numerical Recipes object library
LIBNRC = /usr/local/lib/libnrc.a
#
#YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE
#
PUB_OBJS = libintel.o libintel.a cntcat.o lderiv.o median.o queue.o score.o fmedian.h fmedian.o range.o extreme.o smooth.o rectify.o detrend.o addavg.o scale.o subepoch.o ztrans.o chisquare.o permtest.o ttest.o mannwhitney.o signtest.o friedman.o dumpavg.o plotavg.o fplotavg.o zplotavg.o z.o f2.o chisq.o fisher.o twiddle.o
OBJS = $(PUB_OBJS) eyehand.o average.o heoghisto.o power.o mrqmin.o mrqcof.o nrutil.o
PUB_EXES = sequence cntcat lderiv score range extreme detrend smooth rectify addavg scale subepoch ztrans chisquare permtest ttest mannwhitney signtest friedman dumpavg plotavg fplotavg zplotavg
EXES = $(PUB_EXES) eyehand average heoghisto power
DEBUG_EXES = training_sequence count_stimuli dumpevtb

all:
	cat README

complete: $(EXES)
public: $(PUB_EXES)
debug: $(DEBUG_EXES)

libintel.o: libintel.c
	$(CC) $(CFLAGS) -c libintel.c

libintel.a: libintel.o
	$(AR) r libintel.a libintel.o
	$(RANLIB) libintel.a

sequence: sequence.c
	$(CC) $(CFLAGS) -o sequence sequence.c -lm

training_sequence: training_sequence.c
	$(CC) $(CFLAGS) -o training_sequence training_sequence.c -lm

count_stimuli: count_stimuli.c
	$(CC) $(CFLAGS) -o count_stimuli count_stimuli.c

dumpevtb: dumpevtb.c intel.h gnuro.h libintel.a
	$(CC) $(CFLAGS) -o dumpevtb dumpevtb.c libintel.a

cntcat.o: cntcat.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c cntcat.c

cntcat: cntcat.o libintel.a
	$(CC) $(CFLAGS) -o cntcat cntcat.o libintel.a

lderiv.o: lderiv.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c lderiv.c

lderiv: lderiv.o gnuro.h intel.h libintel.a
	$(CC) $(CFLAGS) -o lderiv lderiv.o libintel.a -lm

median.o: median.c median.h
	$(CC) $(CFLAGS) -c median.c

queue.o: queue.c queue.h
	$(CC) $(CFLAGS) -c queue.c

score.o: score.c fastshft.h gnuro.h intel.h median.h queue.h
	$(CC) $(CFLAGS) -c score.c

score: score.o median.o queue.o libintel.a
	$(CC) $(CFLAGS) -o score score.o median.o queue.o libintel.a -lm

eyehand.o: eyehand.c fastshft.h gnuro.h intel.h median.h
	$(CC) $(CFLAGS) -c eyehand.c

eyehand: eyehand.o median.o fisher.o mrqmin.o mrqcof.o nrutil.o libintel.a
	$(CC) $(CFLAGS) -o eyehand eyehand.o median.o fisher.o mrqmin.o mrqcof.o nrutil.o libintel.a $(LIBNRC) -lm

average.o: average.c fastshft.h gnuro.h intel.h median.h
	$(CC) $(CFLAGS) -c average.c

average: average.o median.o mrqmin.o mrqcof.o nrutil.o libintel.a
	$(CC) $(CFLAGS) -o average average.o median.o mrqmin.o mrqcof.o nrutil.o libintel.a $(LIBNRC) -lm

heoghisto.o: average.c fastshft.h gnuro.h intel.h median.h
	$(CC) $(CFLAGS) -DHISTO_ONLY -c average.c
	mv -f average.o heoghisto.o

heoghisto: heoghisto.o median.o mrqmin.o mrqcof.o nrutil.o libintel.a
	$(CC) $(CFLAGS) -o heoghisto heoghisto.o median.o mrqmin.o mrqcof.o nrutil.o libintel.a $(LIBNRC) -lm

power.o: power.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c power.c

power: power.o libintel.a
	$(CC) $(CFLAGS) -o power power.o libintel.a $(LIBNRC) -lm

fmedian.h: median.h
	sed -e s/short/float/g <median.h >fmedian.h

fmedian.o: median.c fmedian.h
	sed -e s/median\\.h/fmedian\\.h/g <median.c >fmedian.c
	$(CC) $(CFLAGS) -c fmedian.c
	rm -f fmedian.c

range.o: range.c gnuro.h intel.h fmedian.h
	$(CC) $(CFLAGS) -c range.c

range: range.o fmedian.o libintel.a
	$(CC) $(CFLAGS) -o range range.o fmedian.o libintel.a

extreme.o: extreme.c gnuro.h intel.h fmedian.h
	$(CC) $(CFLAGS) -c extreme.c

extreme: extreme.o fmedian.o libintel.a
	$(CC) $(CFLAGS) -o extreme extreme.o fmedian.o libintel.a

smooth.o: smooth.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c smooth.c

smooth: smooth.o libintel.a
	$(CC) $(CFLAGS) -o smooth smooth.o libintel.a

rectify.o: rectify.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c rectify.c

rectify: rectify.o libintel.a
	$(CC) $(CFLAGS) -o rectify rectify.o libintel.a

detrend.o: detrend.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c detrend.c

detrend: detrend.o libintel.a
	$(CC) $(CFLAGS) -o detrend detrend.o libintel.a

addavg.o: addavg.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c addavg.c

addavg: addavg.o libintel.a
	$(CC) $(CFLAGS) -o addavg addavg.o libintel.a

scale.o: scale.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c scale.c

scale: scale.o libintel.a
	$(CC) $(CFLAGS) -o scale scale.o libintel.a

subepoch.o: subepoch.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c subepoch.c

subepoch: subepoch.o libintel.a
	$(CC) $(CFLAGS) -o subepoch subepoch.o libintel.a

ztrans.o: ztrans.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c ztrans.c

ztrans: ztrans.o libintel.a
	$(CC) $(CFLAGS) -o ztrans ztrans.o libintel.a -lm

chisquare.o: chisquare.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c chisquare.c

chisquare: chisquare.o chisq.o z.o libintel.a
	$(CC) $(CFLAGS) -o chisquare chisquare.o chisq.o z.o libintel.a -lm

permtest.o: permtest.c twiddle.h
	$(CC) $(CFLAGS) -c permtest.c

permtest: permtest.o twiddle.o libintel.a
	$(CC) $(CFLAGS) -o permtest permtest.o twiddle.o libintel.a

ttest.o: ttest.c gnuro.h intel.h fisher.h
	$(CC) $(CFLAGS) -c ttest.c

ttest: ttest.o fisher.o libintel.a
	$(CC) $(CFLAGS) -o ttest ttest.o fisher.o libintel.a -lm

mannwhitney.o: mannwhitney.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c mannwhitney.c

mannwhitney: mannwhitney.o libintel.a
	$(CC) $(CFLAGS) -o mannwhitney mannwhitney.o libintel.a

signtest.o: signtest.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c signtest.c

signtest: signtest.o libintel.a
	$(CC) $(CFLAGS) -o signtest signtest.o libintel.a

friedman.o: friedman.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c friedman.c

friedman: friedman.o chisq.o z.o libintel.a
	$(CC) $(CFLAGS) -o friedman friedman.o chisq.o z.o libintel.a -lm

dumpavg.o: dumpavg.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c dumpavg.c

dumpavg: dumpavg.o libintel.a
	$(CC) $(CFLAGS) -o dumpavg dumpavg.o libintel.a

plotavg.o: plotavg.c gnuro.h intel.h fmedian.h
	$(CC) $(CFLAGS) -c plotavg.c

plotavg: plotavg.o fmedian.o libintel.a
	$(CC) $(CFLAGS) -o plotavg plotavg.o fmedian.o libintel.a -lm

fplotavg.o: fplotavg.c gnuro.h intel.h fastshft.h fmedian.h
	$(CC) $(CFLAGS) -c fplotavg.c

fplotavg: fplotavg.o fmedian.o libintel.a
	$(CC) $(CFLAGS) -o fplotavg fplotavg.o fmedian.o libintel.a -lm

zplotavg.o: zplotavg.c gnuro.h intel.h
	$(CC) $(CFLAGS) -c zplotavg.c

zplotavg: zplotavg.o libintel.a
	$(CC) $(CFLAGS) -o zplotavg zplotavg.o libintel.a -lm

fisher.o: fisher.c
	$(CC) $(CFLAGS) -c fisher.c

twiddle.o: twiddle.c
	$(CC) $(CFLAGS) -c twiddle.c

mrqmin.o: $(RECIPES)/mrqcof.c
	sed -e  "s/void *( *\* *funcs *) *( *float/void (*funcs)(double/g" <$(RECIPES)/mrqmin.c >mrqmin.c
	$(CC) $(CFLAGS) -I$(RECIPES) -c mrqmin.c
	rm -f mrqmin.c

mrqcof.o: $(RECIPES)/mrqcof.c
	sed -e  "s/void *( *\* *funcs *) *( *float/void (*funcs)(double/g" <$(RECIPES)/mrqcof.c >mrqcof.c
	$(CC) $(CFLAGS) -I$(RECIPES) -c mrqcof.c
	rm -f mrqcof.c

nrutil.o: $(RECIPES)/nrutil.c
	sed -e "s/void nrerror/static void nrerror/" <$(RECIPES)/nrutil.c >nrutil.c
	$(CC) $(CFLAGS) -I$(RECIPES) -c nrutil.c
	rm -f nrutil.c

z.o: z.c
	$(CC) $(CFLAGS) -c z.c

f2.o: f2.c
	$(CC) $(CFLAGS) -c f2.c

chisq.o: chisq.c
	$(CC) $(CFLAGS) -c chisq.c

install:
	mv -f $(EXES) $(INSTALLDIR)

clean:
	rm -f $(OBJS) $(EXES) $(DEBUG_EXES)
