# Makefile  to build a module
# locate in the source (/src) directory for a bundle
#
# Copyright (C) 1992, California Institute of Technology.
# U.S. Government Sponsorship under NASA Contract NAS7-918
# is acknowledged.
#
# OPSDIR, CONFIGROOT, and SUPERDIR are inherited from ../Makefile
#

# Insert the name of this Bundle as MODULE
MODULE= autoflat
# Almost always needed, ok to change per Bundle needs
#LIBS=		-L/home/rick/lib -lNRec -lm -lc
LIBS=		-lm
IMLIB=          ../../../lib/libim.a
#IM_DIR is directory containing sources for image access library
IM_DIR=  ../../../src/IM

OPSDIR=         /usr/local/ops
LDIR=           $(OPSDIR)/lib
INCLUDEDIR=     $(OPSDIR)/include
# Local libraries
#ILIBS=          $(LDIR)/par.a $(LDIR)/im.a $(LDIR)/libreaux.a
ILIBS=           $(LDIR)/im.a $(LDIR)/par.a $(LDIR)/libreaux.a

# Where to Install it
INSTALLDIR=/dsg/Imaging/config/beta
#
BINDIR=$(INSTALLDIR)/bin
#
MANDIR=$(INSTALLDIR)/man

#CFLAGS=         -f
CFLAGS=         -O

LINTFLAGS=	-h

CFILES= conduct.c main.c flatten.c istats.c ihist.c ptile.c hdrclean.c \
    getimaginfo.c squawk.c nlengths.c

OBJS= conduct.o main.o flatten.o istats.o ihist.o ptile.o hdrclean.o \
    getimaginfo.o squawk.o nlengths.o

SPECIALS= flatten.h

$(MODULE): $(OBJS) $(IMLIB)
	cc -o $(MODULE) $(OBJS)  $(IMLIB) $(LIBS)
$(IMLIB):
	(cd $(IM_DIR); make install )
#	(cd $(IM_DIR); make RANLIB=$(RANLIB) "CFLAGS=$(CFLAGS)" install )

# This is required by higher level makes, it must leave a help.txt
# file in the bundle src directory, even it that means doing nothing
help.txt:help.nrf
	nroff -man help.nrf | colcrt - > help.txt

install: installbin installman

installbin: $(MODULE)
	install -m 755 $(MODULE) $(BINDIR)

installman:
	install -m 644 ../man/man1/$(MODULE).1 $(MANDIR)/man1

# Godliness...
clean :
	rm -f $(OBJS) core a.out

veryclean :
	rm -f $(OBJS) core a.out $(MODULE)

ctags :
	ctags $(CFILES) $(INCLUDES) $(SPECIALS)

lint : $(CFILES)
	lint $(LINTFLAGS) $(CFILES) $(LIBS)

print :	filelist $(CFILES) $(INCLUDES) $(SPECIALS)
	lpr $?

printall: filelist
	pr filelist Makefile $(CFILES) $(INCLUDES) $(SPECIALS) | lpr

filelist  : $(CFILES) $(SPECIALS)
	rm -f filelist
	for i in $(CFILES) $(INCLUDES) $(SPECIALS);  do \
	 echo $$i >> filelist; done

depend:
	${CC} -M ${CFLAGS} ${CFILES} | \
	sed -e ':loop' \
	    -e 's/\.\.\/[^ /]*\/\.\./../' \
	    -e 't loop' | \
	awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
		else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
		       else rec = rec " " $$2 } } \
	      END { print rec } ' > makedep
	echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	cp Makefile Makefile.bak
	ex - Makefile < eddep
	rm eddep makedep



# DO NOT DELETE THIS LINE -- make depend uses it
# IF YOU PUT STUFF HERE IT WILL GO AWAY
# This is just primer, it will go away.
