#
# THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
# PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
# TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
# INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 
# DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 
# THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 
# EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
# FULL TEXT OF THE NON-WARRANTY PROVISIONS.  
# 
# USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
# RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
# TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
# AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
# SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
# THE UNITED STATES.  
# 
# COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED

TAG_REGEXP      = $(BUILD_ROOT)/$(FX_GLIDE_HW)/$(FX_HW_PROJECTS)/src/glide.rx

# Compile for specific hardware
ifeq ($(FX_GLIDE_HW),cvg)
FX_GLIDE_REAL_HW=       1
FX_GLIDE_CTRISETUP =    0

HWSPEC          =       fifo.c
LCDEFS          +=       -DCVG \
                        -DGLIDE_HW_TRI_SETUP=1 -DGLIDE_PACKET3_TRI_SETUP=1 \
                        -DGLIDE_CHIP_BROADCAST=1 \
			-DGLIDE_DISPATCH_SETUP=1 \
			-DGLIDE_DISPATCH_DOWNLOAD=1

ifeq ($(HAL_HW),1)
LCDEFS          +=       -DGLIDE_BLIT_CLEAR=1 \
#                        -DWTF_P_COMDEX=1 -DWTF_P_COMDEX_RESET=1
endif
else 
ifeq ($(FX_GLIDE_HW),h3)
FX_GLIDE_REAL_HW=       1
FX_GLIDE_NO_FIFO=       1
FX_GLIDE_CTRISETUP =    1
HWSPEC          =       fifo.c
LCDEFS          +=      -DH3 \
                        -DGLIDE_HW_TRI_SETUP=1 -DGLIDE_PACKET3_TRI_SETUP=0
else
#error "FX_GLIDE_HW == unknown value (H3|CVG)"
endif
endif

ifeq ($(DEBUG),1)
DBGOPTS          =      -DGLIDE_DEBUG -DGDBG_INFO_ON
GLIDE_SANITY_ALL =      1
endif

ifeq ($(FX_GLIDE_HW),)
#error "FX_GLIDE_HW not defined"
endif

ifneq ($(GL_AMD3D),)
LOBJECTS	=  	xtexdl_def.o xtexdl_3dnow.o \
			xdraw2_def.o xdraw2_3dnow.o \
			xdraw3_def.o xdraw3_3dnow.o
LCDEFS		= 	$(LCDEFS) -DGL_AMD3D
#else
LOBJECTS		=	xtexdl_def.o
endif

# Display Options
DSPOPTS =
SUBLIBRARIES        = $(BUILD_ROOT_SWLIBS)/lib/libfxmisc.a \
		      $(BUILD_ROOT_SWLIBS)/lib/libfxpci.a
ifeq ($(HAL_HW),1)
DSPOPTS         +=      -DHAL_HW=1
SUBLIBRARIES    +=      $(BUILD_ROOT)/$(FX_GLIDE_HW)/lib/libsst1init.a
endif
ifeq ($(DSPOPTS),)
#error "Unknown HAL_* configuration"
endif

# GLIDE_HW_TRI_SETUP:   Use the hw TSU for triangle rendering. 
# GLIDE_TRI_CULLING:    Cull backfaced/zero area triangles in sw before the fifo.
#                       NB: This must be set if GLIDE_HW_TRI_SETUP=0
ifeq ($(FX_GLIDE_SW_SETUP),1)
LCDEFS          +=       -DGLIDE_HW_TRI_SETUP=0 -DGLIDE_TRI_CULLING=1
FX_GLIDE_CTRISETUP = 1
else # HW Setup

# Do culling test in sw for independent triangles
CULL_MODE       =
ifneq ($(FX_GLIDE_HW_CULL),1)
CULL_MODE       =       -DGLIDE_TRI_CULLING=1
endif
DSPOPTS         +=       $(CULL_MODE)

# Send a single DWORD ARGB rather than 4 fp values, at
# the cost of doing the conversion.
ifeq ($(FX_GLIDE_PACK_RGB),1)
LCDEFS          +=       -DGLIDE_PACKED_RGB=1
endif

