#! smake
#
# Copyright (c) Mark J. Kilgard, 1995, 1998.
#
include $(ROOT)/usr/include/make/commondefs

# NOTE:  In my GLUT development tree, many of the C source files for
# GLUT are generated.  For this reason, "make full_clobber" will remove
# these generated C files, while "make clobber" will not.

TOP = ../..

TARGETS = libglut.a

LN = ln -s
MV = mv
RM = -rm -rf

HDRS = glutint.h glutstroke.h layerutil.h glutbitmap.h

SRCS = \
	glut_bitmap.c \
	glut_bwidth.c \
	glut_cindex.c \
	glut_cmap.c \
	glut_cursor.c \
	glut_dials.c \
	glut_dstr.c \
	glut_event.c \
	glut_ext.c \
	glut_fbc.c \
	glut_fullscrn.c \
	glut_gamemode.c \
	glut_get.c \
	glut_glxext.c \
	glut_init.c \
	glut_input.c \
	glut_joy.c \
	glut_key.c \
	glut_keyctrl.c \
	glut_keyup.c \
	glut_menu.c \
	glut_menu2.c \
	glut_mesa.c \
	glut_modifier.c \
	glut_overlay.c \
	glut_shapes.c \
	glut_space.c \
	glut_stroke.c \
	glut_swap.c \
	glut_swidth.c \
	glut_tablet.c \
	glut_teapot.c \
	glut_util.c \
	glut_vidresize.c \
	glut_warp.c \
	glut_win.c \
	glut_winmisc.c \
	layerutil.c

SRCSSEMIGENS = \
	glut_8x13.c \
	glut_9x15.c \
	glut_hel10.c \
	glut_hel12.c \
	glut_hel18.c \
	glut_mroman.c \
	glut_roman.c \
	glut_tr10.c \
	glut_tr24.c

OBJS = $(SRCS:.c=.o) $(SRCSSEMIGENS:.c=.o)
OTHERGENS = y.tab.c y.tab.h strokegen.c strokegen.h strokelex.c
OTHERSRCS = strokegen.y strokelex.l stroke.h
FONTS = Roman.stroke MonoRoman.stroke

# Uncomment the LCDEFS line below if you want to build a version of
# libglut.a that avoids using the SGI "fast atoms" optimization
# introduced in IRIX 6.3.  This optimization eliminates serveral X server
# round-trips.  If you are building libglut.a on an IRIX 6.3 or later
# machine and want a chance (no guarantees) that GLUT executables built
# against your libglut.a will work on IRIX 6.2 machines, uncomment out
# the LCDEFS line below.  Otherwise, you'll get a run-time message about
# "attempted access to unresolvable symbol in XXX: _XSGIFastInternAtom"
#LCDEFS = -DNO_FAST_ATOMS

LCOPTS = -I$(TOP)/include -fullwarn 
LWOFF = ,813,852,827,826
LDIRT = *~ $(OTHERGENS) strokegen *.bak hardcopy glutsrc.ps capturexfont *.pure dstr dstr.c *.gen

default: $(TARGETS)

sinclude ObjectType.mk

$(OBJS) : $(HDRS)

libglut.a : $(OBJS)
	$(RM) $@
	$(AR) crl $@ $(OBJS)

.ORDER : strokegen.h strokegen.c

strokegen.h strokegen.c : strokegen.y
	$(YACC) -d strokegen.y
	$(MV) y.tab.c strokegen.c
	$(MV) y.tab.h strokegen.h

# avoid warnings when compiling lex generated code
strokegen.o : strokegen.c
	$(CC) $(CFLAGS) -woff 726,825,635,818,819,820,824,831,835,822,821,1167,1498,1116,1136,1174,1196,803 -c -MDupdate Makedepend strokegen.c

strokelex.c : strokelex.l
	$(LEX) strokelex.l
	$(MV) lex.yy.c strokelex.c

