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# Build time settings used by system services
18# ========================================================
19ifdef OSRELEASED_DIRECTORY
20
21include $(CLEAR_VARS)
22LOCAL_MODULE := product_id
23LOCAL_MODULE_CLASS := FAKE
24LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)
25include $(BUILD_SYSTEM)/base_rules.mk
26
27# Attempt to populate the product id from a file in the product path.
28LOADED_BRILLO_PRODUCT_ID := $(call cfgtree-get-if-exists,brillo/product_id)
29
30# We don't really have a default value for the product id as the backend
31# interaction will not work if this is not set correctly.
32$(LOCAL_BUILT_MODULE): BRILLO_PRODUCT_ID ?= "$(LOADED_BRILLO_PRODUCT_ID)"
33$(LOCAL_BUILT_MODULE):
34	$(hide) mkdir -p $(dir $@)
35	echo $(BRILLO_PRODUCT_ID) > $@
36	$(hide) mkdir -p $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)
37	ln -sf /oem/$(OSRELEASED_DIRECTORY)/product_id $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)
38
39include $(CLEAR_VARS)
40LOCAL_MODULE := system_id
41LOCAL_MODULE_CLASS := ETC
42LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)
43include $(BUILD_SYSTEM)/base_rules.mk
44
45# Attempt to populate the system id from a file in the product path.
46LOADED_BRILLO_SYSTEM_ID := $(call cfgtree-get-if-exists,brillo/system_id)
47
48$(LOCAL_BUILT_MODULE): BRILLO_SYSTEM_ID ?= "$(LOADED_BRILLO_SYSTEM_ID)"
49$(LOCAL_BUILT_MODULE):
50	$(hide) mkdir -p $(dir $@)
51	echo $(BRILLO_SYSTEM_ID) > $@
52
53
54include $(CLEAR_VARS)
55LOCAL_MODULE := product_version
56LOCAL_MODULE_CLASS := FAKE
57LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/$(OSRELEASED_DIRECTORY)
58include $(BUILD_SYSTEM)/base_rules.mk
59
60# The version is set to 0 if the user did not set the actual version and
61# a version cannot be loaded from the product cfgtree.
62# This allows us to have a valid version number while being easy to filter.
63ifeq ($(BRILLO_PRODUCT_VERSION),)
64# Load from file first
65BRILLO_PRODUCT_VERSION := $(call cfgtree-get-if-exists,brillo/product_version)
66endif
67# If the version is still empty, override it with 0
68ifeq ($(BRILLO_PRODUCT_VERSION),)
69BRILLO_PRODUCT_VERSION := "0"
70endif
71ifeq ($(shell echo $(BRILLO_PRODUCT_VERSION) | grep -E '^[0-9]+$$'),)
72$(error Invalid BRILLO_PRODUCT_VERSION "$(BRILLO_PRODUCT_VERSION)", must be \
73  a single number. Example: "1")
74endif
75
76$(LOCAL_BUILT_MODULE):
77	$(hide) mkdir -p $(dir $@)
78	echo $(BRILLO_PRODUCT_VERSION) > $@
79	$(hide) mkdir -p $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)
80	ln -sf /oem/$(OSRELEASED_DIRECTORY)/product_version $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)
81
82
83include $(CLEAR_VARS)
84LOCAL_MODULE := system_version
85LOCAL_MODULE_CLASS := ETC
86LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/$(OSRELEASED_DIRECTORY)
87include $(BUILD_SYSTEM)/base_rules.mk
88
89# The version is set to 0.0 if the user did not set the actual version and
90# a version cannot be loaded from the product cfgtree.
91# This allows us to have a valid version number while being easy to filter.
92ifeq ($(BRILLO_SYSTEM_VERSION),)
93# Load from file first
94BRILLO_SYSTEM_VERSION := $(call cfgtree-get-if-exists,brillo/system_version)
95endif
96# If the version is still empty, override it with 0.0
97ifeq ($(BRILLO_SYSTEM_VERSION),)
98BRILLO_SYSTEM_VERSION := "0.0"
99endif
100ifeq ($(shell echo $(BRILLO_SYSTEM_VERSION) | grep -E '^[0-9]+\.[0-9]+$$'),)
101$(error Invalid BRILLO_SYSTEM_VERSION "$(BRILLO_SYSTEM_VERSION)", must be \
102  two numbers separated by dots. Example: "1.2")
103endif
104
105# Append BUILD_NUMBER if it is a number or a build timestamp otherwise.
106# We don't want to use BUILD_DATETIME_FROM_FILE as this timestamp must be
107# different at every build.
108# If you don' want this to change at every build, you can define BUILD_NUMBER in
109# your product makefile and increase it manually.
110$(LOCAL_BUILT_MODULE):
111	$(hide) mkdir -p $(dir $@)
112ifeq ($(shell echo $(BUILD_NUMBER) | grep -E '[^0-9]'),)
113	echo $(BRILLO_SYSTEM_VERSION).$(BUILD_NUMBER) > $@
114else
115	echo $(BRILLO_SYSTEM_VERSION).$(BUILD_DATETIME) > $@
116endif
117
118endif
119