ifneq ($(ARCH), WIN_NT)
ifneq ($(ARCH), WIN_98)
ARCH=$(shell uname | sed -e 's/-//g')
endif
endif

LIBRARY = wiregl_client

#CFLAGS += -DINSTRUMENT
#CXXFLAGS += -DINSTRUMENT

FILES = api_templates arrays buffer clipplane config drawpixels flush fog \
	geometry init lights lists map materials matrices misc_vectors normal \
	opengl papi pixelmap pixelstore readpixels state_queries stipple \
	texture util viewport vertexC vertexBB vertex_compressC \
	vertex_compressBB vertex_safecompressC vertex_safecompressBB vpinch \
	wiregl_get
LIBRARIES = wireglutil glcontext
XSLIBS = -lGLU
SHARED = 1

ifeq ($(ARCH), WIN_NT)
FILES += windows_exports wgl
ARCH_EXPORTS_PY = windows_exports.py
ARCH_EXPORTS = windows_exports.c
endif

ifeq ($(ARCH), WIN_98)
FILES += windows_exports wgl
ARCH_EXPORTS_PY = windows_exports.py
ARCH_EXPORTS = windows_exports.c
endif

ifeq ($(ARCH), AIX)
FILES += $(ARCH)_exports glx
ARCH_EXPORTS_PY = IRIX64_exports.py
ARCH_EXPORTS = $(ARCH)_exports.c
endif

ifeq ($(ARCH), Linux)
FILES += $(ARCH)_exports glx
ARCH_EXPORTS_PY = $(ARCH)_exports.py
ARCH_EXPORTS = $(ARCH)_exports.s
endif

ifeq ($(ARCH), IRIX64)
FILES += $(ARCH)_exports glx
ARCH_EXPORTS_PY = $(ARCH)_exports.py
ARCH_EXPORTS = $(ARCH)_exports.c
endif

ifeq ($(ARCH), IRIX)
FILES += IRIX64_exports glx
ARCH_EXPORTS_PY = IRIX64_exports.py
ARCH_EXPORTS = IRIX64_exports.c
endif

PRECOMP = $(ARCH_EXPORTS) api_templates.c opengl.c \
	../include/wireGL.h ../include/wiregl_opcodes.h opengl.def \
	length_table.c

SLOP += $(PRECOMP) gl_header.parsed wiregl_common.pyc

include ../../humper.mk

ifdef WINDOWS
LIB_DEFS = opengl.def
LDFLAGS += user32.lib ws2_32.lib
endif

geometry.c: length_table.c

gl_header.parsed: parser.py system_gl_header/GL.H
	@$(ECHO) "Parsing the system's OpenGL header... should only be done once"
	@python parser.py

opengl.def: wiregl_common.py defs.py gl_header.parsed
	@$(ECHO) "Creating the defs file..."
	@python defs.py > opengl.def

opengl.c: gl_header.parsed wiregl_common.py packer.py packer_special
	@$(ECHO) "Creating the OpenGL packer"
	@python packer.py > opengl.c

# current.c: current.pl ../glcontext/glcurrent_types.pl
# 	  @$(ECHO) "Creating current.c..."
# 	  perl current.pl > current.c

# exports.c: gl_header.parsed wiregl_common.py exports.py \
# 	  packer_state_special packer_vector_special ../include/wireGL.h
# 	  @$(ECHO) "Creating the OpenGL api structures and DLL exports"
# 	  @python exports.py > exports.c

api_templates.c: gl_header.parsed wiregl_common.py api_templates.py
	@$(ECHO) "Creating the OpenGL api structures"
	@python api_templates.py > api_templates.c

length_table.c: gl_header.parsed wiregl_common.py length_table.py
	@$(ECHO) "Creating the Length Table"
	@python length_table.py > length_table.c

$(ARCH_EXPORTS): gl_header.parsed wiregl_common.py $(ARCH_EXPORTS_PY)
	@$(ECHO) "Creating the OpenGL DLL export functions $(ARCH)"
	@python $(ARCH_EXPORTS_PY) > $(ARCH_EXPORTS)

../include/wireGL.h: gl_header.parsed wiregl_common.py header.py
	@$(ECHO) "Creating the WireGL header"
	@python header.py > ../include/wireGL.h

../include/wiregl_opcodes.h: gl_header.parsed wiregl_common.py \
	opcodes.py internal_header_special
	@$(ECHO) "Creating the WireGL opcodes header"
	@python opcodes.py > ../include/wiregl_opcodes.h
