# Description file for rle tool programs. ($rtools)

#
# DEST is where to install the tools 
# RI is the include directory for RLE files
# RL is the library directory (for librle.a)

DEST = ../../bin
RI = ../include
RL = ../lib

LIBES = $(RL)/librle.a
CFLAGS = -O $(DFLAGS) $(IFLAGS)
IFLAGS = -I. -I$(RI)
# System V make pays attention to the SHELL environment variable. Override it.
SHELL = /bin/sh

# Executables.  The .out will be stripped off in the install action.
PGMS = 	applymap.out \
	avg4.out \
	comp.out \
	crop.out \
	fant.out \
	mcut.out \
	mergechan.out \
	pyrmask.out \
	repos.out \
	rleClock.out \
	rleaddcom.out \
	rlebg.out \
	rlebox.out \
	rleflip.out \
	rlehdr.out \
	rlehisto.out \
	rleldmap.out \
	rlemandl.out \
	rlenoise.out \
	rlepatch.out \
	rlescale.out \
	rlesetbg.out \
	rlesplit.out \
	rleswap.out \
	rlezoom.out \
	smush.out \
	to8.out \
	tobw.out \
	unexp.out \
	unslice.out

# Default is what is to be made if nothing is specified.
default: $(PGMS)

makefile:
depend:

# Everything depends on the svfb globals and libraries.
$(PGMS): $(RI)/svfb_global.h $(LIBES)

# A couple programs also depend on the getraw definitions.
applymap.out rlebg.out: $(RI)/rle_getraw.h

# Pyrmask comes in pieces, must be built special.

pyrlib.o: pyrlib.c $(RI)/pyramid.h $(RI)/svfb_global.h
	$(CC) $(CFLAGS) pyrlib.c -c
pyrmask.out: pyrlib.o pyrmask.c $(RI)/pyramid.h $(LIBES)
	$(CC) $(CLFAGS) -I$(RI) pyrmask.c pyrlib.o $(LIBES) -lm -o pyrmask.new
	mv pyrmask.new pyrmask.out

# rleClock has it's own directory, must be built special

rleClock.out: clock/font.c clock/font.h clock/font.src clock/rleClock.c
	(cd clock ; make)

# Incremental install, copies everything ("$?") since last install to DEST dir.
install: $(PGMS)
	for pgm in $?; do cp $$pgm $(DEST)/`basename $$pgm .out`; done
	touch install

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

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

# 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 $@
