#***************************************************************************
# Imakefile for P3D
# Copyright 1989, Pittsburgh Supercomputing Center, Carnegie Mellon University
# Authors Chris Nuuja and Joel Welling
#
# Permission use, copy, and modify this software and its documentation
# without fee for personal use or use within your organization is hereby
# granted, provided that the above copyright notice is preserved in all
# copies and that that copyright and this permission notice appear in
# supporting documentation.  Permission to redistribute this software to
# other organizations or individuals is not granted;  that must be
# negotiated with the PSC.  Neither the PSC nor Carnegie Mellon
# University make any representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#
#***************************************************************************
# Installer should not have to change anything in this file
#---------------------------------------------------------------------+

SUBIMAKES= painter rayshade sgigl_utils

DUI=	/opt/demo/dui

DUI_LIBS= user_parse.o \
	$(DUI)/Render.o \
	$(DUI)/Dialbox.o\
	$(DUI)/Spaceball.o \
	$(DUI)/MkStudios.o \
	$(DUI)/Minivas.o \
	$(DUI)/ParseArg.o \
	$(DUI)/Ui.o \
	$(DUI)/PaintInstr.o \
	$(DUI)/Stop.o \
	$(DUI)/Butt.o \
	$(DUI)/Knobs.o \
	$(DUI)/MkModels.o \
	$(DUI)/Trnsfrmr.o

DORE=	/usr/lib/dore.o

PAINTER= painter/painter_ren.o painter/painter.o painter/painter_clip.o \
	painter/painter_util.o painter/paintr_trans.o

RAYSHADE= rayshade/ray_ren.o rayshade/setup.o rayshade/viewing.o \
	rayshade/object.o rayshade/bounds.o rayshade/voxels.o \
	rayshade/surface.o rayshade/raymath.o rayshade/matrix.o \
	rayshade/raytrace.o rayshade/intersect.o rayshade/grid.o \
	rayshade/cylinder.o rayshade/poly.o rayshade/memory.o \
	rayshade/sphere.o rayshade/triangle.o rayshade/shade.o \
	rayshade/light.o rayshade/outputp.o rayshade/list.o rayshade/box.o

GL_UTILS= sgigl_utils/knobs.o sgigl_utils/button.o sgigl_utils/slider.o \
	sgigl_utils/dialog.o

#if (WHICH_RENDERER==PHIGS_REN)
SUBMAKES= 
RENDERER= phigs_ren.o
#endif

#if (WHICH_RENDERER==SUN_PHIGS_REN)
SUBMAKES= 
RENDERER= sphigs_ren.o
#endif

#if (WHICH_RENDERER==DEC_PHIGS_REN)
SUBMAKES=
RENDERER= dphigs_ren.o
#endif

#if (WHICH_RENDERER==SGIGL_REN)
SUBMAKES= sgigl_utils
RENDERER= sgigl_ren.o
CFLAGS= $(ENV_CFLAGS) $(COPTIONS) -DRENDERER_IS_GL
#endif

#if (WHICH_RENDERER==DORE_REN)
SUBMAKES=
RENDERER= dore_ren.o $(DORE)
#endif

#if (WHICH_RENDERER==PAINTER_REN)
SUBMAKES= painter
RENDERER= $(PAINTER) $(DRAWCGM)
#endif

#if (WHICH_RENDERER==RAYSHADE_REN)
SUBMAKES= rayshade
RENDERER= $(RAYSHADE) $(DRAWCGM)
#endif

#if (WHICH_RENDERER==RENDERMAN_REN)
SUBMAKES=
RENDERER= rendermn_ren.o
#endif

#if (WHICH_RENDERER==ART_REN)
SUBMAKES=
RENDERER= art_ren.o indent.o
#ifdef sun
/* We need to not include XLIBS, because Sun linker will complain about
 * missing shared objects.
 */
#define WHICH_UI KEYBOARD_UI
XLIBS=
#endif
#endif

#if (WHICH_UI==SGIGL_UI)
UI= mouse_ui.o sgigl_mi.o $(GL_UTILS)
#endif

#if (WHICH_UI==XVIEW_UI)
UI= mouse_ui.o xview_mi.o
#endif

#if (WHICH_UI==MOTIF_UI)
UI= mouse_ui.o motif_mi.o motif_view.o motif_flyby.o flyby.o
#endif

#if (WHICH_UI==DORE_UI)
UI= dore_ui.o $(DUI_LIBS)
#endif

#if (WHICH_UI==KEYBOARD_UI)
UI= kui.o
#endif

#if (WHICH_UI==FLYING_UI)
UI= fui.o
#endif

#if (WHICH_UI==ROCKET_UI)
UI= rui.o
#endif

CONTROLLERS= tty.o dq.o lvr.o lvr_io.o

RENDER_DEFS=   -Dincp3d

