# Makefile for the generic driver of AllegroGL

INCDIR = $(MESADIR_U)/include -I$(MESADIR_U)/src -I$(MESADIR_U)/src/swrast_setup

GL_LIB = $(LIB_DIR_U)/libMesaGL.a
GL_HEADERS = $(addprefix $(MESADIR_U)/include/GL/, gl.h glext.h)
GLU_LIB = $(LIB_DIR_U)/libMesaGLU.a
GLU_HEADERS = $(MESADIR_U)/include/GL/glu.h
GLUT_LIB = $(LIB_DIR_U)/libGLUT.a
AMESA_HEADER = $(addprefix -I, $(INCLUDE_DIR))

GL_CORE_SOURCES = \
	swrast_setup/ss_context.c \
	swrast_setup/ss_triangle.c \
	swrast_setup/ss_vb.c \
	api_arrayelt.c \
	api_loopback.c \
	api_noop.c \
	api_validate.c \
	accum.c \
	attrib.c \
	blend.c \
	buffers.c \
	clip.c \
	colortab.c \
	context.c \
	convolve.c \
	debug.c \
	depth.c \
	dispatch.c \
	dlist.c \
	drawpix.c \
	enable.c \
	enums.c \
	eval.c \
	extensions.c \
	feedback.c \
	fog.c \
	get.c \
	glapi.c \
	glthread.c \
	hash.c \
	hint.c \
	histogram.c \
	image.c \
	imports.c \
	light.c \
	lines.c \
	matrix.c \
	mmath.c \
	pixel.c \
	points.c \
	polygon.c \
	rastpos.c \
	state.c \
	stencil.c \
	texformat.c \
	teximage.c \
	texobj.c \
	texstate.c \
	texstore.c \
	texutil.c \
	varray.c \
	vtxfmt.c \
	math/m_debug_clip.c \
	math/m_debug_xform.c \
	math/m_eval.c \
	math/m_matrix.c \
	math/m_translate.c \
	math/m_vector.c \
	math/m_xform.c \
	array_cache/ac_context.c \
	array_cache/ac_import.c \
	swrast/s_aaline.c \
	swrast/s_aatriangle.c \
	swrast/s_accum.c \
	swrast/s_alpha.c \
	swrast/s_alphabuf.c \
	swrast/s_bitmap.c \
	swrast/s_blend.c \
	swrast/s_buffers.c \
	swrast/s_copypix.c \
	swrast/s_context.c \
	swrast/s_depth.c \
	swrast/s_drawpix.c \
	swrast/s_feedback.c \
	swrast/s_fog.c \
	swrast/s_histogram.c \
	swrast/s_imaging.c \
	swrast/s_lines.c \
	swrast/s_logic.c \
	swrast/s_masking.c \
	swrast/s_pixeltex.c \
	swrast/s_points.c \
	swrast/s_readpix.c \
	swrast/s_span.c \
	swrast/s_stencil.c \
	swrast/s_texture.c \
	swrast/s_texstore.c \
	swrast/s_triangle.c \
	swrast/s_zoom.c \
	tnl/t_array_api.c \
	tnl/t_array_import.c \
	tnl/t_context.c \
	tnl/t_eval_api.c \
	tnl/t_imm_alloc.c \
	tnl/t_imm_api.c \
	tnl/t_imm_debug.c \
	tnl/t_imm_dlist.c \
	tnl/t_imm_elt.c \
	tnl/t_imm_eval.c \
	tnl/t_imm_exec.c \
	tnl/t_imm_fixup.c \
	tnl/t_pipeline.c \
	tnl/t_vb_fog.c \
	tnl/t_vb_light.c \
	tnl/t_vb_normals.c \
	tnl/t_vb_points.c \
	tnl/t_vb_render.c \
	tnl/t_vb_texgen.c \
	tnl/t_vb_texmat.c \
	tnl/t_vb_vertex.c
ifneq ($(wildcard $(MESADIR)/docs/RELNOTES-5.0),)
GL_CORE_SOURCES += \
	api_eval.c \
	texcompress.c \
	vpexec.c \
	vpparse.c \
	vpstate.c \
	vsnprintf.c \
	tnl/t_vb_program.c
else
GL_CORE_SOURCES += \
	config.c \
	mem.c \
	math/m_debug_norm.c \
	math/m_debug_vertex.c \
	math/m_vertices.c \
	swrast/s_scissor.c \
	swrast/s_pb.c
endif

DRIVER_SOURCES = src/amesa/amesa.c \
	src/amesa/raster.c