# avoid warnings when compiling lex generated code
strokelex.o : strokelex.c
	$(CC) $(CFLAGS) -woff 831,825,817,835,702,819,635,824,822,1167,1498,1110,1196,1174,803 -c -MDupdate Makedepend strokelex.c

strokegen : strokegen.o strokelex.o
	$(CC) -o $@ $(LDFLAGS) strokegen.o strokelex.o -ll

capturexfont : capturexfont.o
	$(CC) -o $@ $(LDFLAGS) capturexfont.o -lX11

# glut_roman.c and glut_mroman.c are now checked in, but here are rules to generate them
glut_roman.c.gen : Roman.stroke strokegen
	./strokegen -s glutStrokeRoman < Roman.stroke > $@
glut_mroman.c.gen : MonoRoman.stroke strokegen
	./strokegen -s glutStrokeMonoRoman < MonoRoman.stroke > $@

glutsrc.ps : $(SRCS)
	$(RM) hardcopy
	mkdir -p hardcopy
	for i in $(SRCS) ;\
	do \
	  grep -v CENTRY $$i | grep -v INDENT- > hardcopy/$$i; \
	done
	cd hardcopy ; enscript -p ../$@ -G -2r `echo $(SRCS) | fmt -1 | sort`
	$(RM) hardcopy

# The bitmap files can be generated using capturexfont, but because
# they require a connection to an X server and potentially different
# X servers have different fonts, these generated files are part
# of the GLUT distribution.

9_BY_15 = -misc-fixed-medium-r-normal--15-140-75-75-C-90-iso8859-1
8_BY_13 = -misc-fixed-medium-r-normal--13-120-75-75-C-80-iso8859-1
TR10 = -adobe-times-medium-r-normal--10-100-75-75-p-54-iso8859-1
TR24 = -adobe-times-medium-r-normal--24-240-75-75-p-124-iso8859-1
HEL10 = -adobe-helvetica-medium-r-normal--10-100-75-75-p-56-iso8859-1
HEL12 = -adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1
HEL18 = -adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1

semigens : capturexfont
	./capturexfont $(9_BY_15) glutBitmap9By15 > glut_9x15.c.gen
	./capturexfont $(8_BY_13) glutBitmap8By13 > glut_8x13.c.gen
	./capturexfont $(TR10) glutBitmapTimesRoman10 > glut_tr10.c.gen
	./capturexfont $(TR24) glutBitmapTimesRoman24 > glut_tr24.c.gen
	./capturexfont $(HEL10) glutBitmapHelvetica10 > glut_hel10.c.gen
	./capturexfont $(HEL12) glutBitmapHelvetica12 > glut_hel12.c.gen
	./capturexfont $(HEL18) glutBitmapHelvetica18 > glut_hel18.c.gen

# unused test rule for test building 16-bit font
JIS = -jis-fixed-medium-r-normal--24-230-75-75-c-240-jisx0208.1983-0
glut_jis.c : 
	./capturexfont $(JIS) glutBitmapJis > $@

sources: $(SRCS)

symcheck: libglut.a
	-nm -Bo libglut.a | grep -v ' d ' | grep -v ' T glut' | grep -v ' D glut' | grep -v ' U ' | grep -v ' T __glut' | grep -v ' t ' | grep -v ' b ' | grep -v ' D __glut' | grep -v ' B __glut'

dstr.c: glut_dstr.c
	ln -s glut_dstr.c $@

dstr: dstr.c glut_util.o glut_glxext.o
	$(RM) $@
	$(CC) -g -o $@ $(CFLAGS) -DTEST dstr.c glut_util.o glut_glxext.o -lGLU -lGL -lXext -lX11 -lm

./glut.h : glut.h
./glutint.h : glutint.h
./glutstroke.h : glutstroke.h
./strokegen.h : strokegen.h
./stroke.h : stroke.h
./layerutil.h : layerutil.h
strokelex.o: strokelex.c strokegen.h

include $(COMMONRULES)