# 1st stage tsu subtractor clamping fix.
ifneq ($(FX_GLIDE_REAL_HW),1)
ifneq ($(FX_GLIDE_CTRISETUP),1)
#error "ASM triangle code cannot clamp"
endif
LCDEFS          +=       -DGLIDE_FP_CLAMP=1 -DGLIDE_FP_CLAMP_TEX=1
endif

# Super expensive second stage tsu clamping fix.
ifneq ($(FX_HOOPTI_TRI_SETUP_COMPARE),)
# Make sure the normal claming stuff is on.
LCDEFS          +=       -DGLIDE_FP_CLAMP=1 -DGLIDE_FP_CLAMP_TEX=1
LCDEFS          +=       -DHOOPTI_TRI_SETUP_COMPARE=1 -DGLIDE_TRI_CULLING=1
endif # Hoopti tri setup compare
endif # HW Tri Setup

ifneq ($(FX_GLIDE_NO_FIFO),1)
FIFODEFS = -DUSE_PACKET_FIFO=1

ifeq ($(FX_GLIDE_DEBUG_FIFO),1)
# GLIDE_USE_DEBUG_FIFO:   Run w/ the small fifo to cause me/glide more stress
# FIFO_ASSERT_FULL:       Check hw depth/fifo a lot (slow)
LCDEFS          +=       -DGLIDE_USE_DEBUG_FIFO=1 -DFIFO_ASSERT_FULL=1 
#-DASSERT_FAULT=0 #-DGLIDE_SANITY_SIZE=1
endif
endif

# Optimization Options
# This is for turning on and off algorithmic optimizations,
# not flags to the C compiler.  Usually this involves
# enabling/disabling assembly language code, but it can also   
# change the way C code works, or how C code generates data to be 
# used by various pieces of code.
# Usually these are set with environment variables or arguments to 
# nmake.
#

# Turn on/off assembly language trisetup code.
# (C on is Assembly off) (A ssembly T ri S etup OPTS)
ifeq ($(FX_GLIDE_CTRISETUP),1)
ASMTRISETUP     =
ATSOPTS         =       -DGLIDE_USE_C_TRISETUP 
CFILES          =       gxdraw.c
else
CFILES          =       gxdraw.c
ASMTRISETUP     =       xdraw2.S xdraw3.S
DSPOPTS         +=       -DGLIDE_PACKED_RGB=0 -DGLIDE_TRI_CULLING=1
endif

# Turn on/off vertex size table
ifeq ($(FX_GLIDE_VERTEX_TABLE),1)
LCDEFS          +=       -DGLIDE_VERTEX_TABLE
endif

OPTOPTS         =       $(GRMOPTS) $(OTSOPTS) $(ATSOPTS)

# local defines, begin with basics and then add on
LCDEFS          +=       -DGLIDE_LIB

# Turn Off/On compilation of shameless plug
ifeq ($(FX_GLIDE_NO_PLUG),1)
else
LCDEFS          +=       -DGLIDE_PLUG
endif

# Turn Off/On splash screen
ifeq ($(FX_GLIDE_NO_SPLASH),1)
else
LCDEFS          +=       -DGLIDE_SPLASH
endif

ifeq ($(FX_PCI_TARGET),NT)
LCDEFS          +=       -DNT_BUILD
endif

LCDEFS          +=       -DGLIDE3 -DGLIDE3_ALPHA
GLIDE3FILES     =       gstrip.c distrip.c distate.c diget.c

ifneq ($(GLIDE_SANITY_ALL)$(GLIDE_SANITY_SIZE),)
LCDEFS          +=       -DGLIDE_SANITY_SIZE
endif
ifneq ($(GLIDE_SANITY_ALL)$(GLIDE_SANITY_ASSERT),)
LCDEFS          +=       -DGLIDE_SANITY_ASSERT
endif

# Local Defs, Includes, and Options (C)
LCINCS          +=      -I$(BUILD_ROOT)/$(FX_GLIDE_HW)/include 
LCOPTS          =       $(DBGOPTS) $(DSPOPTS) $(OPTOPTS)

