
# Copyright (c) 2001 BBNT Solutions LLC
#
# Permission to use, copy, modify, and distribute this software
# and its documentation for any purpose is hereby granted without
# fee, provided that the above copyright notice and this permission
# appear in all copies and in supporting documentation, and that the
# name of BBN Technologies not be used in advertising or publicity
# pertaining to distribution of the software without specific,
# written prior permission.  BBN makes no representations about the
# suitability of this software for any purposes.  It is provided "AS
# IS" without express or implied warranties.
#
# Mark Allman (mallman@acm.org)
# BBN Technologies
#
# Last Updated: Thu Mar  9, 2006

# General variables...

CC=gcc
CFLAGS=-g -Wall -Werror -Iinclude -I/sw/include # -DTRANSFORM
LD=$(CC)
LDFLAGS=$(CFLAGS)
LIBS=-lreadline -ltermcap -lm
LIBS=-L/usr/local/lib -L/sw/lib -lreadline -ltermcap -lm
LIBS=-L/usr/lib -L/usr/local/lib -L/sw/lib -lreadline -lm -ltermcap
VERS=2.6
VERSION=\"$(VERS)\"
STATS_EXE=stats
STATS_OBJS=a2.o a2-hooks.o base.o basic.o batch.o cdf.o clear.o cmd.o \
	dump.o freq.o help.o input.o interactive.o ks-fit.o output.o \
	percentile.o qsort.o script.o set.o stats.o total.o \
	transform.o trim.o
STATS_HDR=include/stats.h
ANOVA_EXE=anova
ANOVA_OBJS=anova.o
ANOVA_HDR=include/anova.h
DUMPDIFF_EXE=dumpdiff
DUMPDIFF_OBJS=dumpdiff.o util.o
LESQ_EXE=lesq
LESQ_OBJS=lesq.o
TRANSFORM_EXE=transform
TRANSFORM_OBJS=trans.o util.o
UTIL_HDR=include/util.h
DEFAULT_PRGS=$(STATS_EXE) $(DUMPDIFF_EXE) $(LESQ_EXE) $(TRANSFORM_EXE)

# Compilation rules

all: $(DEFAULT_PRGS)

# stats

$(STATS_EXE): $(STATS_OBJS)
	$(LD) $(LDFLAGS) -o $(STATS_EXE) $(STATS_OBJS) $(LIBS)

a2.o: src/a2.c
	$(CC) $(CFLAGS) -c src/a2.c

a2-hooks.o: src/a2-hooks.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/a2-hooks.c

base.o: src/base.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/base.c

basic.o: src/basic.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/basic.c

batch.o: src/batch.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/batch.c

cdf.o: src/cdf.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/cdf.c

clear.o: src/clear.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/clear.c

cmd.o: src/cmd.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/cmd.c

dump.o: src/dump.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/dump.c

freq.o: src/freq.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/freq.c

help.o: src/help.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/help.c

input.o: src/input.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/input.c

interactive.o: src/interactive.c $(STATS_HDR)
	$(CC) $(CFLAGS) -DVERSION=$(VERSION) -c src/interactive.c

ks-fit.o: src/ks-fit.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/ks-fit.c

output.o: src/output.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/output.c

percentile.o: src/percentile.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/percentile.c

qsort.o: src/qsort.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/qsort.c

script.o: src/script.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/script.c

set.o: src/set.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/set.c

stats.o: src/stats.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/stats.c

total.o: src/total.c
	$(CC) $(CFLAGS) -c src/total.c

transform.o: src/transform.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/transform.c

trim.o: src/trim.c $(STATS_HDR)
	$(CC) $(CFLAGS) -c src/trim.c

# generic stuff

util.o: src/util.c $(UTIL_HDR)
	$(CC) $(CFLAGS) -c src/util.c

# anova

$(ANOVA_EXE): $(ANOVA_OBJS)
	$(LD) $(LDFLAGS) -o $(ANOVA_EXE) $(ANOVA_OBJS) $(LIBS)

anova.o: src/anova.c $(ANOVA_HDR)
	$(CC) $(CFLAGS) -c src/anova.c

# dumpdiff 

$(DUMPDIFF_EXE): $(DUMPDIFF_OBJS)
	$(LD) $(LDFLAGS) -o $(DUMPDIFF_EXE) $(DUMPDIFF_OBJS) $(LIBS)

dumpdiff.o: src/dumpdiff.c $(UTIL_HDR)
	$(CC) $(CFLAGS) -DVERSION=$(VERSION) -c src/dumpdiff.c

# lesq

$(LESQ_EXE): $(LESQ_OBJS)
	$(LD) $(LDFLAGS) -o $(LESQ_EXE) $(LESQ_OBJS) $(LIBS)

lesq.o: src/lesq.c
	$(CC) $(CFLAGS) -DVERSION=$(VERSION) -c src/lesq.c

# transform

$(TRANSFORM_EXE): $(TRANSFORM_OBJS)
	$(LD) $(LDFLAGS) -o $(TRANSFORM_EXE) $(TRANSFORM_OBJS) $(LIBS)

trans.o: src/trans.c $(UTIL_HDR)
	$(CC) $(CFLAGS) -DVERSION=$(VERSION) -c src/trans.c

# make release tarballs

tar: 
	$(MAKE) clobber
	tar cf stats$(VERS).tar --exclude CVS Makefile README ChangeLog src/ include/
	mkdir stats$(VERS)
	cd stats$(VERS); tar xf ../stats$(VERS).tar; cd ..
	rm -f stats$(VERS).tar
	tar cf stats$(VERS).tar stats$(VERS)/
	rm -rf stats$(VERS)
	gzip stats$(VERS).tar

# installing rules

install: $(DEFAULT_PRGS)
	for I in $^ ; \
	do \
		install $${I} /usr/local/bin ; \
	done

# Cleaning rules...

clean:
	rm -f *.o lex.yy.c y.tab.c y.tab.h y.output *core

clobber: clean
	rm -f $(STATS_EXE) $(ANOVA_EXE) $(DUMPDIFF_EXE) $(LESQ_EXE) \
		$(TRANSFORM_EXE)
	cd tests; $(MAKE) distclean; cd ..

distclean: clobber
