# Mesa 3-D graphics library
# Version:  4.1
# 
# Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
# 
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# DOS/DJGPP core makefile v1.1 for Mesa 4.0
#
#  Copyright (C) 2002 - Borca Daniel
#  Email : dborca@yahoo.com
#  Web   : http://www.geocities.com/dborca


#
#  Available options:
#
#    Environment variables:
#	CFLAGS
#
#	GLIDE		absolute path to Glide SDK; used with FX.
#			default = $(TOP)/include/glide3
#	FX=1		build for 3dfx Glide3; use it if you have the glide
#			SDK (designed for your platform), and, of course, a
#			3dfx card... Note that this disables compilation of
#			actual DMesa code, as Glide does all the stuff!
#			default = no
#	HAVE_X86=1	optimize for i386.
#			default = no
#	HAVE_MMX=1	MMX instructions; use only if you assembler/compiler
#			supports MMX instruction set; backwards compatibility
#			with older processors is still preserved.
#			default = no
#	HAVE_SSE=1	(see HAVE_MMX)
#			default = no
#	HAVE_3DNOW=1	(see HAVE_MMX)
#			default = no
#
#    Targets:
#	all:		build GL
#	clean:		remove object files
#



.PHONY: all clean

TOP = ..
GLIDE ?= $(TOP)/include/glide3
LIBDIR = $(TOP)/lib
GL_LIB = libgl.a
GL_DXE = gl.dxe
GL_IMP = libigl.a

CC = gcc
CFLAGS += -I$(TOP)/include -I.
ifdef FX
CFLAGS += -D__DOS__ -I$(GLIDE) -DFX -DFX_GLIDE3 -DFXMESA_USE_ARGB
endif

AR = ar
ARFLAGS = ru

ifneq ($(wildcard $(DJDIR)/lib/dxe2.ld),)
DXE2GEN = $(wildcard $(addsuffix /dxe2gen.exe,$(subst ;, ,$(PATH))))
endif

RM = del

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 \
	config.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 \
	texcompress.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_norm.c \
	math/m_debug_vertex.c \
	math/m_debug_xform.c \
	math/m_eval.c \
	math/m_matrix.c \
	math/m_translate.c \
	math/m_vector.c \
	math/m_vertices.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_pb.c \
	swrast/s_pixeltex.c \
	swrast/s_points.c \
	swrast/s_readpix.c \
	swrast/s_scissor.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

X86_SOURCES = \
	X86/x86.c \
	X86/glapi_x86.S \
	X86/common_x86.c \
	X86/common_x86_asm.S \
	X86/x86_xform2.S \
	X86/x86_xform3.S \
	X86/x86_xform4.S \
	X86/x86_vertex.S \
	X86/x86_cliptest.S

MMX_SOURCES = \
	X86/mmx_blend.S

SSE_SOURCES = \
	X86/sse.c \
	X86/sse_xform2.S \
	X86/sse_xform3.S \
	X86/sse_xform4.S \
	X86/sse_vertex.S \
	X86/sse_normal.S

K3D_SOURCES = \
	X86/3dnow.c \
	X86/3dnow_xform2.S \
	X86/3dnow_xform3.S \
	X86/3dnow_xform4.S \
	X86/3dnow_vertex.S

ifdef HAVE_MMX
X86_SOURCES += $(MMX_SOURCES)
CFLAGS += -DUSE_MMX_ASM
HAVE_X86 = 1
endif
ifdef HAVE_SSE
X86_SOURCES += $(SSE_SOURCES)
CFLAGS += -DUSE_SSE_ASM
HAVE_X86 = 1
endif
ifdef HAVE_3DNOW
X86_SOURCES += $(K3D_SOURCES)
CFLAGS += -DUSE_3DNOW_ASM
HAVE_X86 = 1
endif
ifdef HAVE_X86
CFLAGS += -DUSE_X86_ASM
else
X86_SOURCES =
endif

ifndef FX
DRIVER_SOURCES = \
	DOS/dmesa.c \
	DOS/video.c \
	DOS/virtual.S \
	DOS/vesa/vesa.c \
	DOS/dpmi.c
else
DRIVER_SOURCES = \
	FX/fxapi.c \
	FX/fxdd.c \
	FX/fxddspan.c \
	FX/fxddtex.c \
	FX/fxsetup.c \
	FX/fxtexman.c \
	FX/fxtris.c \
	FX/fxvb.c \
	FX/fxglidew.c
endif

SOURCES = $(CORE_SOURCES) $(X86_SOURCES) $(DRIVER_SOURCES)

OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))

.c.o:
	$(CC) -o $@ -c $(CFLAGS) $<
.S.o:
	$(CC) -o $@ -c $(CFLAGS) $<
.s.o:
	$(CC) -o $@ -c $(CFLAGS) -x assembler-with-cpp $<

all: $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GL_DXE) $(LIBDIR)/$(GL_IMP)

$(LIBDIR)/$(GL_LIB): $(OBJECTS)
	$(AR) $(ARFLAGS) $(LIBDIR)/$(GL_LIB) $(OBJECTS)

$(LIBDIR)/$(GL_DXE) $(LIBDIR)/$(GL_IMP): $(OBJECTS)
ifeq ($(DXE2GEN),)
	$(warning Missing DXE2GEN and/or DXE2.LD! You must have DXE2GEN)
	$(warning somewhere in PATH, and DXE2.LD in DJGPP/LIB directory.)
else
	-dxe2gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) $(OBJECTS) -E djgpp_ -E gl -E DMesa -E fxMesa -D "Mesa DJGPP GL" -U
endif

clean:
	-$(RM) $(subst /,\,*.o)
	-$(RM) $(subst /,\,array_cache/*.o)
	-$(RM) $(subst /,\,math/*.o)
	-$(RM) $(subst /,\,swrast/*.o)
	-$(RM) $(subst /,\,swrast_setup/*.o)
	-$(RM) $(subst /,\,tnl/*.o)
	-$(RM) $(subst /,\,X86/*.o)
	-$(RM) $(subst /,\,DOS/*.o)
	-$(RM) $(subst /,\,DOS/vesa/*.o)
	-$(RM) $(subst /,\,FX/*.o)

-include depend