# Local Defs, Includes, and Options (ASM)
LADEFS          +=       $(ASM_REGMAP_DEFS)
LAINCS          =       -I$(BUILD_ROOT)/$(FX_GLIDE_HW)/include
LAOPTS          =       $(DBGOPTS) $(DSPOPTS) $(OPTOPTS)

AFILES          =       $(ASMTRISETUP) cpudtect.S

# sources
HEADERS         =       glide.h glidesys.h glideutl.h
PRIVATE_HEADERS =       fxglide.h gsstdef.h fxinline.h

INSTALL_DESTINATION =   $(BUILD_ROOT)/$(FX_GLIDE_HW)

CFILES          +=  	gsplash.c g3df.c  gu.c gpci.c \
                        diglide.c disst.c ditex.c gbanner.c gerror.c\
                        digutex.c gaa.c gdraw.c\
                        gglide.c glfb.c gsst.c gtex.c gtexdl.c\
                        $(HWSPEC) $(GLIDE3FILES) xtexdl.c

OFILES          =       $(CFILES:.c=.o)

OTHER_CFILES    =       fxgasm.c fxbldno.c fxinline.h

CODFILES        =       $(CFILES:.c=.cod)

# targets
LDIRT           =       fxgasm.o fxgasm fxgasm.h fxinline.h fxbldno.obj fxbldnofxbldno.h

LIBRARIES       =       libglide3.a
SHARED_LIBRARY  =	libglide3.so.3.01
RCFILE          =       glide.rc

# Make a static link library for things like the diags.
ifeq ($(FX_DLL_BUILD),1)
FX_DLL_LIBRARY  =       1
else
LCDEFS          +=       -DFX_STATIC_BUILD
endif


LCDEFS          +=       $(FIFODEFS)

LINKLIBRARIES+=-lm

include $(BUILD_ROOT)/swlibs/include/make/3dfx.linux.mak

ifeq ($(DEBUG),1)
ASM_OPTS += -DGLIDE_DEBUG=1
endif

codfiles:   $(CODFILES)
xdraw2.o : xdraw2.S xdraw2.inc.S fxgasm.h fxinline.h
	$(CC) -c -o $@ xdraw2.S $(ASM_OPTS) $(LAOPTS)

xdraw3.o : xdraw3.S fxgasm.h
	$(CC) -c -o $@ xdraw3.S $(ASM_OPTS) $(LAOPTS)

cpudtect.o :
	$(CC) -c -o $@ cpudtect.S $(ASM_OPTS) $(LAOPTS)

xtexdl_3dnow.o: xtexdl.S fxgasm.h 
	$(CC) -DGL_AMD3D=1 -c -o $@ xtexdl.S

xtexdl_def.o: xtexdl.c fxglide.h
	$(CC) -c -o $@ xtexdl.c

ctags:  $(CFILES)
	ctags $(CFILES)

gbanner.o : banner.inc
gsplash.o : splshdat.c

#--------------------------------------------------------------------------
# special rules for making FXGASM.H
#
fxgasm: fxgasm.c $(HEADERS) gsstdef.h fxglide.h 
	$(CC) -o $@ fxgasm.c $(GCDEFS) $(LCDEFS) $(VCDEFS) $(LCOPTS) \
	-I$(BUILD_ROOT)/$(FX_GLIDE_HW)/include -I$(BUILD_ROOT)/swlibs/include \
	$(LDFLAGS)
fxgasm.h: fxgasm
	./fxgasm > fxgasm.h
fxinline.h: fxgasm
	./fxgasm -inline > fxinline.h

#--------------------------------------------------------------------------
# special rules for making FXBLDNO.H
#

fxbldno.exe: fxbldno.c $(HEADERS) $(PRIVATE_HEADERS)
	$(CC) -o $@ fxbldno.c $(GCDEFS) $(LCDEFS) $(VCDEFS) $(LCOPTS) $(LDFLAGS)

fxbldno.h: fxbldno
	fxbldno > fxbldno.h

glide.res: rcver.h fxbldno.h
gglide.o: rcver.h

ifneq ($(FX_GLIDE_CTRISETUP),1)
gdraw.o: fxinline.h
endif


