1# Copyright 2020 The Shaderc Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15ROOT_SHADERC_PATH := $(call my-dir)
16
17include $(ROOT_SHADERC_PATH)/third_party/Android.mk
18include $(ROOT_SHADERC_PATH)/libshaderc_util/Android.mk
19include $(ROOT_SHADERC_PATH)/libshaderc/Android.mk
20
21ALL_LIBS:=libglslang.a \
22	libOGLCompiler.a \
23	libOSDependent.a \
24	libshaderc.a \
25	libshaderc_util.a \
26	libSPIRV.a \
27	libHLSL.a \
28	libSPIRV-Tools.a \
29	libSPIRV-Tools-opt.a
30
31SHADERC_HEADERS=shaderc.hpp shaderc.h env.h status.h visibility.h
32SHADERC_HEADERS_IN_OUT_DIR=$(foreach H,$(SHADERC_HEADERS),$(NDK_APP_LIBS_OUT)/../include/shaderc/$(H))
33
34define gen_libshaderc_header
35$(NDK_APP_LIBS_OUT)/../include/shaderc/$(1) : \
36		$(ROOT_SHADERC_PATH)/libshaderc/include/shaderc/$(1)
37	$(call host-mkdir,$(NDK_APP_LIBS_OUT)/../include/shaderc)
38	$(call host-cp,$(ROOT_SHADERC_PATH)/libshaderc/include/shaderc/$(1) \
39		,$(NDK_APP_LIBS_OUT)/../include/shaderc/$(1))
40
41endef
42
43define gen_libshaderc
44
45$(1)/combine.ar: $(addprefix $(1)/, $(ALL_LIBS))
46	@echo "create libshaderc_combined.a" > $(1)/combine.ar
47	$(foreach lib,$(ALL_LIBS),
48		@echo "addlib $(lib)" >> $(1)/combine.ar
49	)
50	@echo "save" >> $(1)/combine.ar
51	@echo "end" >> $(1)/combine.ar
52
53$(1)/libshaderc_combined.a: $(addprefix $(1)/, $(ALL_LIBS)) $(1)/combine.ar
54	@echo "[$(TARGET_ARCH_ABI)] Combine: libshaderc_combined.a <= $(ALL_LIBS)"
55	@cd $(1) && $(2)ar -M < combine.ar && cd $(ROOT_SHADERC_PATH)
56	@$(2)objcopy --strip-debug $(1)/libshaderc_combined.a
57
58$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a: \
59		$(1)/libshaderc_combined.a
60	$(call host-mkdir,$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI))
61	$(call host-cp,$(1)/libshaderc_combined.a \
62		,$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a)
63
64ifndef HEADER_TARGET
65HEADER_TARGET=1
66$(eval $(foreach H,$(SHADERC_HEADERS),$(call gen_libshaderc_header,$(H))))
67endif
68
69libshaderc_combined: \
70	$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a
71
72endef
73
74libshaderc_combined: $(SHADERC_HEADERS_IN_OUT_DIR)
75
76$(eval $(call gen_libshaderc,$(TARGET_OUT),$(TOOLCHAIN_PREFIX)))
77