1 # Copyright 2015 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 LOCAL_MOJO_ROOT := $(call my-dir) 6 7 include $(LOCAL_MOJO_ROOT)/build_mojom_template_tools.mk 8 9 mojo_generated_sources_dir := \ 10 $(call generated-sources-dir-for,SHARED_LIBRARIES,libmojo,,) 11 generated_templates_dir := $(mojo_generated_sources_dir)/templates 12 generated_sources_dir := $(local-generated-sources-dir) 13 generated_files := 14 15 # $(1): a single mojom file 16 define generate-mojom-source 17 18 mojom_file := $(1) 19 local_path := $(LOCAL_PATH) 20 target_path := $(generated_sources_dir) 21 gen_cc := $$(target_path)/$$(mojom_file).cc 22 gen_h := $$(target_path)/$$(mojom_file).h 23 gen_internal_h := $$(target_path)/$$(mojom_file)-internal.h 24 gen_srcjar := $$(target_path)/$$(mojom_file).srcjar 25 gen_src := $$(gen_cc) $$(gen_h) $$(gen_internal_h) $$(gen_srcjar) 26 mojom_bindings_generator_flags := $$(LOCAL_MOJOM_BINDINGS_GENERATOR_FLAGS) 27 # TODO(lhchavez): Generate these files instead of expecting them to be there. 28 mojom_type_mappings := 29 ifneq ($$(LOCAL_MOJOM_TYPE_MAPPINGS),) 30 mojom_type_mappings := $$(local_path)/$$(LOCAL_MOJOM_TYPE_MAPPINGS) 31 mojom_bindings_generator_flags += --typemap $$(abspath $$(mojom_type_mappings)) 32 endif 33 34 $$(gen_cc) : PRIVATE_PATH := $$(local_path) 35 $$(gen_cc) : PRIVATE_MOJO_ROOT := $$(LOCAL_MOJO_ROOT) 36 $$(gen_cc) : PRIVATE_TARGET := $$(target_path) 37 $$(gen_cc) : PRIVATE_FLAGS := $$(mojom_bindings_generator_flags) 38 $$(gen_cc) : PRIVATE_CUSTOM_TOOL = \ 39 (cd $$(PRIVATE_PATH) && \ 40 python $$(abspath $$(MOJOM_BINDINGS_GENERATOR)) \ 41 --use_bundled_pylibs generate \ 42 $$(subst $$(PRIVATE_PATH)/,,$$<) \ 43 -I $$(abspath $$(PRIVATE_MOJO_ROOT)):$$(abspath $$(PRIVATE_MOJO_ROOT)) \ 44 -o $$(abspath $$(PRIVATE_TARGET)) \ 45 --bytecode_path $$(abspath $$(generated_templates_dir)) \ 46 -g c++,java \ 47 $$(PRIVATE_FLAGS)) 48 $$(gen_cc) : $$(local_path)/$$(mojom_file) $$(mojom_type_mappings) \ 49 $$(MOJOM_TEMPLATE_TOOLS) $$(generated_templates_dir)/.stamp 50 $$(transform-generated-source) 51 52 # Make the other generated files depend on the .cc file. Unfortunately, the 53 # Make->ninja translation would generate one individual rule for each generated 54 # file, resulting in the files being (racily) generated multiple times. 55 $$(gen_internal_h): $$(gen_cc) 56 $$(hide) touch $$@ 57 58 $$(gen_h): $$(gen_cc) 59 $$(hide) touch $$@ 60 61 $$(gen_srcjar): $$(gen_cc) 62 $$(hide) touch $$@ 63 64 generated_files += $$(gen_src) 65 66 # LOCAL_GENERATED_SOURCES will filter out anything that's not a C/C++ source 67 # file. 68 LOCAL_GENERATED_SOURCES += $$(gen_src) 69 70 endef # define generate-mojom-source 71 72 # Build each file separately since the build command needs to be done per-file. 73 $(foreach file,$(LOCAL_MOJOM_FILES),$(eval $(call generate-mojom-source,$(file)))) 74 75 # Add the generated sources to the C includes. 76 LOCAL_C_INCLUDES += $(generated_sources_dir) 77 78 # Also add the generated sources to the C exports. 79 LOCAL_EXPORT_C_INCLUDE_DIRS += $(generated_sources_dir) 80