GLU_C_SOURCES = \
	libutil/error.c		\
	libutil/glue.c		\
	libutil/mipmap.c	\
	libutil/project.c	\
	libutil/quad.c		\
	libutil/registry.c	\
	libtess/dict.c		\
	libtess/geom.c		\
	libtess/memalloc.c	\
	libtess/mesh.c		\
	libtess/normal.c	\
	libtess/priorityq.c	\
	libtess/render.c	\
	libtess/sweep.c		\
	libtess/tess.c		\
	libtess/tessmono.c
GLU_CC_SOURCES = \
	libnurbs/interface/bezierEval.cc		\
	libnurbs/interface/bezierPatch.cc		\
	libnurbs/interface/bezierPatchMesh.cc		\
	libnurbs/interface/glcurveval.cc		\
	libnurbs/interface/glinterface.cc		\
	libnurbs/interface/glrenderer.cc		\
	libnurbs/interface/glsurfeval.cc		\
	libnurbs/interface/incurveeval.cc		\
	libnurbs/interface/insurfeval.cc		\
	libnurbs/internals/arc.cc			\
	libnurbs/internals/arcsorter.cc			\
	libnurbs/internals/arctess.cc			\
	libnurbs/internals/backend.cc			\
	libnurbs/internals/basiccrveval.cc		\
	libnurbs/internals/basicsurfeval.cc		\
	libnurbs/internals/bin.cc			\
	libnurbs/internals/bufpool.cc			\
	libnurbs/internals/cachingeval.cc		\
	libnurbs/internals/ccw.cc			\
	libnurbs/internals/coveandtiler.cc		\
	libnurbs/internals/curve.cc			\
	libnurbs/internals/curvelist.cc			\
	libnurbs/internals/curvesub.cc			\
	libnurbs/internals/dataTransform.cc		\
	libnurbs/internals/displaylist.cc		\
	libnurbs/internals/flist.cc			\
	libnurbs/internals/flistsorter.cc		\
	libnurbs/internals/hull.cc			\
	libnurbs/internals/intersect.cc			\
	libnurbs/internals/knotvector.cc		\
	libnurbs/internals/mapdesc.cc			\
	libnurbs/internals/mapdescv.cc			\
	libnurbs/internals/maplist.cc			\
	libnurbs/internals/mesher.cc			\
	libnurbs/internals/monoTriangulationBackend.cc	\
	libnurbs/internals/monotonizer.cc		\
	libnurbs/internals/mycode.cc			\
	libnurbs/internals/nurbsinterfac.cc		\
	libnurbs/internals/nurbstess.cc			\
	libnurbs/internals/patch.cc			\
	libnurbs/internals/patchlist.cc			\
	libnurbs/internals/quilt.cc			\
	libnurbs/internals/reader.cc			\
	libnurbs/internals/renderhints.cc		\
	libnurbs/internals/slicer.cc			\
	libnurbs/internals/sorter.cc			\
	libnurbs/internals/splitarcs.cc			\
	libnurbs/internals/subdivider.cc		\
	libnurbs/internals/tobezier.cc			\
	libnurbs/internals/trimline.cc			\
	libnurbs/internals/trimregion.cc		\
	libnurbs/internals/trimvertpool.cc		\
	libnurbs/internals/uarray.cc			\
	libnurbs/internals/varray.cc			\
	libnurbs/nurbtess/directedLine.cc		\
	libnurbs/nurbtess/gridWrap.cc			\
	libnurbs/nurbtess/monoChain.cc			\
	libnurbs/nurbtess/monoPolyPart.cc		\
	libnurbs/nurbtess/monoTriangulation.cc		\
	libnurbs/nurbtess/partitionX.cc			\
	libnurbs/nurbtess/partitionY.cc			\
	libnurbs/nurbtess/polyDBG.cc			\
	libnurbs/nurbtess/polyUtil.cc			\
	libnurbs/nurbtess/primitiveStream.cc		\
	libnurbs/nurbtess/quicksort.cc			\
	libnurbs/nurbtess/rectBlock.cc			\
	libnurbs/nurbtess/sampleComp.cc			\
	libnurbs/nurbtess/sampleCompBot.cc		\
	libnurbs/nurbtess/sampleCompRight.cc		\
	libnurbs/nurbtess/sampleCompTop.cc		\
	libnurbs/nurbtess/sampleMonoPoly.cc		\
	libnurbs/nurbtess/sampledLine.cc		\
	libnurbs/nurbtess/searchTree.cc

GLUT_CORE_SOURCES = callback.c color.c font.c globals.c init.c menu.c models.c \
          overlay.c state.c teapot.c window.c

