xref: /aosp_15_r20/trusty/kernel/make/generic_compile.mk (revision 344aa361028b423587d4ef3fa52a23d194628137)
1*344aa361SAndroid Build Coastguard Worker#
2*344aa361SAndroid Build Coastguard Worker# Copyright (c) 2017, 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# args:
25*344aa361SAndroid Build Coastguard Worker# GENERIC_CC : path to compiler (required)
26*344aa361SAndroid Build Coastguard Worker# GENERIC_SRCS : list of source files (required)
27*344aa361SAndroid Build Coastguard Worker# GENERIC_OBJ_DIR : a directory to hold the created .o files (required)
28*344aa361SAndroid Build Coastguard Worker# GENERIC_FLAGS : list of flags for the compiler
29*344aa361SAndroid Build Coastguard Worker# GENERIC_CFLAGS : list of flags for the compiler, when compiling C files.
30*344aa361SAndroid Build Coastguard Worker# GENERIC_CPPFLAGS : list of flags for the compiler, when compiling C++ files.
31*344aa361SAndroid Build Coastguard Worker# GENERIC_SRCDEPS : extra source dependencies
32*344aa361SAndroid Build Coastguard Worker
33*344aa361SAndroid Build Coastguard Worker# Validate arguments.
34*344aa361SAndroid Build Coastguard Workerifeq ($(GENERIC_CC), )
35*344aa361SAndroid Build Coastguard Worker$(error GENERIC_CC must be specified)
36*344aa361SAndroid Build Coastguard Workerendif
37*344aa361SAndroid Build Coastguard Worker
38*344aa361SAndroid Build Coastguard Workerifeq ($(GENERIC_SRCS), )
39*344aa361SAndroid Build Coastguard Worker$(error GENERIC_SRCS must be specified)
40*344aa361SAndroid Build Coastguard Workerendif
41*344aa361SAndroid Build Coastguard Worker
42*344aa361SAndroid Build Coastguard Workerifeq ($(GENERIC_OBJ_DIR), )
43*344aa361SAndroid Build Coastguard Worker$(error GENERIC_OBJ_DIR must be specified)
44*344aa361SAndroid Build Coastguard Workerendif
45*344aa361SAndroid Build Coastguard Worker
46*344aa361SAndroid Build Coastguard WorkerGENERIC_FLAGS += --sysroot $(CLANG_HOST_SYSROOT)
47*344aa361SAndroid Build Coastguard Worker
48*344aa361SAndroid Build Coastguard Worker# Group the source files so we can differ the flags between C, C++, and assembly.
49*344aa361SAndroid Build Coastguard WorkerGENERIC_C_SRCS := $(filter %.c,$(GENERIC_SRCS))
50*344aa361SAndroid Build Coastguard WorkerGENERIC_C_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.c,%.o,$(GENERIC_C_SRCS)))
51*344aa361SAndroid Build Coastguard Worker
52*344aa361SAndroid Build Coastguard WorkerGENERIC_CC_SRCS := $(filter %.cc,$(GENERIC_SRCS))
53*344aa361SAndroid Build Coastguard WorkerGENERIC_CC_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.cc,%.o,$(GENERIC_CC_SRCS)))
54*344aa361SAndroid Build Coastguard Worker
55*344aa361SAndroid Build Coastguard WorkerGENERIC_CPP_SRCS := $(filter %.cpp,$(GENERIC_SRCS))
56*344aa361SAndroid Build Coastguard WorkerGENERIC_CPP_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.cpp,%.o,$(GENERIC_CPP_SRCS)))
57*344aa361SAndroid Build Coastguard Worker
58*344aa361SAndroid Build Coastguard WorkerGENERIC_ASM_SRCS := $(filter %.S,$(GENERIC_SRCS))
59*344aa361SAndroid Build Coastguard WorkerGENERIC_ASM_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.S,%.o,$(GENERIC_ASM_SRCS)))
60*344aa361SAndroid Build Coastguard Worker
61*344aa361SAndroid Build Coastguard WorkerGENERIC_OBJS := $(strip $(GENERIC_C_OBJS) $(GENERIC_CC_OBJS) $(GENERIC_CPP_OBJS) $(GENERIC_ASM_OBJS))
62*344aa361SAndroid Build Coastguard Worker
63*344aa361SAndroid Build Coastguard Worker# Bind inputs.
64*344aa361SAndroid Build Coastguard Worker$(GENERIC_OBJS): CC := $(GENERIC_CC)
65*344aa361SAndroid Build Coastguard Worker$(GENERIC_OBJS): FLAGS := $(GENERIC_FLAGS)
66*344aa361SAndroid Build Coastguard Worker$(GENERIC_OBJS): CFLAGS := $(GENERIC_CFLAGS)
67*344aa361SAndroid Build Coastguard Worker$(GENERIC_OBJS): CPPFLAGS := $(GENERIC_CPPFLAGS)
68*344aa361SAndroid Build Coastguard Worker$(GENERIC_OBJS): ASMFLAGS := $(GENERIC_ASMFLAGS)
69*344aa361SAndroid Build Coastguard Worker$(GENERIC_OBJS): LOG_NAME := $(GENERIC_LOG_NAME)
70*344aa361SAndroid Build Coastguard Worker
71*344aa361SAndroid Build Coastguard Worker$(GENERIC_C_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.c $(GENERIC_SRCDEPS)
72*344aa361SAndroid Build Coastguard Worker	@$(call ECHO,$(LOG_NAME),building,$@)
73*344aa361SAndroid Build Coastguard Worker	@$(MKDIR)
74*344aa361SAndroid Build Coastguard Worker	$(NOECHO)$(CC) $(FLAGS) $(CFLAGS) -c $< -MMD -o $@
75*344aa361SAndroid Build Coastguard Worker	@$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@)
76*344aa361SAndroid Build Coastguard Worker
77*344aa361SAndroid Build Coastguard Worker$(GENERIC_CC_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.cc $(GENERIC_SRCDEPS)
78*344aa361SAndroid Build Coastguard Worker	@$(call ECHO,$(LOG_NAME),building,$@)
79*344aa361SAndroid Build Coastguard Worker	@$(MKDIR)
80*344aa361SAndroid Build Coastguard Worker	$(NOECHO)$(CC) $(FLAGS) $(CPPFLAGS) -c $< -MMD -o $@
81*344aa361SAndroid Build Coastguard Worker	@$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@)
82*344aa361SAndroid Build Coastguard Worker
83*344aa361SAndroid Build Coastguard Worker$(GENERIC_CPP_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.cpp $(GENERIC_SRCDEPS)
84*344aa361SAndroid Build Coastguard Worker	@$(call ECHO,$(LOG_NAME),building,$@)
85*344aa361SAndroid Build Coastguard Worker	@$(MKDIR)
86*344aa361SAndroid Build Coastguard Worker	$(NOECHO)$(CC) $(FLAGS) $(CPPFLAGS) -c $< -MMD -o $@
87*344aa361SAndroid Build Coastguard Worker	@$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@)
88*344aa361SAndroid Build Coastguard Worker
89*344aa361SAndroid Build Coastguard Worker$(GENERIC_ASM_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.S $(GENERIC_SRCDEPS)
90*344aa361SAndroid Build Coastguard Worker	@$(call ECHO,$(LOG_NAME),building,$@)
91*344aa361SAndroid Build Coastguard Worker	@$(MKDIR)
92*344aa361SAndroid Build Coastguard Worker	$(NOECHO)$(CC) $(FLAGS) $(ASMFLAGS) -c $< -MMD -o $@
93*344aa361SAndroid Build Coastguard Worker	@$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@)
94*344aa361SAndroid Build Coastguard Worker
95*344aa361SAndroid Build Coastguard Worker# Cleanup inputs
96*344aa361SAndroid Build Coastguard WorkerGENERIC_CC :=
97*344aa361SAndroid Build Coastguard WorkerGENERIC_SRCS :=
98*344aa361SAndroid Build Coastguard WorkerGENERIC_OBJ_DIR :=
99*344aa361SAndroid Build Coastguard WorkerGENERIC_FLAGS :=
100*344aa361SAndroid Build Coastguard WorkerGENERIC_CFLAGS :=
101*344aa361SAndroid Build Coastguard WorkerGENERIC_CPPFLAGS :=
102*344aa361SAndroid Build Coastguard WorkerGENERIC_ASMFLAGS :=
103*344aa361SAndroid Build Coastguard WorkerGENERIC_SRCDEPS :=
104*344aa361SAndroid Build Coastguard WorkerGENERIC_LOG_NAME :=
105*344aa361SAndroid Build Coastguard Worker# Cleanup internal
106*344aa361SAndroid Build Coastguard WorkerGENERIC_C_SRCS :=
107*344aa361SAndroid Build Coastguard WorkerGENERIC_C_OBJS :=
108*344aa361SAndroid Build Coastguard WorkerGENERIC_CC_SRCS :=
109*344aa361SAndroid Build Coastguard WorkerGENERIC_CC_OBJS :=
110*344aa361SAndroid Build Coastguard WorkerGENERIC_CPP_SRCS :=
111*344aa361SAndroid Build Coastguard WorkerGENERIC_CPP_OBJS :=
112*344aa361SAndroid Build Coastguard WorkerGENERIC_ASM_SRCS :=
113*344aa361SAndroid Build Coastguard WorkerGENERIC_ASM_OBJS :=
114*344aa361SAndroid Build Coastguard Worker
115*344aa361SAndroid Build Coastguard Worker# GENERIC_OBJS is returned.
116