# Makefile for conversion programs
#

# DEST is where to install the tools 
# RI is the include directory for RLE files
# RL is the library directory (for librle.a)
# TI is the tex include directory
DEST = ../../../bin
RI = ../../include
RL = ../../lib
TI = ../h

# For systems without bcopy and bzero, librle.a has substitutes
LIBES=  ../lib/lib.a $(RL)/librle.a

# Add -Dhpux to avoid HP compiler bugs
CFLAGS = -O $(DFLAGS) $(IFLAGS)
IFLAGS = -I. -I$(RI) -I$(TI)

# System V make pays attention to the SHELL environment variable. Override it.
SHELL = /bin/sh
MAKE=	make

# Executable programs
PGMS= dvirle1.out dvirle2.out dviselect.out
SCRIPTS= dvirle.sh topcrop.sh 

SRCS=	dvirle1.c dvirle2.c dviselect.c

default:  all

all:	$(PGMS)

# Clean up installed stuff and binaries
pristine: clean
	for pgm in $(SCRIPTS); do rm -f $(DEST)/`basename $$pgm .sh`; done
	for pgm in $(PGMS); do rm -f $(DEST)/`basename $$pgm .out`; done
	-rm -f install*

# Clean up binaries
clean:
	-rm -f core *.o $(PGMS)

makefile:
depend:

# Everything depends on the svfb globals and libraries.
# Also depend on the .h files in $(TI) (This may break your make)
$(PGMS): $(RI)/svfb_global.h $(LIBES) $(TI)/*.h

install: install-pgms install-scripts
	touch install

install-scripts: $(SCRIPTS)
	for pgm in $?; do d=$(DEST)/`basename $$pgm .sh`; \
		cp $$pgm $$d; chmod +x $$d; done
	touch install-scripts

install-pgms: $(PGMS)
	for pgm in $?; do cp $$pgm $(DEST)/`basename $$pgm .out`; done
	touch install-pgms

dviselect.out: dviselect.c
	${CC} ${CFLAGS} -o dviselect.out dviselect.c $(LIBES)

# Default rule for making a program from its .c file.
# The mv will not be done if there is an error, so a broken program
# will not be left around.
.SUFFIXES:
.SUFFIXES: .out .c
.c.out:
	$(CC) $(CFLAGS) $< $(LIBES) -lm -o $*.new
	mv $*.new $@