MESA_SAMPLES = accum bitmap1 bitmap2 blendxor copy depth    \
          eval fog line logo nurb olympic point  \
          prim quad select shape sphere star stencil stretch texture  \
          tri wave

GLU_CORE_SOURCES = $(GLU_C_SOURCES) $(GLU_CC_SOURCES)

GL_SOURCES = $(addprefix $(MESADIR_U)/src/,$(GL_CORE_SOURCES))
GL_OBJECTS = $(GL_SOURCES:.c=.o) $(OBJ_DIR_U)/amesa.o $(OBJ_DIR_U)/raster.o

GLU_SOURCES = $(addprefix $(MESADIR_U)/si-glu/,$(GLU_CORE_SOURCES))
GLU_OBJECTS = $(addprefix $(MESADIR_U)/si-glu/,$(GLU_C_SOURCES:.c=.o) $(GLU_CC_SOURCES:.cc=.o))

GLUT_SOURCES = $(addprefix $(SRC_DIR_U)/amesa/glut-dj/,$(GLUT_CORE_SOURCES))
GLUT_OBJECTS = $(addprefix $(OBJ_DIR_U)/,$(GLUT_CORE_SOURCES:.c=.o))

glut : $(GLUT_LIB)

mesa-samples : $(addprefix $(MESADIR_U)/samples/, $(addsuffix .exe, $(MESA_SAMPLES))) $(GL_LIB) $(GLU_LIB) $(GLUT_LIB)

$(GL_LIB): $(GL_OBJECTS)
	ar rus $(GL_LIB) $?

$(GLU_LIB): $(GLU_OBJECTS)
	ar rus $(GLU_LIB) $?

$(GLUT_LIB): $(GLUT_OBJECTS)
	ar rus $(GLUT_LIB) $?

ifdef MESADIR
include $(MESADIR_U)/src/depend
endif

$(MESADIR_U)/src/%.o: $(MESADIR_U)/src/%.c
	$(CC) -c -I. -I$(INCDIR) $(CFLAGS) $(CPPFLAGS) $< -o $@

$(MESADIR_U)/si-glu/%.o: $(MESADIR_U)/si-glu/%.c
	$(CC) -c -I. -I$(INCDIR) -I$(MESADIR_U)/si-glu/include -I$(MESADIR_U)/si-glu/internals -DLIBRARYBUILD $(CFLAGS) $(CPPFLAGS) $< -o $@

$(MESADIR_U)/si-glu/%.o: $(MESADIR_U)/si-glu/%.cc
	$(CXX) -c -I. -I$(INCDIR) -I$(MESADIR_U)/si-glu/include -I$(MESADIR_U)/si-glu/internals -I$(MESADIR_U)/si-glu/libnurbs/internals -I$(MESADIR_U)/si-glu/libnurbs/inteface -I$(MESADIR_U)/si-glu/libnurbs/nurbtess -DLIBRARYBUILD $(CFLAGS) $(CPPFLAGS) $< -o $@

$(MESADIR_U)/samples/%.exe: $(MESADIR_U)/samples/%.c  $(GLUT_LIB) $(LIB_PATH_U) $(GL_LIB) $(GLU_LIB)
	$(CC) $(CFLAGS) $(CPPFLAGS) $^ -o $@ $(LDLIBS)

$(OBJ_DIR_U)/%.o: $(SRC_DIR_U)/amesa/glut-dj/%.c
	$(CC) -c -I. $(AMESA_HEADER) -I$(INCDIR) $(CFLAGS) -I$(SRC_DIR_U)/amesa/glut-dj $(CFLAGS) $< -o $@

$(OBJ_DIR_U)/%.o: $(SRC_DIR_U)/amesa/%.c
	$(CC) -o $@ -I. $(AMESA_HEADER) -I$(INCDIR) $(CFLAGS) -I$(SRC_DIR_U)/amesa -c $<

mesaclean :
	rm -f $(MESADIR_U)/src/*.o
	rm -f $(MESADIR_U)/src/swrast_setup/*.o
	rm -f $(MESADIR_U)/src/math/*.o
	rm -f $(MESADIR_U)/src/array_cache/*.o
	rm -f $(MESADIR_U)/src/swrast/*.o
	rm -f $(MESADIR_U)/src/tnl/*.o
	rm -f $(MESADIR_U)/si-glu/libutil/*.o
	rm -f $(MESADIR_U)/si-glu/libtess/*.o
	rm -f $(MESADIR_U)/si-glu/libnurbs/interface/*.o
	rm -f $(MESADIR_U)/si-glu/libnurbs/internals/*.o
	rm -f $(MESADIR_U)/si-glu/libnurbs/nurbtess/*.o

