#
# Makefile for dvi previewer.
#

# The following seven lines are the crucial ones.
OSDEFS=-DMSBITFIRST
OPTIONDEFS=-DUSE_PK -DBUTTONS -DGREY
DEFAULT_FONT_PATH=/usr/local/tex/fonts
DEFAULT_VF_PATH=/usr/local/tex/fonts/vf
DEFAULT_FONT_SIZES=$(SIZES300)
DEFAULT_FIG_PATH=/usr/local/tex/inputs
DEFAULT_HEADER_PATH=/usr/local/tex/ps

# CC=cc
LINT=lint
# LINT=$(CC) -c -Wall -Wshadow -Wpointer-arith
# also maybe -Wcast-qual -Wwrite-strings
RM=rm -f
INSTALL=install

TOP=/usr/X11
OPENWINTOP=/usr/openwin
INCDIR=$(TOP)/include
LIBDIR=-L$(TOP)/lib
LIBXAW=-lXaw
XMULIB=-lXmu
EXTENSIONLIB=-lXext
DESTDIR=$(TOP)
BINDIR=$(DESTDIR)/bin
MANDIR=$(DESTDIR)/man
MANEXT=1
INCLUDES=-I$(INCDIR)

DEFS=$(OSDEFS) $(OPTIONDEFS)
FONTDEFINES=-DDEFAULT_FONT_PATH=\"$(DEFAULT_FONT_PATH)\" \
  -DDEFAULT_VF_PATH=\"$(DEFAULT_VF_PATH)\" \
  -DDEFAULT_FONT_SIZES=\"$(DEFAULT_FONT_SIZES)\" \
  -DDEFAULT_SUBDIR_PATH=\"$(DEFAULT_SUBDIR_PATH)\" \
  -DDEFAULT_FIG_PATH=\"$(DEFAULT_FIG_PATH)\" \
  -DDEFAULT_HEADER_PATH=\"$(DEFAULT_HEADER_PATH)\"
CFLAGS=-O $(INCLUDES) $(DEFS)
LIBS=$(LIBDIR) $(VARLIBS) -lX11 -lm

#
# Nothing below this line should need to be changed by the user.
#

# Sizes for magstephalf and magsteps 0..5.
SIZES72=72:79:86:104:124:149:179
SIZES85=85:93:102:122:147:176:212
SIZES118=118:129:142:170:204:245
SIZES300=300:329:360:432:518:622:746
SIZES400=400:438:480:576:691:829:995
SIZES600=600:657:720:864:1037:1244:1493

default: xdvi

config:
	./mkconfig make $(DEFS)

Makefile.cfg: Makefile mkconfig
	./mkconfig make $(DEFS)

include Makefile.cfg

SRCS=xdvi.c events.c dvi_init.c dvi_draw.c special.c font_open.c vf.c util.c \
  $(VARSRCS)
OBJS=xdvi.o events.o dvi_init.o dvi_draw.o special.o font_open.o vf.o util.o \
  $(VAROBJS)

.c.o:
	$(CC) -c $(CFLAGS) $*.c

xdvi:	$(OBJS)
	$(CC) $(CFLAGS) -o xdvi $(OBJS) $(LIBS)
	chmod go+rx xdvi

xdvi.o: xdvi.h patchlevel.h xdvi.icon
events.o: xdvi.h
dvi_init.o:xdvi.h dvi.h
dvi_draw.o:xdvi.h dvi.h
special.o:xdvi.h
vf.o:	xdvi.h dvi.h
util.o:	xdvi.h
pk.o:	xdvi.h
gf.o:	xdvi.h
psdps.o:xdvi.h
psnews.o:xdvi.h
psgs.o:	xdvi.h

font_open.o:	font_open.c xdvi.h
	$(CC) -c $(CFLAGS) $(FONTDEFINES) font_open.c

psheader.c:	psheader.txt squeeze
	./squeeze psheader.txt psheader.c

squeeze:	squeeze.c
	$(CC) $(CFLAGS) -o squeeze squeeze.c

xdvi.man: xdvi_man.sed mksedscript
	chmod u+x mksedscript
	./mksedscript "$(DEFAULT_FONT_PATH)" $(DEFAULT_FONT_SIZES) \
		"$(DEFAULT_VF_PATH)" "$(DEFAULT_FIG_PATH)" \
		"$(DEFAULT_HEADER_PATH)" $(DEFS) > sedscript
	sed -f sedscript < xdvi_man.sed > xdvi.man

install: xdvi xdvi.man
	$(INSTALL) -s -m 755 xdvi $(BINDIR)
	$(INSTALL) -m 644 xdvi.man $(MANDIR)/man$(MANEXT)/xdvi.$(MANEXT)

uninstall:
	$(RM) $(BINDIR)/xdvi $(MANDIR)/man$(MANEXT)/xdvi.$(MANEXT)

TAGS:	$(srcs)
	etags $(srcs)

clean:
	$(RM) *.o xdvi xdvi.man core sedscript psheader.c squeeze *~

mostlyclean:
	$(RM) *.o xdvi xdvi.man core sedscript *~

distclean: clean
	$(RM) Makefile.cfg

veryclean: distclean
	$(RM) TAGS

realclean: distclean
	$(RM) TAGS

lint: psheader.c
	$(LINT) $(INCLUDES) $(DEFS) $(FONTDEFINES) $(SRCS) -lm
