1# Copyright (C) 2011 The Android Open Source Project
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
15# We have to use BUILD_PREBUILT instead of PRODUCT_COPY_FIES,
16# because MINIMAL_FONT_FOOTPRINT is only available in Android.mks.
17
18LOCAL_PATH := $(call my-dir)
19
20##########################################
21# create symlink for given font
22# $(1): new font $(2): link target
23# should be used with eval: $(eval $(call ...))
24define create-font-symlink
25$(PRODUCT_OUT)/system/fonts/$(1) : $(PRODUCT_OUT)/system/fonts/$(2)
26	@echo "Symlink: $$@ -> $$<"
27	@mkdir -p $$(dir $$@)
28	@rm -rf $$@
29	$(hide) ln -sf $$(notdir $$<) $$@
30# this magic makes LOCAL_REQUIRED_MODULES work
31ALL_MODULES.$(1).INSTALLED := \
32    $(ALL_MODULES.$(1).INSTALLED) $(PRODUCT_OUT)/system/fonts/$(1)
33endef
34
35##########################################
36# The following fonts are just symlinks, for backward compatibility.
37##########################################
38$(eval $(call create-font-symlink,DroidSans.ttf,Roboto-Regular.ttf))
39$(eval $(call create-font-symlink,DroidSans-Bold.ttf,Roboto-Bold.ttf))
40$(eval $(call create-font-symlink,DroidSerif-Regular.ttf,NotoSerif-Regular.ttf))
41$(eval $(call create-font-symlink,DroidSerif-Bold.ttf,NotoSerif-Bold.ttf))
42$(eval $(call create-font-symlink,DroidSerif-Italic.ttf,NotoSerif-Italic.ttf))
43$(eval $(call create-font-symlink,DroidSerif-BoldItalic.ttf,NotoSerif-BoldItalic.ttf))
44
45extra_font_files := \
46    DroidSans.ttf \
47    DroidSans-Bold.ttf
48
49################################
50# Use DroidSansMono to hang extra_font_files on
51include $(CLEAR_VARS)
52LOCAL_MODULE := DroidSansMono.ttf
53LOCAL_SRC_FILES := $(LOCAL_MODULE)
54LOCAL_MODULE_CLASS := ETC
55LOCAL_MODULE_TAGS := optional
56LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts
57LOCAL_REQUIRED_MODULES := $(extra_font_files)
58include $(BUILD_PREBUILT)
59extra_font_files :=
60
61################################
62# Build the rest of font files as prebuilt.
63
64# $(1): The source file name in LOCAL_PATH.
65#       It also serves as the module name and the dest file name.
66define build-one-font-module
67$(eval include $(CLEAR_VARS))\
68$(eval LOCAL_MODULE := $(1))\
69$(eval LOCAL_SRC_FILES := $(1))\
70$(eval LOCAL_MODULE_CLASS := ETC)\
71$(eval LOCAL_MODULE_TAGS := optional)\
72$(eval LOCAL_MODULE_PATH := $(TARGET_OUT)/fonts)\
73$(eval include $(BUILD_PREBUILT))
74endef
75
76font_src_files := \
77    AndroidClock.ttf
78
79$(foreach f, $(font_src_files), $(call build-one-font-module, $(f)))
80
81build-one-font-module :=
82font_src_files :=
83
84################################
85# Copies the font configuration file into system/etc for the product as fonts.xml.
86# In the case where $(ADDITIONAL_FONTS_FILE) is defined, the content of $(ADDITIONAL_FONTS_FILE)
87# is added to the $(AOSP_FONTS_FILE).
88include $(CLEAR_VARS)
89
90LOCAL_MODULE := fonts.xml
91LOCAL_MODULE_CLASS := ETC
92
93AOSP_FONTS_FILE := frameworks/base/data/fonts/fonts.xml
94
95ifdef ADDITIONAL_FONTS_FILE
96ADDITIONAL_FONTS_SCRIPT := frameworks/base/tools/fonts/add_additional_fonts.py
97ADD_ADDITIONAL_FONTS := $(local-generated-sources-dir)/fonts.xml
98
99$(ADD_ADDITIONAL_FONTS): PRIVATE_SCRIPT := $(ADDITIONAL_FONTS_SCRIPT)
100$(ADD_ADDITIONAL_FONTS): PRIVATE_ADDITIONAL_FONTS_FILE := $(ADDITIONAL_FONTS_FILE)
101$(ADD_ADDITIONAL_FONTS): $(ADDITIONAL_FONTS_SCRIPT) $(AOSP_FONTS_FILE) $(ADDITIONAL_FONTS_FILE)
102	rm -f $@
103	python $(PRIVATE_SCRIPT) $@ $(PRIVATE_ADDITIONAL_FONTS_FILE)
104else
105ADD_ADDITIONAL_FONTS := $(AOSP_FONTS_FILE)
106endif
107
108LOCAL_PREBUILT_MODULE_FILE := $(ADD_ADDITIONAL_FONTS)
109
110include $(BUILD_PREBUILT)
111
112# Run sanity tests on fonts on checkbuild
113checkbuild: fontchain_lint
114
115FONTCHAIN_LINTER := $(HOST_OUT_EXECUTABLES)/fontchain_linter
116ifeq ($(MINIMAL_FONT_FOOTPRINT),true)
117CHECK_EMOJI := false
118else
119CHECK_EMOJI := true
120endif
121
122fontchain_lint_timestamp := $(call intermediates-dir-for,PACKAGING,fontchain_lint)/stamp
123
124.PHONY: fontchain_lint
125fontchain_lint: $(fontchain_lint_timestamp)
126
127fontchain_lint_deps := \
128    external/unicode/DerivedAge.txt \
129    external/unicode/emoji-data.txt \
130    external/unicode/emoji-sequences.txt \
131    external/unicode/emoji-variation-sequences.txt \
132    external/unicode/emoji-zwj-sequences.txt \
133    external/unicode/additions/emoji-data.txt \
134    external/unicode/additions/emoji-sequences.txt \
135    external/unicode/additions/emoji-zwj-sequences.txt \
136
137$(fontchain_lint_timestamp): $(FONTCHAIN_LINTER) $(TARGET_OUT)/etc/fonts.xml $(PRODUCT_OUT)/system.img $(fontchain_lint_deps)
138	@echo Running fontchain lint
139	$(FONTCHAIN_LINTER) $(TARGET_OUT) $(CHECK_EMOJI) external/unicode
140	touch $@
141