xref: /aosp_15_r20/trusty/kernel/make/host_lib.mk (revision 344aa361028b423587d4ef3fa52a23d194628137)
1*344aa361SAndroid Build Coastguard Worker#
2*344aa361SAndroid Build Coastguard Worker# Copyright (c) 2022, Google, Inc. All rights reserved
3*344aa361SAndroid Build Coastguard Worker#
4*344aa361SAndroid Build Coastguard Worker# Permission is hereby granted, free of charge, to any person obtaining
5*344aa361SAndroid Build Coastguard Worker# a copy of this software and associated documentation files
6*344aa361SAndroid Build Coastguard Worker# (the "Software"), to deal in the Software without restriction,
7*344aa361SAndroid Build Coastguard Worker# including without limitation the rights to use, copy, modify, merge,
8*344aa361SAndroid Build Coastguard Worker# publish, distribute, sublicense, and/or sell copies of the Software,
9*344aa361SAndroid Build Coastguard Worker# and to permit persons to whom the Software is furnished to do so,
10*344aa361SAndroid Build Coastguard Worker# subject to the following conditions:
11*344aa361SAndroid Build Coastguard Worker#
12*344aa361SAndroid Build Coastguard Worker# The above copyright notice and this permission notice shall be
13*344aa361SAndroid Build Coastguard Worker# included in all copies or substantial portions of the Software.
14*344aa361SAndroid Build Coastguard Worker#
15*344aa361SAndroid Build Coastguard Worker# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*344aa361SAndroid Build Coastguard Worker# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*344aa361SAndroid Build Coastguard Worker# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18*344aa361SAndroid Build Coastguard Worker# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19*344aa361SAndroid Build Coastguard Worker# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20*344aa361SAndroid Build Coastguard Worker# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21*344aa361SAndroid Build Coastguard Worker# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*344aa361SAndroid Build Coastguard Worker#
23*344aa361SAndroid Build Coastguard Worker
24*344aa361SAndroid Build Coastguard Worker# Rather than relying on the libraries provided by the host, these rules build
25*344aa361SAndroid Build Coastguard Worker# library dependencies for host tools and tests. Note that for simplicity,
26*344aa361SAndroid Build Coastguard Worker# building library dependencies recursively is not supported; any dependencies
27*344aa361SAndroid Build Coastguard Worker# for the library being built using these rules must be provided by the host.
28*344aa361SAndroid Build Coastguard Worker
29*344aa361SAndroid Build Coastguard Worker# args:
30*344aa361SAndroid Build Coastguard Worker# HOST_LIB_NAME : name of the library (required)
31*344aa361SAndroid Build Coastguard Worker# HOST_LIB_SRCS : list of source files (required)
32*344aa361SAndroid Build Coastguard Worker# HOST_LIB_FLAGS : list of flags for the compiler
33*344aa361SAndroid Build Coastguard Worker# HOST_LIB_VARIANT : suffix for the host lib to support build variants
34*344aa361SAndroid Build Coastguard Worker# HOST_INCLUDE_DIRS : list of include directories that all of the host tool/test depends on
35*344aa361SAndroid Build Coastguard Worker
36*344aa361SAndroid Build Coastguard Worker# output
37*344aa361SAndroid Build Coastguard Worker# lib$(HOST_LIB_NAME).a is appended to HOST_LIB_ARCHIVES
38*344aa361SAndroid Build Coastguard Worker
39*344aa361SAndroid Build Coastguard Worker# Validate arguments.
40*344aa361SAndroid Build Coastguard Workerifeq ($(HOST_LIB_NAME), )
41*344aa361SAndroid Build Coastguard Worker$(error HOST_LIB_NAME must be specified)
42*344aa361SAndroid Build Coastguard Workerendif
43*344aa361SAndroid Build Coastguard Worker
44*344aa361SAndroid Build Coastguard Workerifeq ($(HOST_LIB_SRCS), )
45*344aa361SAndroid Build Coastguard Worker$(error HOST_LIB_SRCS must be specified)
46*344aa361SAndroid Build Coastguard Workerendif
47*344aa361SAndroid Build Coastguard Worker
48*344aa361SAndroid Build Coastguard Worker# Build a static archive variant if requested
49*344aa361SAndroid Build Coastguard Workerifeq (true, $(call TOBOOL,$(HOST_STATIC_LINK)))
50*344aa361SAndroid Build Coastguard WorkerHOST_LIB_FLAGS += -static
51*344aa361SAndroid Build Coastguard WorkerHOST_LIB_VARIANT += -static
52*344aa361SAndroid Build Coastguard Workerendif
53*344aa361SAndroid Build Coastguard Worker
54*344aa361SAndroid Build Coastguard WorkerHOST_LIB_ARCHIVE := $(BUILDDIR)/host_libs/lib$(HOST_LIB_NAME)$(HOST_LIB_VARIANT).a
55*344aa361SAndroid Build Coastguard Worker
56*344aa361SAndroid Build Coastguard Worker# Guard against multiple rules for the same targets which produces make warnings
57*344aa361SAndroid Build Coastguard Workerifndef HEADER_GUARD_HOST_LIB_$(BUILDDIR)_$(HOST_LIB_NAME)_$(HOST_LIB_VARIANT)
58*344aa361SAndroid Build Coastguard WorkerHEADER_GUARD_HOST_LIB_$(BUILDDIR)_$(HOST_LIB_NAME)_$(HOST_LIB_VARIANT):=1
59*344aa361SAndroid Build Coastguard Worker
60*344aa361SAndroid Build Coastguard Worker# Compile library sources.
61*344aa361SAndroid Build Coastguard WorkerGENERIC_CC := $(HOST_CC)
62*344aa361SAndroid Build Coastguard WorkerGENERIC_SRCS := $(HOST_LIB_SRCS)
63*344aa361SAndroid Build Coastguard WorkerGENERIC_OBJ_DIR := $(BUILDDIR)/host_libs/obj/$(HOST_LIB_NAME)$(HOST_LIB_VARIANT)
64*344aa361SAndroid Build Coastguard WorkerGENERIC_FLAGS := -O1 -g -Wall -Wextra -Wno-unused-parameter -Werror -Wno-missing-field-initializers $(HOST_SANITIZER_FLAGS) $(HOST_LIB_FLAGS) $(addprefix -I, $(HOST_INCLUDE_DIRS))
65*344aa361SAndroid Build Coastguard WorkerGENERIC_CFLAGS := -std=c11 -D_POSIX_C_SOURCE=200809
66*344aa361SAndroid Build Coastguard WorkerGENERIC_CPPFLAGS := -std=c++20 $(HOST_LIBCXX_CPPFLAGS)
67*344aa361SAndroid Build Coastguard WorkerGENERIC_LOG_NAME := $(HOST_LIB_NAME)
68*344aa361SAndroid Build Coastguard Workerinclude make/generic_compile.mk
69*344aa361SAndroid Build Coastguard Worker
70*344aa361SAndroid Build Coastguard Worker# Build static library
71*344aa361SAndroid Build Coastguard Worker$(HOST_LIB_ARCHIVE): HOST_LIB_NAME := $(HOST_LIB_NAME)
72*344aa361SAndroid Build Coastguard Worker$(HOST_LIB_ARCHIVE): $(GENERIC_OBJS)
73*344aa361SAndroid Build Coastguard Worker	@$(call ECHO,$(HOST_LIB_NAME),aring,$@)
74*344aa361SAndroid Build Coastguard Worker	@$(MKDIR)
75*344aa361SAndroid Build Coastguard Worker	$(NOECHO)$(AR) crs $@ $^
76*344aa361SAndroid Build Coastguard Worker	@$(call ECHO_DONE_SILENT,$(HOST_LIB_NAME),aring,$@)
77*344aa361SAndroid Build Coastguard Worker
78*344aa361SAndroid Build Coastguard Workerendif
79*344aa361SAndroid Build Coastguard WorkerHOST_LIB_ARCHIVES += $(HOST_LIB_ARCHIVE)
80*344aa361SAndroid Build Coastguard Worker
81*344aa361SAndroid Build Coastguard Worker# cleanup input variables
82*344aa361SAndroid Build Coastguard WorkerHOST_LIB_NAME :=
83*344aa361SAndroid Build Coastguard WorkerHOST_LIB_SRCS :=
84*344aa361SAndroid Build Coastguard WorkerHOST_LIB_FLAGS :=
85*344aa361SAndroid Build Coastguard WorkerHOST_LIB_VARIANT :=
86*344aa361SAndroid Build Coastguard Worker# cleanup internal variables
87*344aa361SAndroid Build Coastguard WorkerHOST_LIB_ARCHIVE :=
88*344aa361SAndroid Build Coastguard WorkerGENERIC_OBJS :=
89