#
# 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

ifeq ($(FX_CHRIS_DENIS_ANTHONY_HACK),1)
LCDEFS          +=       -DCHRIS_DENIS_ANTHONY_HACK=1
endif

FX_TACO_MEMORY_FIFO_HACK = 
ifneq ($(FX_TACO_MEMORY_FIFO_HACK),)
LCDEFS          +=       -DTACO_MEMORY_FIFO_HACK
endif

ifneq ($(DIAG_BUILD),)
LCDEFS          +=       -DDIAG_BUILD
endif

# This is a bit of a red herring
ifeq ($(FX_GLIDE_DIRECT_WRITE),1)
FX_GLIDE_DIRECT_WRITE   = 1
LCDEFS          +=       -DDIRECT_IO=1
else
FX_GLIDE_PACKET_FIFO    = 1
endif

ifeq ($(FX_GLIDE_PACKET_FIFO),1)
CMDXPORTDEFS    =       -DGLIDE_PACKET3_TRI_SETUP=1 -DUSE_PACKET_FIFO=1 -DGLIDE_HW_TRI_SETUP=1
else 
CMDXPORTDEFS    =       -DUSE_PACKET_FIFO=0 -DGLIDE_HW_TRI_SETUP=1 -DGLIDE_PACKET3_TRI_SETUP=0
FX_GLIDE_DEBUG_FIFO=1
endif

FX_GLIDE_REAL_HW=       1
FX_GLIDE_NO_FIFO=       1

ifneq ($(FX_GLIDE_CTRISETUP),1)
FX_GLIDE_CTRISETUP =    0
endif
HWSPEC          =       fifo.c
LCDEFS          +=      -DH3 $(CMDXPORTDEFS)
                        
INITLIB         =       $(BUILD_ROOT)/$(FX_GLIDE_HW)/lib$(FX_GLIDE_HW)init.a


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

# Display Options
DSPOPTS =
SUBLIBRARIES =
DSPOPTS         +=      -DGLIDE_INIT_HWC

ifeq ($(HAL_HW),1)
DSPOPTS         +=      -DHAL_HW=1
SUBLIBRARIES	+=	$(BUILD_ROOT_SWLIBS)/lib/libfxmisc.a \
			$(BUILD_ROOT_SWLIBS)/lib/libfxpci.a \
			$(BUILD_ROOT)/$(FX_GLIDE_HW)/lib/libminihwc.a
LINKLIBRARIES   +=	-L/usr/X11R6/lib -lX11 -lXext	-lXxf86dga -lXxf86vm
endif

ifeq ($(HAL_HW),)
SUBLIBRARIES    +=      $(BUILD_ROOT)/h3/lib/libminihwc.a
endif

# 3DNow stuff
GL_AMD3D        =       1
ifneq ($(GL_AMD3D),)
LCDEFS          +=      -DGL_AMD3D
LIBOBJS         +=      xtexdl_3dnow.o
CFILES          +=      xtexdl_def.c
endif

# 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

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
DSPOPTS         +=      -DGLIDE_DISPATCH_SETUP=1 -DGLIDE_PACKED_RGB=0

ifeq ($(GL_AMD3D),)
ASMTRISETUP     =       xdraw2.S
else
LIBOBJS		+=	xdraw2_def.o xdraw2_3dnow.o
endif #GL_AMD3D
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

#Glide 3 Stuff, for migration all
ifneq ($(FX_GLIDE3),)
LCDEFS          +=      -DGLIDE3
GLIDE3FILES     =       gstrip.c distrip.c distate.c diget.c
endif

#Glide 3. remove migration stuff
ifneq ($(FX_GLIDE3_ALPHA),)
LCDEFS          +=      -DGLIDE3_ALPHA
GLIDE3FILES     =       gstrip.c distrip.c distate.c diget.c
endif

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 gump.h glidesys.h glideutl.h
PRIVATE_HEADERS =       fxglide.h gsstdef.h fxinline.h fxsplash.h

INSTALL_DESTINATION =   $(BUILD_ROOT)/$(FX_GLIDE_HW)

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

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

OTHER_CFILES    =       fxgasm.c fxbldno.c fxinline.h

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

ifeq ($(FX_GLIDE3),1)
LIBRARIES       =       libglide3.a
SHARED_LIBRARY  =	libglide3.so.3.10
else
LIBRARIES       =       libglide.a
SHARED_LIBRARY  =	libglide.so.2.60
endif
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)

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

ctags:  $(CFILES)
	ctags $(CFILES)

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

#--------------------------------------------------------------------------
# special rules for making FXGASM.H
#
fxgasm: fxgasm.c $(HEADERS) gsstdef.h fxglide.h makefile.linux
	$(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 -hex > fxgasm.h
fxinline.h: fxgasm
	./fxgasm -inline > fxinline.h


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

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

fxbldno.h: fxbldno
	./fxbldno > fxbldno.h

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

xdraw2.o : xdraw2.S xdraw2.inc.S fxgasm.h fxinline.h
	$(CC) -c -o xdraw2.o $(AFLAGS) xdraw2.S

cpudtect.o : cpudtect.S
	$(CC) -c -o cpudtect.o $(AFLAGS) cpudtect.S

ifneq ($(GL_AMD3D),)
xdraw2_def.o: xdraw2.S xdraw2.inc.S fxgasm.h
	$(CC) -c -o $@ $(AFLAGS) xdraw2.S

xdraw2_3dnow.o: xdraw2.S xdraw2.inc.S fxgasm.h
	$(CC) -c -o $@ $(AFLAGS) -DGL_AMD3D -DUSE_PACKET_FIFO xdraw2.S

xtexdl_3dnow.o: xtexdl.S fxgasm.h
	$(CC) -c -o $@ $(AFLAGS) -DGL_AMD3D -DUSE_PACKET_FIFO xtexdl.S
endif
