Home | History | Annotate | Download | only in libmojo
      1 # Copyright 2016 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 JNI_GENERATOR_TOOL := \
      8 	$(LOCAL_MOJO_ROOT)/base/android/jni_generator/jni_generator.py
      9 
     10 generated_sources_dir := $(local-generated-sources-dir)
     11 generated_files :=
     12 
     13 # $(1): a single Java file
     14 define generate-jni-header
     15 
     16 java_file := $(1)
     17 local_path := $(LOCAL_PATH)
     18 target_path := $(generated_sources_dir)/jni
     19 gen_h := $$(target_path)/$$(basename $$(notdir $$(java_file)))_jni.h
     20 
     21 $$(gen_h) : PRIVATE_PATH := $$(local_path)
     22 $$(gen_h) : PRIVATE_TARGET := $$(target_path)
     23 $$(gen_h) : PRIVATE_CUSTOM_TOOL = \
     24   (cd $$(PRIVATE_PATH) && \
     25    python $$(abspath $$(JNI_GENERATOR_TOOL)) \
     26 	 --input_file=$$(subst $$(PRIVATE_PATH)/,,$$<) \
     27 	 --output_dir=$$(abspath $$(PRIVATE_TARGET)) \
     28 	 --includes base/android/jni_generator/jni_generator_helper.h \
     29 	 --ptr_type long \
     30 	 --native_exports_optional)
     31 $$(gen_h) : $$(local_path)/$$(java_file) $$(JNI_GENERATOR_TOOL)
     32 	$$(transform-generated-source)
     33 
     34 generated_files += $$(gen_h)
     35 
     36 endef  # define generate-jni-header
     37 
     38 # Build each file separately since the build command needs to be done per-file.
     39 $(foreach file,$(LOCAL_JAVA_JNI_FILES),$(eval $(call generate-jni-header,$(file))))
     40 
     41 # Add the generated sources to the C includes.
     42 LOCAL_C_INCLUDES += $(generated_sources_dir)
     43 
     44 # Create a stamp file after all files have been generated.
     45 gen := $(generated_sources_dir)/.jni.stamp
     46 $(gen) : $(generated_files)
     47 	$(hide) echo $^ | sed -e 's/ /\n/g' > $@
     48 
     49 # Add the stamp file as a dependency to {import,export}_includes.
     50 $(local-intermediates-dir)/import_includes: | $(generated_sources_dir)/.jni.stamp
     51