ALISP = interp.o construct.o prims.o alisp_util.o env.o mem.o \
	lexer.o parse.o scan_token.o key.o ge_error.o alisp.o

P3D= render_ctrl.o matrix_ops.o p3d.o control.o assist.o assist_text.o \
	assist_spln.o assist_attr.o assist_nrml.o assist_mtrx.o \
	assist_colr.o material.o color.o vector.o point.o vertex.o \
	$(CONTROLLERS)

CSOURCE= alisp.c alisp_main.c alisp_util.c assist.c assist_attr.c \
	assist_colr.c assist_mtrx.c assist_nrml.c assist_spln.c assist_text.c \
	call_out.c construct.c control.c dore_ren.c dore_ui.c dphigs_ren.c \
	dq.c dump_ren.c env.c fui.c ge_error.c geom_spec.c indent.c interp.c \
	key.c kui.c lexer.c lvr.c lvr_io.c make_hershey.c matrix_ops.c mem.c \
	motif_mi.c mouse_ui.c p3d.c parse.c phigs_ren.c prims.c raydump_ren.c \
	render_ctrl.c rui.c scan_token.c sgigl_mi.c sgigl_ren.c sphigs_ren.c \
	syscall.c tdump_ren.c tty.c tui.c user_parse.c xview_mi.c material.c \
	art_ren.c rendermn_ren.c motif_view.c motif_flyby.c flyby.c \
	color.c vector.c point.c vertex.c

OTHER_SOURCE= hfonts.bin descrip.mms cc.opt data.button data.dial \
	data.explain

HFILES= alisp.h alisp_node.h assist.h control.h cylinder.h defs.h ge_error.h \
	hershey.h hfonts.h indent.h lvr_defines.h matrix_ops.h mi.h p3d.h \
	parse.h ren.h render_ctrl.h sphere.h syscall.h ui.h motif_mi.h \
	flyby.h flyby_preamble.h

LIB=	$(DEVLIBS) $(XLIBS) $(SLIBS) $(LIBOPTIONS)

EXECUTABLES=display-p3d render-p3d dump-p3d tdump-p3d alisp make_hershey

INSTALLABLES=display-p3d render-p3d dump-p3d tdump-p3d alisp

LOAD_PATH = '"$(ROOT_PATH)/load/"'

DEPEND_FLAGS= $(RENDER_DEFS)

all:: submakes display-p3d render-p3d dump-p3d tdump-p3d alisp hershey.h

hershey.h: make_hershey hfonts.bin
	./make_hershey

make_hershey: make_hershey.c hfonts.h
	$(CC) $(CFLAGS) -o make_hershey make_hershey.c

tdump-p3d: $(ALISP) call_render.o syscall.o $(P3D) tui.o tdump_ren.o \
	indent.o
	$(CC) -o tdump-p3d $(ALISP) call_render.o syscall.o tui.o \
		tdump_ren.o indent.o $(P3D) $(LIB)

dump-p3d: $(ALISP) call_render.o syscall.o $(P3D) tui.o dump_ren.o \
	indent.o
	$(CC) -o dump-p3d $(ALISP) call_render.o syscall.o tui.o \
		dump_ren.o indent.o $(P3D) $(LIB)

display-p3d:  $(ALISP) call_render.o syscall.o $(RENDERER) $(UI) $(P3D) 
	$(CC) -o display-p3d $(ALISP) call_render.o syscall.o \
		$(P3D) $(UI) $(RENDERER) $(LIB)

render-p3d:  $(ALISP) call_render.o syscall.o $(RENDERER) tui.o $(P3D) 
	$(CC) -o render-p3d $(DORE_DEFS) $(ALISP) call_render.o syscall.o \
		tui.o $(P3D) $(RENDERER) $(LIB)

alisp: $(ALISP) call_out.o syscall.o matrix_ops.o alisp_main.o 
	$(CC) -o  alisp $(ALISP) call_out.o syscall.o alisp_main.o -lm

/**/# Triggers for make of files in subdirectories
$(PAINTER): painter-trigger
	$(FILETEST) $@

painter-trigger:
	cd painter ; make

$(RAYSHADE): rayshade-trigger
	$(FILETEST) $@

rayshade-trigger:
	cd rayshade ; make

$(GL_UTILS): sgigl-trigger
	$(FILETEST) $@

sgigl-trigger:
	cd sgigl_utils ; make

/**/# Special make rules - call_render has same dependencies as call_out
call_render.o: call_out.o
	mv call_out.o call_sav.o
	$(CC) $(CFLAGS) -c $(RENDER_DEFS) call_out.c
	mv call_out.o call_render.o
	mv call_sav.o call_out.o

prims.o:
	$(CC) $(CFLAGS) -c -DLOAD_PATH=$(LOAD_PATH) prims.c








