• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- makefile -*-
2#
3# This makefile template should be included by makefiles in
4# library directories.
5#
6
7# Set the directories for the local sources and headers
8LOCAL_SRCDIR :=  $(abspath $(LOCAL_PATH)/$(SRCDIR))
9TMP_SRCDIR := $(abspath $(LOCAL_PATH)/$(SRCDIR))
10LOCAL_INCSRCDIR :=  $(abspath $(LOCAL_PATH)/$(INCSRCDIR))
11
12#$(info LOCAL_PATH = $(LOCAL_PATH))
13#$(info LOCAL_SRCDIR = $(LOCAL_SRCDIR))
14#$(info TMP_SRCDIR = $(TMP_SRCDIR))
15#$(info LOCAL_INCSRCDIR = $(LOCAL_INCSRCDIR))
16
17
18###########################################################
19#
20# See if there are any plugin files to include
21#
22MY_TARGET_PLUGINS := $($(TARGET)_plugins)
23SOLIB_OBJDIR_COMP :=
24SOLIB_TARGET_COMP :=
25ifeq ($(DEFAULT_LIBTYPE),shared-archive)
26  ifneq ($(strip $(SOLIB)),)
27    SOLIB_TARGET_COMP :=_$(SOLIB)
28    ifneq ($(strip $($(TARGET)_plugins_$(SOLIB))),)
29      MY_TARGET_PLUGINS := $($(TARGET)_plugins_$(SOLIB))
30      SOLIB_OBJDIR_COMP := /$(SOLIB)
31    endif
32  endif
33endif
34
35# $(info plugins to include $(TARGET) = $(MY_TARGET_PLUGINS))
36ifneq ($(strip $(MY_TARGET_PLUGINS)),)
37include $(call process_include_list,$(LOCAL_PATH),$(MY_TARGET_PLUGINS))
38endif
39
40
41#
42# See if there are any additional src files listed. E.g. assembly src files for codecs
43#
44-include $(call process_include_list,$(LOCAL_PATH),$(TOOLSET)_$(PROCESSOR).mk)
45###########################################################
46# Rules for installing the header files
47
48HDR_FILES := $(notdir $(HDRS))
49LOCAL_INSTALLED_HDRS := $(HDR_FILES:%=$(INCDESTDIR)/%)
50
51$(foreach hdr, $(strip $(HDRS)), $(eval $(call INST_TEMPLATE,$(notdir $(hdr)),$(patsubst %/,%,$(LOCAL_INCSRCDIR)/$(dir $(hdr))),$(INCDESTDIR))))
52
53$(INCDESTDIR)/ALL_HDRS_INSTALLED: $(LOCAL_INSTALLED_HDRS)
54
55###################################################################
56#
57#                   Set up the target
58
59# remove any leading / trailing whitespace
60TARGET := $(strip $(TARGET))
61
62
63$(TARGET)_libmode ?= $(DEFAULT_LIBMODE)
64$(TARGET)_libtype ?= $(DEFAULT_LIBTYPE)
65
66$(TARGET)_asm_flags ?= $(DEFAULT_CPP_ASM_FLAGS)
67XCPPFLAGS += $($(TARGET)_asm_flags)
68
69# $(info target = $(TARGET), libtype = $($(TARGET)_libtype))
70
71ifeq ($($(TARGET)_libtype),shared-archive)
72  CUMULATIVE_TARGET_LIST := $(CUMULATIVE_TARGET_LIST) $(TARGET)
73  LIB_EXT:=$(SHARED_ARCHIVE_LIB_EXT)
74  OBJSUBDIR:=shared
75  XCXXFLAGS+=$(SHARED_CXXFLAGS)
76  TMPDEPS = $(patsubst %,$$(%_fullname),$(LIBS))
77  $(eval $(TARGET)_LIBDEPS = $(TMPDEPS))
78else
79  ifeq ($($(TARGET)_libtype),shared)
80    LIB_EXT:=$(SHARED_LIB_EXT)
81    OBJSUBDIR:=shared
82    XCXXFLAGS+=$(SHARED_CXXFLAGS)
83    TMPDEPS = $(patsubst %,$$(%_fullname),$(LIBS))
84    $(eval $(TARGET)_LIBDEPS = $(TMPDEPS))
85  else
86    LIB_EXT:=$(STAT_LIB_EXT)
87    OBJSUBDIR:=static
88    $(TARGET)_LIBDEPS =
89  endif
90endif
91
92ifeq ($($(TARGET)_libmode),debug)
93  TARGET_NAME_SUFFIX:=_debug
94  OBJSUBDIR:=$(OBJSUBDIR)-dbg
95  XCPPFLAGS+=$(DEBUG_CPPFLAGS)
96  XCXXFLAGS+=$(DEBUG_CXXFLAGS)
97else
98  TARGET_NAME_SUFFIX:=
99  OBJSUBDIR:=$(OBJSUBDIR)-rel
100  XCXXFLAGS+=$(OPT_CXXFLAG)
101  XCXXFLAGS+=$(RELEASE_CXXFLAGS)
102  XCPPFLAGS+=$(RELEASE_CPPFLAGS)
103endif
104
105ifneq ($(strip $(OPTIMIZE_FOR_PERFORMANCE_OVER_SIZE)),true)
106  XCXXFLAGS += $(OPTIMIZE_FOR_SIZE)
107endif
108
109OBJDIR := $(subst $(SRC_ROOT),$(BUILD_ROOT),$(abspath $(LOCAL_PATH)/$(OUTPUT_DIR_COMPONENT)$(SOLIB_OBJDIR_COMP)/$(OBJSUBDIR)))
110
111ifeq ($($(TARGET)_libtype),shared-archive)
112  LIBTARGET := $(TARGET:%=$(OBJDIR)/lib%$(TARGET_NAME_SUFFIX).$(LIB_EXT))
113else
114  LIBTARGET := $(TARGET:%=$(DESTDIR)/lib%$(TARGET_NAME_SUFFIX).$(LIB_EXT))
115endif
116
117$(TARGET)$(SOLIB_TARGET_COMP)_fullname := $(LIBTARGET)
118
119#$(info src_root = $(abspath $(SRC_ROOT)))
120#$(info build_root = $(abspath $(BUILD_ROOT)))
121#$(info objdir = $(OBJDIR))
122
123$(eval $(call set-src-and-obj-names,$(SRCS),$(LOCAL_SRCDIR)))
124
125TMPOBJS := $(patsubst %,$$(%_compiled_objs),$(COMPONENT_LIBS))
126$(eval COMPILED_OBJS += $(TMPOBJS))
127
128
129# save compiled objects in a macro
130$(TARGET)_compiled_objs := $(COMPILED_OBJS)
131
132ifneq ($(strip $(FORCED_OBJS)),)
133 # The point of this dependency is to force object rebuilds when the
134 # corresponding dependency files are missing (even if the object file exists).
135 $(FORCED_OBJS): FORCE
136endif
137
138# $(info DEPS = $(DEPS))
139
140ifneq "$(MAKECMDGOALS)" "clean"
141  ifneq ($(strip $(FOUND_DEPS)),)
142  -include $(FOUND_DEPS)
143  endif
144endif
145
146
147# LOCAL_XINCDIRS := $(abspath $(patsubst %,$(LOCAL_PATH)/%,$(filter ../%,$(XINCDIRS))))
148
149# Currently remove -I until the old makefiles are obsoleted
150LOCAL_XINCDIRS := $(abspath $(patsubst ../%,$(LOCAL_PATH)/../%,$(patsubst -I%,%,$(XINCDIRS))))
151
152
153LOCAL_TOTAL_INCDIRS := $(LOCAL_SRCDIR) $(LOCAL_INCSRCDIR) $(LOCAL_XINCDIRS)
154
155# $(info  LOCAL_TOTAL_INCDIRS = $(LOCAL_TOTAL_INCDIRS), XCXXFLAGS = $(XCXXFLAGS))
156
157$(COMPILED_OBJS): XFLAGS := $(XCPPFLAGS) $(patsubst %,-I%,$(LOCAL_TOTAL_INCDIRS)) $(XCXXFLAGS)
158
159#$(info remote_dirs = $(REMOTE_DIRS))
160
161ifneq ($(strip $(REMOTE_DIRS)),)
162# $(info remote dirs = $(REMOTE_DIRS))
163$(foreach srcdir, $(strip $(REMOTE_DIRS)), $(eval $(call OBJ_TEMPLATE,$(srcdir),$(OBJDIR))))
164endif
165
166
167$(OBJDIR)/%.$(OBJ_EXT): $(LOCAL_SRCDIR)/%.cpp
168	$(call make-cpp-obj-and-depend,$<,$@,$(subst .$(OBJ_EXT),.d,$@),$(XFLAGS))
169
170$(OBJDIR)/%.$(OBJ_EXT): $(LOCAL_SRCDIR)/%.c
171	$(call make-c-obj-and-depend,$<,$@,$(subst .$(OBJ_EXT),.d,$@),$(XFLAGS))
172
173# $(info target = $(TARGET), LIBDEPS = $($(TARGET)_LIBDEPS))
174
175$(LIBTARGET): LIBTYPE := $($(TARGET)_libtype)
176
177$(LIBTARGET): $(COMPILED_OBJS) $($(TARGET)_LIBDEPS)
178	@echo Build $@
179	$(call create_objdir,$(@D))
180	$(call generate_$(LIBTYPE)_lib,$@,$^)
181	@echo Done
182
183ALL_LIBS_INSTALLED: $(LIBTARGET)
184
185# Pseudo-targets for libraries. With this, we can use "make lib$(TARGET)" instead of "make $(DESTDIR)/lib%$(TARGET_NAME_SUFFIX).$(LIB_EXT)"
186# E.g., make libunit_test
187lib$(TARGET): $(LIBTARGET)
188
189-include $(MK)/depgraph.mk
190
191TARGET_TYPE := library
192
193-include $(PLATFORM_EXTRAS)
194
195
196.PRECIOUS:: $(DEPS) $(COMPILED_OBJS)
197
198
199