1# 2# Copyright (C) 2015 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17# Print modules and their transitive dependencies with license files. 18# To invoke, run "make deps-license PROJ_PATH=<proj-path-patterns> DEP_PATH=<dep-path-patterns>". 19# PROJ_PATH restricts the paths of the source modules; DEP_PATH restricts the paths of the dependency modules. 20# Both can be makefile patterns supported by makefile function $(filter). 21# Example: "make deps-license packages/app/% external/%" prints all modules in packages/app/ with their dpendencies in external/. 22# The printout lines look like "<module_name> :: <module_paths> :: <license_files>". 23 24ifneq (,$(filter deps-license,$(MAKECMDGOALS))) 25ifndef PROJ_PATH 26$(error To "make deps-license" you must specify PROJ_PATH and DEP_PATH.) 27endif 28ifndef DEP_PATH 29$(error To "make deps-license" you must specify PROJ_PATH and DEP_PATH.) 30endif 31 32# Expand a module's dependencies transitively. 33# $(1): the variable name to hold the result. 34# $(2): the initial module name. 35define get-module-all-dependencies 36$(eval _gmad_new := $(sort $(filter-out $($(1)),\ 37 $(foreach m,$(2),$(ALL_DEPS.$(m).ALL_DEPS)))))\ 38$(if $(_gmad_new),$(eval $(1) += $(_gmad_new))\ 39 $(call get-module-all-dependencies,$(1),$(_gmad_new))) 40endef 41 42define print-deps-license 43$(foreach m, $(sort $(ALL_DEPS.MODULES)),\ 44 $(eval m_p := $(sort $(ALL_MODULES.$(m).PATH) $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PATH)))\ 45 $(if $(filter $(PROJ_PATH),$(m_p)),\ 46 $(eval deps :=)\ 47 $(eval $(call get-module-all-dependencies,deps,$(m)))\ 48 $(info $(m) :: $(m_p) :: $(ALL_DEPS.$(m).LICENSE))\ 49 $(foreach d,$(deps),\ 50 $(eval d_p := $(sort $(ALL_MODULES.$(d).PATH) $(ALL_MODULES.$(d)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PATH)))\ 51 $(if $(filter $(DEP_PATH),$(d_p)),\ 52 $(info $(space)$(space)$(space)$(space)$(d) :: $(d_p) :: $(ALL_DEPS.$(d).LICENSE)))))) 53endef 54 55.PHONY: deps-license 56deps-license: 57 @$(call print-deps-license) 58 59endif 60