blob: 908239a41ea4a886cd6d0d5e7d1f5cc0bda6300d [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001# Common Makefile configuration
2#
3
4# The following variables must be set
5# MOD_NAME - module name. Depending on MOD_TYPE can be encapsulated (e.g., MOD_NAME=os --> libos.a)
6# MOD_TYPE - module type. Supported types currently are "lib", "app", "linux_module" and "linux_lib"
7# Note:
8# For library module it is possible to specify "unitest" target in
9# $(MAKE_DEVICE_DIR)/modules.host / embedded.
10# In this case unitest.c is compiled and linked with its module library.
11# However, MOD_TYPE remains a "lib".
12#
13# The following variables are optional
14# srcs - list of .c source files relative to SRC_DIR
15# as_srcs - list of .s (lower case s) source files relative to SRC_DIR
16# AS_srcs - list of .S (upper case .S) source files relative to SRC_DIR
17# gen_srcs - list of .c that have to be generated as part of the build
18# MOD_DEPS - list of modules the "current" module depends on. OS abstraction layer dependency
19# (module "os") is always present implicitly. For example, api_cli module's Makefile
20# includes the following line:
21# MOD_DEPS = cli api utils model
22# MOD_INC_DIRS - used when module exports includes in directory(s) other than the module directory
23# MOD_DEFS - additional defines, including -D. the defines are added when compiling "this" module
24# and all modules depending on it
25# MOD_LIBS - additional libraries required by the module, including -l and -L
26# MOD_CUSTOM - if set "y", default rule for building the module is NOT provided.
27# In this case the rule for building $(MOD_TARGET) must be provided in module's Makefile
28#
29# The following variables are not required in most cases, but supported nonetheless
30# EXTRA_CFLAGS - extra CFLAGS the module requires for compilation
31# EXTRA_INCLUDES - extra include directories the module requires for compilation (with -I)
32# EXTRA_LIBS_PATH - additional library search paths
33# EXTRA_LIBS additional libraries to link with
34#
35# The following variables are pre-set and can be used in module-specific Makefile
36# TOP_DIR - fully qualified top directory
37# MOD_DIR - module directory relative to the top directory
38# OUT_DIR_BASE - output directory base
39# ALL_MODULES - list of all modules in the current subsystem (host/embedded)
40# ALL_LIB_MODULES - list of all lib modules in the current subsystem (host/embedded)
41# ALL_APP_MODULES - list of all app modules in the current subsystem (host/embedded)
42# SIMULATION_BUILD - set "y" for simulation build (CROSS_COMPILE is empty)
43# OS - OS
44# ENABLE_EPON - set "y" if EPON mode is included
45# ENABLE_GPON - set "y" if GPON mode is included
46# ENABLE_XGPON - set "y" if XGPON mode is included
47# ENABLE_GPON_OR_XGPON - set "y" if GPON or XGPON mode is included
48# ENABLE_CLI - set "n" if host CLI support is not required
49# ENABLE_LOG - set "n" if host logger support is not required
50#
51# USE_CLANG - set "y" to enable CLANG code pass for improved diagnostic
52#
53# The following variables are pre-set and can be used and/or overwritten in module-specific Makefile
54# SRC_DIR - fully-qualified source directory
55# OUT_DIR - module output directory
56# TARGET_LIB - library name for "lib" module. By default it is $(MOD_NAME)
57# TARGET_LIB_FNAME - module library file name including path. By default it is $(OUT_DIR)/lib$(TARGET_LIB).a
58# MOD_TARGET - module target name, including path. By default it is
59# $(OUT_DIR)/$(MOD_NAME) for "app" modules
60# $(TARGET_LIB_FNAME) for "lib" modules
61# CODEGEN_OUTPUT_DIR - output directory containing generated files
62
63TOOLCHAIN ?= gcc
64OS ?= posix
65DEBUG ?= y
66BLD_DEP ?= gcc
67USE_CLANG ?= n
68
69export BOARD
70export TOOLCHAIN
71export OS
72export DEBUG
73export BLD_DEP
74export OS_KERNEL
75
76V ?= 0
77ifeq (x"$(V)", x"0")
78 SILENT_BUILD = @
79endif
80
81#
82# Compiler warning configuration
83# Some extra warnings are always enabled. Others must be opted in on the module level
84#
85ENABLE_EXTRA_WARNINGS ?= y
86export ENABLE_EXTRA_WARNINGS
87
88# Include optional platform-specific configuration
89-include $(MAKE_DEVICE_DIR)/Makefile.$(SUBSYSTEM).config
90
91ENABLE_EPON ?= y
92ENABLE_GPON ?= y
93ENABLE_XGPON ?= y
94
95ENABLE_GPON_OR_XGPON = n
96ifeq ("$(ENABLE_GPON)", "y")
97 ENABLE_GPON_OR_XGPON = y
98endif
99ifeq ("$(ENABLE_XGPON)", "y")
100 ENABLE_GPON_OR_XGPON = y
101endif
102export ENABLE_EPON
103export ENABLE_GPON
104export ENABLE_XGPON
105export ENABLE_GPON_OR_XGPON
106
107SRC_DIR = $(TOP_DIR)/$(MOD_DIR)
108
109ifeq ("$(RELEASE_BUILD)", "y")
110 OUT_DIR_BASE ?= $(TOP_DIR)/build
111 OUT_DIR = $(OUT_DIR_BASE)/$(MOD_DIR)
112 MODEL_OUT_DIR= $(TOP_DIR)/host_driver/model
113 CONFIG_DIR = host_driver/config
114else
115 OUT_DIR_BASE ?= $(TOP_DIR)/build/$(PLATFORM)/$(SUBSYSTEM)
116 OUT_DIR = $(OUT_DIR_BASE)/$(MOD_DIR)
117 MODEL_OUT_DIR= $(OUT_DIR_BASE)/common/model/$(PLATFORM)
118 CONFIG_DIR = $(SUBSYSTEM)/config
119 OS_PLATFORM_DIR = $(SUBSYSTEM)/os_abstraction/$(PLATFORM)
120endif
121
122# Host CLI and logger support
123ENABLE_CLI ?= y
124ENABLE_LOG ?= y
125ENABLE_KT2 ?= n
126
127MOD_DEFS += -DUSE_DRIVER_CLI=1 -DFULL_DRIVER=1 -DCFE_DRIVER=0
128
129export ENABLE_CLI
130export ENABLE_LOG
131export ENABLE_KT2
132
133ifeq ("$(SUBSYSTEM)", "embedded")
134 override ENABLE_CLI = y
135 override ENABLE_LOG = y
136endif
137
138#
139### Include module Makefile
140# For MOD_CUSTOM only will be included in Makefile.rules second time for propagate custom rules
141#
142include $(SRC_DIR)/Makefile
143
144# Code-generator - related parameters
145CODEGEN_INPUT_DIR = $(SRC_DIR)/codegen_templates
146CODEGEN_OUTPUT_DIR = $(OUT_DIR)
147CODEGEN_DIR = $(TOP_DIR)/bin/codegen
148MODEL_FILE = $(TOP_DIR)/common/model/$(PLATFORM)/$(PLATFORM).objset
149CODEGEN_EXE = $(CODEGEN_DIR)/Teknovus.MetaStructure.CodeGenerator.exe
150MONO_VER ?= 4.3.2.467
151MONO_PATH ?= /opt/mono-$(MONO_VER)/bin/mono
152
153export SRC_DIR
154export OUT_DIR_BASE
155export OUT_DIR
156export MODEL_OUT_DIR
157
158ifeq ("$(wildcard $(MONO_PATH))", "")
159 # If we can't find Mono installed in the correct path, default to the current PATH version.
160 # In the future, we should always use Mono from a common tools directory.
161 # TODO: change this once the compiler/toolchain paths are better defined.
162 MONO_PATH = mono
163endif
164
165# Treat "yes" and "y" the same
166ifeq ("$(USE_CLANG)", "yes")
167 USE_CLANG := y
168endif
169ifeq ("$(USE_CLANG)", "y")
170 include $(MAKE_DIR)/clang.opts
171endif
172
173# Disable code generation in release build
174ifeq ("$(RELEASE_BUILD)", "y")
175 srcs := $(srcs) $(gen_srcs)
176 gen_srcs :=
177 # Disable LINT and CLANG
178 USE_LINT = n
179 USE_CLANG = n
180 EXTRA_DEFINES += -DRELEASE_BUILD
181endif
182
183SRCS = $(strip $(srcs:%=$(SRC_DIR)/%))
184
185# In COMPILE_ALL_IN_ONE_GO mode all .c files of a module are compiled in
186# a single invocation of BLD_CC compiler. In result, objects files are created
187# in OUT_DIR even if module's .c files are spread in sub-directories
188ifeq ("$(COMPILE_ALL_IN_ONE_GO)", "y")
189 srcs_no_dir = $(notdir $(srcs))
190 _OBJS = $(srcs_no_dir:%.c=$(OUT_DIR)/%.o)
191else
192 _OBJS = $(srcs:%.c=$(OUT_DIR)/%.o)
193endif
194
195as_SRCS = $(strip $(as_srcs:%=$(SRC_DIR)/%))
196as_OBJS = $(as_srcs:%.s=$(OUT_DIR)/%.o)
197_OBJS += $(as_OBJS)
198
199AS_SRCS = $(strip $(AS_srcs:%=$(SRC_DIR)/%))
200AS_OBJS = $(AS_srcs:%.S=$(OUT_DIR)/%.o)
201_OBJS += $(AS_OBJS)
202
203ifneq ("$(gen_srcs)", "")
204 GEN_SRCS = $(strip $(gen_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
205 _OBJS += $(GEN_SRCS:%.c=%.o)
206endif
207OBJS = $(strip $(_OBJS))
208
209# Add default dependency on OS abstraction
210ifeq ("$(MOD_NAME)", "")
211 ifneq (x"$(V)", x"0")
212 $(info MOD_NAME is not set for $(SRC_DIR)/Makefile. Skipping..)
213 endif
214 MOD_TYPE = _skip_
215endif
216
217# Add default dependency on OS abstraction
218ifneq ("$(MOD_SUPPRESS_OS_DEP), "y)
219 ifeq ("$(MOD_TYPE)", "linux_module")
220 _kernel = y
221 endif
222 ifeq ("$(MOD_TYPE)", "linux_lib")
223 _kernel = y
224 endif
225 ifeq ("$(_kernel)", "y")
226 MOD_DEPS := os_linux $(MOD_DEPS)
227 else
228 MOD_DEPS := os $(MOD_DEPS)
229 endif
230endif
231
232# GEN_OBJTAGS define which objects are generated. If not set explicitly,
233# derive it from ENABLE_EPON, ENABLE_GPON, ENABLE_XGPON flags
234ifeq ("$(GEN_OBJTAGS)", "")
235 ifeq ("$(ENABLE_EPON)", "y")
236 GEN_OBJTAGS := $(GEN_OBJTAGS),EPON,AE
237 endif
238 ifeq ("$(ENABLE_GPON)", "y")
239 GEN_OBJTAGS := $(GEN_OBJTAGS),GPON
240 endif
241 ifeq ("$(ENABLE_XGPON)", "y")
242 GEN_OBJTAGS := $(GEN_OBJTAGS),XGPON
243 endif
244 ifeq ("$(GEN_OBJTAGS)", "")
245 $(error At least one of ENABLE_EPON, ENABLE_GPON, ENABLE_XGPON must be set =y)
246 endif
247endif
248
249# Extra types filter
250ifneq ("$(EXTRA_TYPES)", "")
251 EXTRA_TYPES := $(shell echo -n $(EXTRA_TYPES) | sed -e 's/ /\\|/g')
252 GEN_EXTRA_TYPES := -typeNameFilter=\^\($(EXTRA_TYPES)\)\$$
253endif
254
255OS_KERNEL ?= $(OS)
256UC_PLATFORM = $(shell echo $(PLATFORM) | tr a-z A-Z)
257UC_SUBSYSTEM = $(shell echo $(SUBSYSTEM) | tr a-z A-Z)
258UC_OS = $(shell echo $(OS) | tr a-z A-Z)
259UC_OS_KERNEL = $(shell echo $(OS_KERNEL) | tr a-z A-Z)
260
261BUILD_TIME = $(shell date +%s)
262BUILD_TIME_ZONE = $(shell date +%:z)
263EXTRA_CFLAGS += -DBUILD_TIME=$(BUILD_TIME) -DBUILD_TIME_ZONE='"$(BUILD_TIME_ZONE)"'
264
265EXTRA_DEFINES += -DBCM_SUBSYSTEM_$(UC_SUBSYSTEM) -DBCM_PLATFORM_$(UC_PLATFORM) -DBCM_OS_$(UC_OS)
266EXTRA_DEFINES += -D$(UC_OS_KERNEL)_KERNEL_SPACE
267ifeq ("$(ENABLE_EPON)", "y")
268 EXTRA_DEFINES += -DBCM_EPON
269endif
270ifeq ("$(ENABLE_GPON)", "y")
271 EXTRA_DEFINES += -DBCM_GPON
272endif
273ifeq ("$(ENABLE_XGPON)", "y")
274 EXTRA_DEFINES += -DBCM_XGPON
275endif
276
277# Build unitests for simulation and from Jenkins jobs
278UNITEST ?= n
279
280ifeq ("$(SIMULATION_BUILD)", "y")
281 EXTRA_DEFINES += -DSIMULATION_BUILD
282 UNITEST = y
283endif
284
285ifeq ("$(JENKINS_BUILD)", "y")
286 UNITEST = y
287endif
288
289EXTRA_INCLUDES += -I$(SRC_DIR)
290
291OPT_DISABLE_EMBEDDED ?= n
292OPT_DISABLE_HOST ?=n
293
294ifeq ("OPT_DISABLE_$(UC_SUBSYSTEM)", "OPT_DISABLE_EMBEDDED")
295 OPT_DISABLE := $(OPT_DISABLE_EMBEDDED)
296else
297 OPT_DISABLE := $(OPT_DISABLE_HOST)
298endif
299
300ARCH_CFLAGS = $(ARCH_FLAGS)
301ifeq ("$(OPT_DISABLE)", "y")
302 ARCH_CFLAGS += $(DEBUG_O_CFLAGS)
303 EXTRA_LFLAGS += $(DEBUG_O_LFLAGS)
304 EXTRA_ASFLAGS += $(DEBUG_O_ASFLAGS)
305 EXTRA_asFLAGS += $(DEBUG_O_asLAGS)
306else
307 ARCH_CFLAGS += $(RELEASE_O_CFLAGS)
308 EXTRA_LFLAGS += $(RELEASE_O_LFLAGS)
309 EXTRA_ASFLAGS += $(RELEASE_O_ASFLAGS)
310 EXTRA_asFLAGS += $(RELEASE_O_asFLAGS)
311endif
312
313# Treat lib as shared lib if BUILD_SHARED_LIBS is y
314ifeq ("$(BUILD_SHARED_LIBS)", "y")
315 ifeq ("$(MOD_TYPE)", "lib")
316 MOD_TYPE = shared_lib
317 endif
318 SHARED_LIB_PATH ?= $(OUT_DIR_BASE)/shared_libs
319endif
320
321# Calculate MOD_TARGET based on MOD_TYPE
322ifeq ("$(MOD_TYPE)", "lib")
323 ifneq ("$(OBJS)", "")
324 TARGET_LIB ?= $(MOD_NAME)
325 TARGET_LIB_FNAME ?= $(OUT_DIR)/lib$(TARGET_LIB).a
326 endif
327 MOD_TARGET ?= $(TARGET_LIB_FNAME)
328else ifeq ("$(MOD_TYPE)", "shared_lib")
329 ifneq ("$(OBJS)", "")
330 TARGET_LIB ?= $(MOD_NAME)
331 TARGET_LIB_FNAME ?= $(OUT_DIR)/lib$(TARGET_LIB).so
332 endif
333 MOD_TARGET ?= $(TARGET_LIB_FNAME)
334else ifeq ("$(MOD_TYPE)", "app")
335 MOD_TARGET ?= $(OUT_DIR)/$(MOD_NAME)
336else ifeq ("$(MOD_TYPE)", "linux_module")
337 ifeq ("$(KERNELDIR)", "")
338 $(error KERNELDIR must be set in board profile)
339 endif
340 ifeq ("$(KERNEL_ARCH)", "")
341 $(error KERNEL_ARCH must be set in board profile)
342 endif
343 ifeq ("$(KERNEL_OUTDIR)", "")
344 KERNEL_OUTDIR := $(KERNELDIR)
345 endif
346 MOD_TARGET ?= $(SRC_DIR)/$(MOD_NAME).ko
347else ifeq ("$(MOD_TYPE)", "linux_lib")
348 MOD_TARGET ?= $(OUT_DIR_BASE)/$(MOD_NAME).linuxlib
349else ifeq ("$(MOD_TYPE)", "_skip_")
350 MOD_TARGET = .dummy
351else
352 $(error MOD_TYPE $(MOD_TYPE) is incorrect for module $(MOD_NAME). Must be lib or app)
353endif
354
355ifeq ("$(MOD_TARGET)", "")
356 MOD_TARGET = $(MOD_NAME)
357endif
358
359ifeq ("$(OS)", "posix")
360 EXTRA_DEFINES += -D_XOPEN_SOURCE=600
361 LIBS = -lrt -lpthread -lm
362endif
363
364# Make sure that paths in EXTRA_INCLUDES are absolute
365ifneq ("$(EXTRA_INCLUDES)", "")
366 # Make sure that each directory is an absolute path
367 EXTRA_INCS = $(addprefix -I$(TOP_DIR)/, $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_INCLUDES))))
368endif
369ifneq ("$(EXTRA_ASINCLUDES)", "")
370 # Make sure that each directory is an absolute path
371 EXTRA_ASINCS = $(addprefix -I$(TOP_DIR)/, $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_ASINCLUDES))))
372endif
373ifneq ("$(EXTRA_asINCLUDES)", "")
374 # Make sure that each directory is an absolute path
375 EXTRA_asINCS = $(addprefix -I$(TOP_DIR)/, $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_asINCLUDES))))
376endif
377ifeq ("$(USE_LINT)", "y")
378 USE_LINT := yes
379endif
380ifeq ("$(USE_LINT)", "yes")
381 EXTRA_DEFINES += -DUSE_LINT
382endif
383
384EXTRA_DEFINES += $(USER_EXTRA_DEFINES) $(USER_EXTRA_$(UC_SUBSYSTEM)_DEFINES)
385EXTRA_CFLAGS += $(USER_EXTRA_CFLAGS) $(USER_EXTRA_$(UC_SUBSYSTEM)_CFLAGS)
386CFLAGS += $(ARCH_CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES)
387ASFLAGS += $(ARCH_FLAGS) $(EXTRA_ASFLAGS) $(EXTRA_ASINCS) $(EXTRA_ASDEFINES)
388asFLAGS += $(ARCH_FLAGS) $(EXTRA_asFLAGS) $(EXTRA_asINCS) $(EXTRA_asDEFINES)
389LFLAGS += $(ARCH_FLAGS) $(EXTRA_LFLAGS)
390DEP_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES)
391CLANG_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES) $(CLANG_OPTS)