LICENSE   := GPLv2
VERSION   := 11.2.2
DOWNLOADS := mesa.archive

URL_BASE      := https://mesa.freedesktop.org/archive/older-versions
URL(mesa)     := $(URL_BASE)/11.x/$(VERSION)/mesa-$(VERSION).tar.gz
SHA(mesa)     := e2453014cd2cc5337a5180cdeffe8cf24fffbb83e20a96888e2b01df868eaae6

DIR(mesa)     := src/lib/mesa
TAR_OPT(mesa) := --strip-components=1 --files-from $(REP_DIR)/src/lib/mesa/files.list
HASH_INPUT    += $(REP_DIR)/src/lib/mesa/files.list


PATCHES := src/lib/mesa/patches/egl.patch
PATCH_OPT := -p1

DIRS := include
DIR_CONTENT(include) = $(wildcard src/lib/mesa/include/*)

#
# Check for tools
#
$(call check_tool,bison)
$(call check_tool,flex)
$(call check_tool,python)


#
# Determine python version to use
#
PYTHON := $(notdir $(lastword $(shell which python2 $(addprefix python2.,4 5 6 7 8))))
ifeq ($(PYTHON),)
default: python_not_installed
python_not_installed:
	$(error mesa requires python2)
endif

#
# Generate files
#
generated_files = src/lib/mesa/src/compiler/glsl/glsl_parser.cpp \
                  src/lib/mesa/src/compiler/glsl/glsl_lexer.cpp \
                  src/lib/mesa/src/compiler/glsl/glcpp/glcpp-parse.c \
                  src/lib/mesa/src/compiler/glsl/glcpp/glcpp-lex.c \
                  src/lib/mesa/src/mesa/program/program_parse.tab.c \
                  src/lib/mesa/src/mesa/program/lex.yy.c \
                  src/lib/mesa/src/mapi/shared-glapi/glapi_mapi_tmp.h \

src/lib/mesa/src/compiler/glsl/glsl_parser.cpp:
	@$(MSG_GENERATE)$(notdir $@)
	$(VERBOSE)bison  -o $@ -p "_mesa_glsl_" \
		--defines=$(@D)/glsl_parser.h $(@D)/glsl_parser.yy

src/lib/mesa/src/compiler/glsl/glsl_lexer.cpp:
	@$(MSG_GENERATE)$(notdir $@)
	$(VERBOSE)flex -o $@ $(@D)/glsl_lexer.ll

src/lib/mesa/src/compiler/glsl/glcpp/glcpp-parse.c:
	@$(MSG_GENERATE)$(notdir $@)
	$(VERBOSE)bison  -o $@ -p "glcpp_parser_" --defines=$(@D)/glcpp-parse.h \
		$(@D)/glcpp-parse.y

src/lib/mesa/src/compiler/glsl/glcpp/glcpp-lex.c:
	@$(MSG_GENERATE)$(notdir $@)
	$(VERBOSE)flex  -o $@ $(@D)/glcpp-lex.l

src/lib/mesa/src/mesa/program/program_parse.tab.c:
	@$(MSG_GENERATE)$(notdir $@)
	$(VERBOSE)bison -o $@ -p "_mesa_program_" --defines=$(@D)/program_parse.tab.h \
		$(@D)/program_parse.y

src/lib/mesa/src/mesa/program/lex.yy.c:
	@$(MSG_GENERATE)$(notdir $@)
	$(VERBOSE)flex -o $@ $(@D)/program_lexer.l

src/lib/mesa/src/mapi/shared-glapi/glapi_mapi_tmp.h:
	@$(MSG_GENERATE)$(notdir $@)
	$(VERBOSE)mkdir -p $(@D)
	$(VERBOSE)$(PYTHON) $(@D)/../mapi_abi.py --mode lib --printer shared-glapi \
		$(@D)/../glapi/gen/gl_and_es_API.xml > $@

default: $(DOWNLOADS) $(generated_files)

# vi: set ft=make :
