#######
# Where the executable goes
BINDIR=/usr/local/bin

#######
# Man pages

MANDIR=/usr/local/man/man1
MANEXT=1

#######
# CC
CC=gcc

#######
# Define's
# Define STRINGS if <strings.h> is to be used in place of <string.h>
# Define NOMEM if <memory.h> isn't available.
# Define EBCDIC if that character set is used.
DEFS =  -D_HPUX_SOURCE # -DNOMEM -DSTRINGS # -DEBCDIC

# Sizes of shorts, ints, longs.  (This has to be a #define: the sizeof
# operator isn't sufficient because we need to use the sizes in the argument
# to a #if expression.)
SIZES = -DL_SHORT=2 -DL_INT=4 -DL_LONG=4


#######
# CFLAGS
# Always keep $(DEFS) and $(SIZES) in CFLAGS
CFLAGS = -O $(DEFS) $(SIZES)

#######
# LDFLAGS,LDLIBS

LDFLAGS=
LDLIBS=


####################################################################
# You shouldn't have to modify anything below this line.
####################################################################

VIZOBJS = viz.o vizgrammar.o lists.o loadfile.o viz_decode.o
VIZ_H = viz.h dep.h translate.h string.h memory.h version.h
VIZSRC = viz.c vizgrammar.y lists.c loadfile.c viz_decode.c
VIZSRC_C = viz.c vizgrammar.c lists.c loadfile.c viz_decode.c

INVIZOBJS = inviz.o strtou.o strtod.o inviz_text.o inviz_num.o
INVIZSRC = inviz.c strtou.c strtod.c inviz_text.c inviz_num.c

ALL = README INSTALL Artistic Copying WhatsNew Makefile viz.1 inviz.1 $(VIZSRC) $(INVIZSRC) $(VIZ_H)

all: viz inviz

lint: $(VIZSRC_C)
	lint -h $(VIZSRC_C) > lint.out

viz:	$(VIZOBJS)
	$(CC) $(LDFLAGS) $(DEFS) $(VIZOBJS) -o viz

viz.o:	viz.h translate.h

vizgrammar.o:	viz.h

# For producing a .c file for lint to work on.
vizgrammar.c: vizgrammar.y
	@ echo "** Expect 4 shift/reduce conflicts **"
	yacc vizgrammar.y
	mv y.tab.c vizgrammar.c

lists.o:	viz.h

viz.h:	dep.h
	@ touch viz.h

inviz:	$(INVIZOBJS)
	$(CC) $(LDFLAGS) $(INVIZOBJS) -lm -o inviz

inviz.o:	viz.h translate.h

viz_decode.o: viz.h translate.h
	$(CC) $(CFLAGS) -DVIZ -c viz_decode.c

inviz_text.o: viz.h translate.h
	$(CC) $(CFLAGS) -c inviz_text.c

inviz_num.o: viz.h translate.h
	$(CC) $(CFLAGS) -c inviz_num.c

install: viz inviz
	cp viz $(BINDIR) && chmod 755 $(BINDIR)/viz
	cp inviz $(BINDIR) && chmod 755 $(BINDIR)/inviz
	cp viz.1 $(MANDIR)/viz.$(MANEXT) && \
		chmod 644 $(MANDIR)/viz.$(MANEXT)
	cp inviz.1 $(MANDIR)/inviz.$(MANEXT) && \
		chmod 644 $(MANDIR)/inviz.$(MANEXT)

clean:
	rm -f *.o viz inviz y.tab.c y.tab.h

# Because of the wide variation in shar commands, the shar arguments
# used below sticks to a minimal set, and we generate various shar file
# headers by hand.
shar: $(ALL)
	( echo "#include <stdio.h>" ; \
	echo '#include "version.h"' ; \
	echo 'main() {printf("%s.%s\\n",Version,Patchlevel);exit(0);}') > temp.c
	cc temp.c
	V=viz-`a.out`; mkdir $$V && cp $(ALL) $$V && \
	    (echo "Submitted-by: will@nfra.nl" ; \
	    echo "Archive-name: $$V/part01" ; echo "" ; \
	    echo "---- Cut Here and feed the following to sh ----" ; \
	    shar $$V ) > $$V.shar && rm -rf $$V
	rm a.out temp.c
