1# Mesa 3-D graphics library
2#
3# Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
4# Copyright (C) 2010-2011 LunarG Inc.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a
7# copy of this software and associated documentation files (the "Software"),
8# to deal in the Software without restriction, including without limitation
9# the rights to use, copy, modify, merge, publish, distribute, sublicense,
10# and/or sell copies of the Software, and to permit persons to whom the
11# Software is furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included
14# in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22# DEALINGS IN THE SOFTWARE.
23
24# included by glsl Android.mk for source generation
25
26ifeq ($(LOCAL_MODULE_CLASS),)
27LOCAL_MODULE_CLASS := STATIC_LIBRARIES
28endif
29
30intermediates := $(call local-generated-sources-dir)
31prebuilt_intermediates := $(MESA_TOP)/prebuilt-intermediates
32
33LOCAL_SRC_FILES := $(LOCAL_SRC_FILES)
34
35LOCAL_C_INCLUDES += \
36	$(intermediates)/glsl \
37	$(intermediates)/glsl/glcpp \
38	$(LOCAL_PATH)/glsl \
39	$(LOCAL_PATH)/glsl/glcpp \
40
41LOCAL_GENERATED_SOURCES += $(addprefix $(intermediates)/, \
42	$(LIBGLCPP_GENERATED_FILES) \
43	$(LIBGLSL_GENERATED_FILES))
44
45LOCAL_EXPORT_C_INCLUDE_DIRS += \
46	$(intermediates)/glsl \
47
48# Modules using libmesa_nir must set LOCAL_GENERATED_SOURCES to this
49MESA_GEN_GLSL_H := $(addprefix $(call local-generated-sources-dir)/, \
50	glsl/ir_expression_operation.h \
51	glsl/ir_expression_operation_constant.h \
52	glsl/ir_expression_operation_strings.h)
53
54define local-l-or-ll-to-c-or-cpp
55	@mkdir -p $(dir $@)
56	@echo "Mesa Lex: $(PRIVATE_MODULE) <= $<"
57	$(hide) $(LEX) --nounistd -o$@ $<
58endef
59
60define glsl_local-y-to-c-and-h
61	@mkdir -p $(dir $@)
62	@echo "Mesa Yacc: $(PRIVATE_MODULE) <= $<"
63	$(hide) $(YACC) -o $@ -p "glcpp_parser_" $<
64endef
65
66YACC_HEADER_SUFFIX := .hpp
67
68define local-yy-to-cpp-and-h
69	@mkdir -p $(dir $@)
70	@echo "Mesa Yacc: $(PRIVATE_MODULE) <= $<"
71	$(hide) $(YACC) -p "_mesa_glsl_" -o $@ $<
72	touch $(@:$1=$(YACC_HEADER_SUFFIX))
73	echo '#ifndef '$(@F:$1=_h) > $(@:$1=.h)
74	echo '#define '$(@F:$1=_h) >> $(@:$1=.h)
75	cat $(@:$1=$(YACC_HEADER_SUFFIX)) >> $(@:$1=.h)
76	echo '#endif' >> $(@:$1=.h)
77	rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
78endef
79
80$(intermediates)/glsl/glsl_lexer.cpp: $(LOCAL_PATH)/glsl/glsl_lexer.ll
81	$(call local-l-or-ll-to-c-or-cpp)
82
83$(intermediates)/glsl/glsl_parser.cpp: $(LOCAL_PATH)/glsl/glsl_parser.yy
84	$(call local-yy-to-cpp-and-h,.cpp)
85
86$(intermediates)/glsl/glsl_parser.h: $(intermediates)/glsl/glsl_parser.cpp
87
88$(intermediates)/glsl/glcpp/glcpp-lex.c: $(LOCAL_PATH)/glsl/glcpp/glcpp-lex.l
89	$(call local-l-or-ll-to-c-or-cpp)
90
91$(intermediates)/glsl/glcpp/glcpp-parse.c: $(LOCAL_PATH)/glsl/glcpp/glcpp-parse.y
92	$(call glsl_local-y-to-c-and-h)
93
94$(LOCAL_PATH)/glsl/ir.h: $(intermediates)/glsl/ir_expression_operation.h
95
96$(intermediates)/glsl/ir_expression_operation.h: $(prebuilt_intermediates)/glsl/ir_expression_operation.h
97	cp -a $< $@
98
99$(intermediates)/glsl/ir_expression_operation_constant.h: $(prebuilt_intermediates)/glsl/ir_expression_operation_constant.h
100	cp -a $< $@
101
102$(intermediates)/glsl/ir_expression_operation_strings.h: $(prebuilt_intermediates)/glsl/ir_expression_operation_strings.h
103	cp -a $< $@
104