1# 2# Copyright (C) 2009 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# the sort also acts as a strip to remove the single space entries that creep in because of the evals 18define gather-all-makefiles-for-current-product 19$(eval _all_products_visited := )\ 20$(sort $(call gather-all-makefiles-for-current-product-inner,$(INTERNAL_PRODUCT))) 21endef 22 23define gather-all-makefiles-for-current-product-inner 24 $(foreach p,$(1),\ 25 $(if $(filter $(p),$(_all_products_visited)),, \ 26 $(p) \ 27 $(eval _all_products_visited += $(p)) \ 28 $(call gather-all-makefiles-for-current-product-inner, $(PRODUCTS.$(strip $(p)).INHERITS_FROM)) 29 ) \ 30 ) 31endef 32 33node_color_target := orange 34node_color_common := beige 35node_color_vendor := lavenderblush 36node_color_default := white 37define node-color 38$(if $(filter $(1),$(PRIVATE_TOP_LEVEL_MAKEFILE)),\ 39 $(node_color_target),\ 40 $(if $(filter build/make/target/product/%,$(1)),\ 41 $(node_color_common),\ 42 $(if $(filter vendor/%,$(1)),$(node_color_vendor),$(node_color_default))\ 43 )\ 44) 45endef 46 47open_parethesis := ( 48close_parenthesis := ) 49 50# Emit properties of a product node to a file. 51# $(1) the product 52# $(2) the output file 53define emit-product-node-props 54$(hide) echo \"$(1)\" [ \ 55label=\"$(dir $(1))\\n$(notdir $(1))$(if $(filter $(1),$(PRIVATE_TOP_LEVEL_MAKEFILE)),$(subst $(open_parethesis),,$(subst $(close_parenthesis),,\\n\\n$(PRODUCT_MODEL)\\n$(PRODUCT_DEVICE))))\" \ 56style=\"filled\" fillcolor=\"$(strip $(call node-color,$(1)))\" \ 57colorscheme=\"svg\" fontcolor=\"darkblue\" \ 58] >> $(2) 59 60endef 61 62products_graph := $(OUT_DIR)/products.dot 63 64$(products_graph): PRIVATE_ALL_MAKEFILES_FOR_THIS_PRODUCT := $(call gather-all-makefiles-for-current-product) 65$(products_graph): PRIVATE_TOP_LEVEL_MAKEFILE := $(INTERNAL_PRODUCT) 66$(products_graph): 67 @echo Product graph DOT: $@ for $(PRIVATE_TOP_LEVEL_MAKEFILE) 68 $(hide) echo 'digraph {' > $@ 69 $(hide) echo 'graph [ ratio=.5 ];' >> $@ 70 $(hide) $(foreach p,$(PRIVATE_ALL_MAKEFILES_FOR_THIS_PRODUCT), \ 71 $(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), echo \"$(d)\" -\> \"$(p)\" >> $@;)) 72 $(foreach p,$(PRIVATE_ALL_MAKEFILES_FOR_THIS_PRODUCT),$(call emit-product-node-props,$(p),$@)) 73 $(hide) echo '}' >> $@ 74 75.PHONY: product-graph 76product-graph: $(products_graph) 77 @echo Product graph .dot file: $(products_graph) 78 @echo Command to convert to pdf: dot -Tpdf -Nshape=box -o $(OUT_DIR)/products.pdf $(products_graph) 79 @echo Command to convert to svg: dot -Tsvg -Nshape=box -o $(OUT_DIR)/products.svg $(products_graph) 80