############################################################################
#
# Makefile for XPLOT program.
#

# The directory that xplot goes to on a "make install"
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/man/man1

# The filename of the helpfile. Used for copying on a "make install" and
# as the filename in the sources.
HELPDIR = $(PREFIX)/share/xplot
HELPFILE = $(HELPDIR)/xplot.help

# If you want xplot to auto-daemonize (go to background) when started,
# uncomment the following
DAEMONIZE = -DDAEMONIZE

# Two variables to find the forms library and headers.
# You will need the library and header to compile XPlot. You can ftp them
# from ftp://bloch.phys.uwm.edu/pub/xforms or
# ftp://ftp.cs.ruu.nl/pub/XFORMS.
#
# The directory that you keep forms.h, if it's not a system-include directory.
# Prefix this name with -I, e.g.:
# FORM_INCLUDE = -I/usr/local/X11/include

# The directory where you keep libforms.a, if it's a non-system library
# dir. Prefix this name with -L, e.g.:
FORM_LIB = -L/usr/X11R6/lib

# Next, we need the libfli.a library and fli.h, the ICCE Add-ons for
# XForms. The sources are incuded here, and built here.  For your own
# projects, You can ftp it from ftp://ftp.icce.rug.nl/pub/unix.
#
# The directory where you have the ICCE XForms add-ons include file, e.g.:
# FLI_INCLUDE = -I/usr/local/X11/include
FLI_INCLUDE = -I../libfli/lib

# The directory where you have the ICCE XForms add-ons, e.g.:
# FLI_LIB = -L/usr/local/X11/lib
FLI_LIB = -L../libfli/lib

# The rest should be OK, no need to change.
#############################################################################

# current version, my task to change that
VER = 1.19

# C flag for debugging: -g gives gdb info, but "install -s" will strip when
# "make install" is done
CDEBUG = -g

# Linkage flags, default none
LDEBUG=

# object files we need
OBJ = error.o fgetline.o readfile.o usage.o xplot.o forms.o setrange.o \
      setlinetype.o checkranges.o  activatordone.o redrawplots.o \
      guessy.o redraw.o quit.o doblowup.o quitblowup.o setautoredraw.o \
      setboundary.o setinputstrings.o boundaries.o activatesets.o \
      setactive.o dohelp.o helpdone.o settitle.o warning.o showform.o

# compilation flags
CFLAGS = -O2 $(CDEBUG) -Wall \
    -DVER=\"$(VER)\" \
    -DHELPFILE=\"$(HELPFILE)\" \
    $(FORM_INCLUDE) $(FLI_INCLUDE) \
    $(DAEMONIZE)

# entry point
foobar:
	@echo 'Make what? Select:'
	@echo 'make xplot: make program in this dir, non-debug version'
	@echo 'make debug: make program in this dir, debug version'
	@echo 'make tests: make in this dir and run a couple of tests'
	@echo 'make clean: clean up stale files'
	@echo 'make install: make program and install it to $(BINDIR)'
	@echo 'make dist: make distribution, only for me (karel)'
	exit 1

../libfli/lib/libfli.a:
	(cd ../libfli/lib/; ./cbuild)

# executable
xplot: $(OBJ) ../libfli/lib/libfli.a
	$(CC) -o xplot $(OBJ) $(FORM_LIB) $(FLI_LIB) \
	    -lforms -lfli -lX11 -lm $(LDEBUG)

debug:
	make CDEBUG=-g LDEBUG=-static DAEMONIZE='' xplot

# tests to run
tests: xplot
	@echo Sine function..
	test/sine | ./xplot
	@echo 'Hit ENTER..'
	@read
	@echo Nontabulated line..
	test/nontab | ./xplot
	@echo 'Hit ENTER..'
	@read
	@echo Now for both..
	test/sine > /tmp/sine.data.out
	test/nontab > /tmp/nontab.data.out
	./xplot /tmp/sine.data.out /tmp/nontab.data.out
	@echo 'Hit ENTER..'
	@read
	rm -f /tmp/sine.data.out /tmp/nontab.data.out
	@echo Now lots of sines..
	test/lotsofsines
	./xplot /tmp/lotsofsines.data.out.*
	@echo 'Hit ENTER..'
	@read
	@echo 'Test series done!'
	rm -f /tmp/lotsofsines.data.out.*

# installation
install: $(BINDIR)/xplot $(HELPFILE)

$(BINDIR)/xplot: xplot
	install -s -m 755 xplot $(BINDIR)
	install -m 644 xplot.1 $(MANDIR)

$(HELPFILE): ../xplot.help
	install -d  $(HELPDIR)
	install -m 644 ../xplot.help $(HELPFILE)

# cleaning up
clean:
	rm -f $(OBJ) xplot ../libfli/lib/libfli.a

# distribution
dist: clean
	./.makedist $(VER)

# extra deps
plot.c: plot.fd
	fdesign -altformat -convert plot.fd

forms.o: forms.c plot.c
usage.o: usage.c Makefile
dohelp.o: dohelp.c Makefile
xplot.o: xplot.c Makefile
