1# 2# Copyright (c) 2017, Google, Inc. All rights reserved 3# 4# Permission is hereby granted, free of charge, to any person obtaining 5# a copy of this software and associated documentation files 6# (the "Software"), to deal in the Software without restriction, 7# including without limitation the rights to use, copy, modify, merge, 8# publish, distribute, sublicense, and/or sell copies of the Software, 9# and to permit persons to whom the Software is furnished to do so, 10# subject to the following conditions: 11# 12# The above copyright notice and this permission notice shall be 13# included in all copies or substantial portions of the Software. 14# 15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22# 23 24# args: 25# GENERIC_CC : path to compiler (required) 26# GENERIC_SRCS : list of source files (required) 27# GENERIC_OBJ_DIR : a directory to hold the created .o files (required) 28# GENERIC_FLAGS : list of flags for the compiler 29# GENERIC_CFLAGS : list of flags for the compiler, when compiling C files. 30# GENERIC_CPPFLAGS : list of flags for the compiler, when compiling C++ files. 31# GENERIC_SRCDEPS : extra source dependencies 32 33# Validate arguments. 34ifeq ($(GENERIC_CC), ) 35$(error GENERIC_CC must be specified) 36endif 37 38ifeq ($(GENERIC_SRCS), ) 39$(error GENERIC_SRCS must be specified) 40endif 41 42ifeq ($(GENERIC_OBJ_DIR), ) 43$(error GENERIC_OBJ_DIR must be specified) 44endif 45 46# Group the source files so we can differ the flags between C, C++, and assembly. 47GENERIC_C_SRCS := $(filter %.c,$(GENERIC_SRCS)) 48GENERIC_C_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.c,%.o,$(GENERIC_C_SRCS))) 49 50GENERIC_CC_SRCS := $(filter %.cc,$(GENERIC_SRCS)) 51GENERIC_CC_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.cc,%.o,$(GENERIC_CC_SRCS))) 52 53GENERIC_CPP_SRCS := $(filter %.cpp,$(GENERIC_SRCS)) 54GENERIC_CPP_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.cpp,%.o,$(GENERIC_CPP_SRCS))) 55 56GENERIC_ASM_SRCS := $(filter %.S,$(GENERIC_SRCS)) 57GENERIC_ASM_OBJS := $(addprefix $(GENERIC_OBJ_DIR)/,$(patsubst %.S,%.o,$(GENERIC_ASM_SRCS))) 58 59GENERIC_OBJS := $(strip $(GENERIC_C_OBJS) $(GENERIC_CC_OBJS) $(GENERIC_CPP_OBJS) $(GENERIC_ASM_OBJS)) 60 61# Bind inputs. 62$(GENERIC_OBJS): CC := $(GENERIC_CC) 63$(GENERIC_OBJS): FLAGS := $(GENERIC_FLAGS) 64$(GENERIC_OBJS): CFLAGS := $(GENERIC_CFLAGS) 65$(GENERIC_OBJS): CPPFLAGS := $(GENERIC_CPPFLAGS) 66$(GENERIC_OBJS): ASMFLAGS := $(GENERIC_ASMFLAGS) 67$(GENERIC_OBJS): LOG_NAME := $(GENERIC_LOG_NAME) 68 69$(GENERIC_C_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.c $(GENERIC_SRCDEPS) 70 @$(call ECHO,$(LOG_NAME),building,$@) 71 @$(MKDIR) 72 $(NOECHO)$(CC) $(FLAGS) $(CFLAGS) -c $< -MMD -o $@ 73 @$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@) 74 75$(GENERIC_CC_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.cc $(GENERIC_SRCDEPS) 76 @$(call ECHO,$(LOG_NAME),building,$@) 77 @$(MKDIR) 78 $(NOECHO)$(CC) $(FLAGS) $(CPPFLAGS) -c $< -MMD -o $@ 79 @$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@) 80 81$(GENERIC_CPP_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.cpp $(GENERIC_SRCDEPS) 82 @$(call ECHO,$(LOG_NAME),building,$@) 83 @$(MKDIR) 84 $(NOECHO)$(CC) $(FLAGS) $(CPPFLAGS) -c $< -MMD -o $@ 85 @$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@) 86 87$(GENERIC_ASM_OBJS): $(GENERIC_OBJ_DIR)/%.o: %.S $(GENERIC_SRCDEPS) 88 @$(call ECHO,$(LOG_NAME),building,$@) 89 @$(MKDIR) 90 $(NOECHO)$(CC) $(FLAGS) $(ASMFLAGS) -c $< -MMD -o $@ 91 @$(call ECHO_DONE_SILENT,$(LOG_NAME),building,$@) 92 93# Cleanup inputs 94GENERIC_CC := 95GENERIC_SRCS := 96GENERIC_OBJ_DIR := 97GENERIC_FLAGS := 98GENERIC_CFLAGS := 99GENERIC_CPPFLAGS := 100GENERIC_ASMFLAGS := 101GENERIC_SRCDEPS := 102GENERIC_LOG_NAME := 103# Cleanup internal 104GENERIC_C_SRCS := 105GENERIC_C_OBJS := 106GENERIC_CC_SRCS := 107GENERIC_CC_OBJS := 108GENERIC_CPP_SRCS := 109GENERIC_CPP_OBJS := 110GENERIC_ASM_SRCS := 111GENERIC_ASM_OBJS := 112 113# GENERIC_OBJS is returned. 114