blob: 169a6492e1155edda32779aad288dbf13eb48d1f [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", "linux_lib", "shared_lib"
7# Note:
8# For library module it is possible to specify "unitest" target in
9# mk/$(SUBSYSTEM)/modules.core / .apps
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_bal_srcs - list of .c that have to be generated as part of the build from bal.objset
18# gen_bal_hdrs - list of .h that have to be generated as part of the build from bal.objset
19# gen_omci_srcs - list of .c that have to be generated as part of the build from omci.objset
20# gen_omci_hdrs - list of .h that have to be generated as part of the build from omci.objset
21# gen_omci_stack_srcs - list of .c that have to be generated as part of the build from omci_me_datamodel.csv
22# gen_omci_stack_hdrs - list of .h that have to be generated as part of the build from omci_me_datamodel.csv
23# MOD_DEPS - list of modules the "current" module depends on. OS abstraction layer dependency
24# (module "os") is always present implicitly. For example, api_cli module's Makefile
25# includes the following line:
26# MOD_DEPS = cli api utils model
27# MOD_DEPS_OPT - similar to MOD_DEPS, but dependencies are optional and might not be present in the source tree.
28# MOD_INC_DIRS - used when module exports includes in directory(s) other than the module directory
29# MOD_DEFS - additional defines, including -D. the defines are added when compiling "this" module
30# and all modules depending on it
31# MOD_LIBS - additional libraries required by the module, including -l and -L
32# MOD_CUSTOM - if set "y", default rule for building the module is NOT provided.
33# In this case the rule for building $(MOD_TARGET) must be provided in module's Makefile
34# MOD_POST_BUILD - optional commands that should be executed after successful module build
35#
36# The following variables are not required in most cases, but supported nonetheless
37# EXTRA_CFLAGS - extra CFLAGS the module requires for compilation
38# EXTRA_INCLUDES - extra include directories the module requires for compilation (with -I)
39# EXTRA_LIBS_PATH - additional library search paths
40# EXTRA_LIBS additional libraries to link with
41#
42# The following variables are pre-set and can be used in module-specific Makefile
43# TOP_DIR - fully qualified top directory
44# MOD_DIR - module directory relative to the top directory
45# OUT_DIR_BASE - output directory base
46# ALL_MODULES - list of all modules in the current subsystem (core/apps)
47# ALL_LIB_MODULES - list of all lib modules in the current subsystem (core/apps)
48# ALL_APP_MODULES - list of all app modules in the current subsystem (core/apps)
49# SIMULATION_BUILD - set "y" for simulation build (CROSS_COMPILE is empty)
50# OS - OS
51# ENABLE_EPON - set "y" if EPON mode is included
52# ENABLE_GPON - set "y" if GPON mode is included
53# ENABLE_XGPON - set "y" if XGPON mode is included
54# ENABLE_GPON_OR_XGPON - set "y" if GPON or XGPON mode is included
55# ENABLE_CLI - set "n" if CLI support is not required
56# ENABLE_LOG - set "n" if logger support is not required
57#
58# USE_CLANG - set "y" to enable CLANG code pass for improved diagnostic
59#
60# The following variables are pre-set and can be used and/or overwritten in module-specific Makefile
61# SRC_DIR - fully-qualified source directory
62# OUT_DIR - module output directory
63# TARGET_LIB - library name for "lib" or "shared_lib" module. By default it is $(MOD_NAME)
64# TARGET_LIB_FNAME - module library file name including path.
65# By default it is $(OUT_DIR)/lib$(TARGET_LIB).a for "lib" module and
66# $(OUT_DIR)/lib$(TARGET_LIB).so for "shared_lib"
67# MOD_TARGET - module target name, including path. By default it is
68# $(OUT_DIR)/$(MOD_NAME) for "app" modules
69# $(TARGET_LIB_FNAME) for "lib" and "shared_lib" modules
70# CODEGEN_OUTPUT_DIR - output directory containing generated files
71
72TOOLCHAIN ?= gcc
73OS ?= posix
74DEBUG ?= y
75BLD_DEP ?= gcc
76USE_CLANG ?= n
77
78export SHELL := /bin/bash
79
80export BOARD
81export TOOLCHAIN
82export OS
83export DEBUG
84export BLD_DEP
85export OS_KERNEL
86
87V ?= 0
88ifeq (x"$(V)", x"0")
89 SILENT_BUILD = @
90endif
91
92SRC_DIR = $(TOP_DIR)/$(MOD_DIR)
93OUT_DIR_BASE ?= $(TOP_DIR)/build/$(SUBSYSTEM)
94OUT_DIR := $(OUT_DIR_BASE)/$(MOD_DIR)
95
96#
97# Compiler warning configuration
98# Some extra warnings are always enabled. Others must be opted in on the module level
99#
100ENABLE_EXTRA_WARNINGS ?= y
101export ENABLE_EXTRA_WARNINGS
102
103ifneq ("$(BUILD_NC_AGENT)", "y")
104 override NC_AGENT := none
105endif
106
107# Include optional subsystem-specific configuration
108-include mk/$(SUBSYSTEM)/Makefile.$(SUBSYSTEM).config
109
110ENABLE_EPON ?= y
111ENABLE_GPON ?= y
112ENABLE_XGPON ?= y
113
114ENABLE_GPON_OR_XGPON = n
115ifeq ("$(ENABLE_GPON)", "y")
116 ENABLE_GPON_OR_XGPON = y
117endif
118ifeq ("$(ENABLE_XGPON)", "y")
119 ENABLE_GPON_OR_XGPON = y
120endif
121export ENABLE_EPON
122export ENABLE_GPON
123export ENABLE_XGPON
124export ENABLE_GPON_OR_XGPON
125
126CONFIG_DIR = src/common/config
127OS_PLATFORM_DIR = src/$(SUBSYSTEM)/platform
128
129# CLI and logger support
130ENABLE_CLI ?= y
131ENABLE_LOG ?= y
132BAL_MONOLITHIC ?= y
133
134export ENABLE_CLI
135export ENABLE_LOG
136export BAL_MONOLITHIC
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)/src/datamodel/bin/codegen
148CODEGEN_EXE = $(CODEGEN_DIR)/Teknovus.MetaStructure.CodeGenerator.exe
149
150OMCI_STACK_CODEGEN_INPUT_DIR = $(SRC_DIR)/me_codegen
151OMCI_STACK_CODEGEN_EXE = $(OUT_DIR)/omci_me_codegen
152
153BAL_MODEL_FILE = $(TOP_DIR)/src/datamodel/bal.objset
154OMCI_MODEL_FILE = $(TOP_DIR)/src/datamodel/omci.objset
155OMCI_STACK_MODEL_FILE = $(TOP_DIR)/src/datamodel/omci_me_datamodel.csv
156MONO_VER ?= 4.3.2.467
157MONO_PATH ?= /opt/mono-$(MONO_VER)/bin/mono
158
159export SRC_DIR
160export OUT_DIR_BASE
161export OUT_DIR
162export MODEL_OUT_DIR
163
164ifeq ("$(wildcard $(MONO_PATH))", "")
165 # If we can't find Mono installed in the correct path, default to the current PATH version.
166 # In the future, we should always use Mono from a common tools directory.
167 # TODO: change this once the compiler/toolchain paths are better defined.
168 MONO_PATH = mono
169endif
170
171# Treat "yes" and "y" the same
172ifeq ("$(USE_CLANG)", "yes")
173 USE_CLANG := y
174endif
175ifeq ("$(USE_CLANG)", "y")
176 include $(MAKE_DIR)/clang.opts
177endif
178
179# Disable code generation in release build
180ifeq ("$(RELEASE_BUILD)", "y")
181 srcs := $(srcs) $(gen_bal_srcs) $(gen_omci_srcs)
182 gen_bal_hdrs :=
183 gen_bal_srcs :=
184 gen_omci_hdrs :=
185 gen_omci_srcs :=
186 # Disable LINT and CLANG
187 USE_LINT = n
188 USE_CLANG = n
189endif
190
191SRCS = $(strip $(srcs:%=$(SRC_DIR)/%))
192
193# In COMPILE_ALL_IN_ONE_GO mode all .c files of a module are compiled in
194# a single invocation of BLD_CC compiler. In result, objects files are created
195# in OUT_DIR even if module's .c files are spread in sub-directories
196ifeq ("$(COMPILE_ALL_IN_ONE_GO)", "y")
197 srcs_no_dir = $(notdir $(srcs))
198 _OBJS = $(srcs_no_dir:%.c=$(OUT_DIR)/%.o)
199else
200 _OBJS = $(srcs:%.c=$(OUT_DIR)/%.o)
201endif
202
203as_SRCS = $(strip $(as_srcs:%=$(SRC_DIR)/%))
204as_OBJS = $(as_srcs:%.s=$(OUT_DIR)/%.o)
205_OBJS += $(as_OBJS)
206
207AS_SRCS = $(strip $(AS_srcs:%=$(SRC_DIR)/%))
208AS_OBJS = $(AS_srcs:%.S=$(OUT_DIR)/%.o)
209_OBJS += $(AS_OBJS)
210
211ifneq ("$(gen_bal_srcs)", "")
212 GEN_BAL_SRCS = $(strip $(gen_bal_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
213 _OBJS += $(GEN_BAL_SRCS:%.c=%.o)
214endif
215ifneq ("$(gen_bal_hdrs)", "")
216 GEN_BAL_HDRS = $(strip $(gen_bal_hdrs:%=$(CODEGEN_OUTPUT_DIR)/%))
217endif
218
219ifneq ("$(gen_omci_srcs)", "")
220 GEN_OMCI_SRCS = $(strip $(gen_omci_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
221 _OBJS += $(GEN_OMCI_SRCS:%.c=%.o)
222endif
223ifneq ("$(gen_omci_hdrs)", "")
224 GEN_OMCI_HDRS = $(strip $(gen_omci_hdrs:%=$(CODEGEN_OUTPUT_DIR)/%))
225endif
226
227ifneq ("$(gen_omci_stack_srcs)", "")
228 GEN_OMCI_STACK_SRCS = $(strip $(gen_omci_stack_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
229 _OBJS += $(GEN_OMCI_STACK_SRCS:%.c=%.o)
230endif
231ifneq ("$(gen_omci_stack_hdrs)", "")
232 GEN_OMCI_STACK_HDRS = $(strip $(gen_omci_stack_hdrs:%=$(CODEGEN_OUTPUT_DIR)/%))
233endif
234
235OBJS = $(strip $(_OBJS))
236
237GEN_SRCS = $(GEN_BAL_SRCS) $(GEN_OMCI_SRCS) $(GEN_OMCI_STACK_SRCS)
238GEN_HDRS = $(GEN_BAL_HDRS) $(GEN_OMCI_HDRS) $(GEN_OMCI_STACK_HDRS)
239
240# Add default dependency on OS abstraction
241ifeq ("$(MOD_NAME)", "")
242 ifneq (x"$(V)", x"0")
243 $(info MOD_NAME is not set for $(SRC_DIR)/Makefile. Skipping..)
244 endif
245 MOD_TYPE = _skip_
246endif
247
248# Add default dependency on OS abstraction
249ifneq ("$(MOD_SUPPRESS_OS_DEP), "y)
250 ifeq ("$(MOD_TYPE)", "linux_module")
251 _kernel = y
252 endif
253 ifeq ("$(MOD_TYPE)", "linux_lib")
254 _kernel = y
255 endif
256 ifeq ("$(_kernel)", "y")
257 MOD_DEPS := os_linux $(MOD_DEPS)
258 else
259 MOD_DEPS := os $(MOD_DEPS)
260 endif
261endif
262
263# Extra types filter
264ifneq ("$(EXTRA_TYPES)", "")
265 EXTRA_TYPES := $(shell echo -n $(EXTRA_TYPES) | sed -e 's/ /\\|/g')
266 GEN_EXTRA_TYPES := -typeNameFilter=\^\($(EXTRA_TYPES)\)\$$
267endif
268
269OS_KERNEL ?= $(OS)
270UC_PLATFORM = $(shell echo $(PLATFORM) | tr a-z A-Z)
271UC_SUBSYSTEM = $(shell echo $(SUBSYSTEM) | tr a-z A-Z)
272UC_OS = $(shell echo $(OS) | tr a-z A-Z)
273UC_OS_KERNEL = $(shell echo $(OS_KERNEL) | tr a-z A-Z)
274
275EXTRA_DEFINES += -DBCM_SUBSYSTEM_$(UC_SUBSYSTEM) -DBCM_PLATFORM_$(UC_PLATFORM) -DBCM_OS_$(UC_OS)
276EXTRA_DEFINES += -DBCM_SUBSYSTEM_HOST
277EXTRA_DEFINES += -D$(UC_OS_KERNEL)_KERNEL_SPACE
278ifeq ("$(ENABLE_EPON)", "y")
279 EXTRA_DEFINES += -DBCM_EPON
280endif
281ifeq ("$(ENABLE_GPON)", "y")
282 EXTRA_DEFINES += -DBCM_GPON
283endif
284ifeq ("$(ENABLE_XGPON)", "y")
285 EXTRA_DEFINES += -DBCM_XGPON
286endif
287
288ifneq ("$(CONFIG_MAC_RPC)", "n")
289EXTRA_DEFINES += -DCONFIG_MAC_RPC
290endif
291
292ifneq ("$(CONFIG_SWITCH_RPC)", "n")
293EXTRA_DEFINES += -DCONFIG_SWITCH_RPC
294endif
295
296ifneq ("$(BOARD)", "")
297EXTRA_DEFINES += -DBOARD=$(BOARD)
298endif
299
300ifeq ("$(BOARD)", "wrx")
301EXTRA_DEFINES += -DWRX_BUILD
302endif
303
304ifeq ("$(BUILD_OF_AGENT)", "y")
305EXTRA_DEFINES += -DBUILD_OF_AGENT
306endif
307
308ifeq ("$(FORCE_PKTIN_SND)", "y")
309EXTRA_DEFINES += -DFORCE_PKTIN_SND
310endif
311
312# Build unitests for simulation and from Jenkins jobs
313UNITEST ?= n
314
315ifeq ("$(SIMULATION_BUILD)", "y")
316 EXTRA_DEFINES += -DSIMULATION_BUILD
317 UNITEST = y
318endif
319
320ifeq ("$(JENKINS_BUILD)", "y")
321 UNITEST = y
322endif
323
324ifeq ("$(BAL_MONOLITHIC)", "y")
325 EXTRA_DEFINES += -DBAL_MONOLITHIC
326endif
327
328EXTRA_INCLUDES += -I$(SRC_DIR)
329EXTRA_INCLUDES += -I$(TOP_SRC_DIR)/common/include -I$(OUT_DIR_BASE)/src/common/include
330
331OPT_DISABLE_$(UC_SUBSYSTEM) ?=n
332OPT_DISABLE := $(OPT_DISABLE_$(UC_SUBSYSTEM))
333
334ARCH_CFLAGS = $(ARCH_FLAGS)
335ifeq ("$(OPT_DISABLE)", "y")
336 ARCH_CFLAGS += $(DEBUG_O_CFLAGS)
337 EXTRA_LFLAGS += $(DEBUG_O_LFLAGS)
338 EXTRA_ASFLAGS += $(DEBUG_O_ASFLAGS)
339 EXTRA_asFLAGS += $(DEBUG_O_asLAGS)
340else
341 ARCH_CFLAGS += $(RELEASE_O_CFLAGS)
342 EXTRA_LFLAGS += $(RELEASE_O_LFLAGS)
343 EXTRA_ASFLAGS += $(RELEASE_O_ASFLAGS)
344 EXTRA_asFLAGS += $(RELEASE_O_asFLAGS)
345endif
346
347# 3rd party packages install location
348INSTALL_DIR ?= $(OUT_DIR_BASE)
349export INSTALL_DIR
350EXTRA_INCLUDES += -I$(INSTALL_DIR)/include
351
352PATH := $(INSTALL_DIR)/bin:$(PATH)
353export PATH
354
355# Shared library location
356SHARED_LIB_DIR ?= $(INSTALL_DIR)/lib
357export SHARED_LIB_DIR
358
359# Treat lib as shared lib if BUILD_SHARED_LIBS is y
360ifeq ("$(BUILD_SHARED_LIBS)", "y")
361 export BUILD_SHARED_LIBS
362 ifeq ("$(MOD_TYPE)", "lib")
363 MOD_TYPE = shared_lib
364 endif
365 EXTRA_LIBS_PATH += -L$(TOP_DIR)/$(LOCAL_MAPLE_SDK_DIR)/build/shared_libs
366endif
367EXTRA_LIBS_PATH += -L$(SHARED_LIB_DIR)
368
369# Calculate MOD_TARGET based on MOD_TYPE
370ifeq ("$(MOD_TYPE)", "lib")
371 ifneq ("$(OBJS)", "")
372 TARGET_LIB ?= $(MOD_NAME)
373 TARGET_LIB_FNAME ?= $(OUT_DIR)/lib$(TARGET_LIB).a
374 endif
375 MOD_TARGET ?= $(TARGET_LIB_FNAME)
376else ifeq ("$(MOD_TYPE)", "shared_lib")
377 ifneq ("$(OBJS)", "")
378 TARGET_LIB ?= $(MOD_NAME)
379 TARGET_LIB_FNAME ?= $(OUT_DIR)/lib$(TARGET_LIB).so
380 endif
381 MOD_TARGET ?= $(TARGET_LIB_FNAME)
382else ifeq ("$(MOD_TYPE)", "app")
383 MOD_TARGET ?= $(OUT_DIR)/$(MOD_NAME)
384else ifeq ("$(MOD_TYPE)", "linux_module")
385 ifeq ("$(KERNELDIR)", "")
386 $(error KERNELDIR must be set in board profile)
387 endif
388 ifeq ("$(KERNEL_ARCH)", "")
389 $(error KERNEL_ARCH must be set in board profile)
390 endif
391 ifeq ("$(KERNEL_OUTDIR)", "")
392 KERNEL_OUTDIR := $(KERNELDIR)
393 endif
394 MOD_TARGET ?= $(SRC_DIR)/$(MOD_NAME).ko
395else ifeq ("$(MOD_TYPE)", "linux_lib")
396 MOD_TARGET ?= $(OUT_DIR_BASE)/$(MOD_NAME).linuxlib
397else ifeq ("$(MOD_TYPE)", "_skip_")
398 MOD_TARGET = .dummy
399else
400 $(error MOD_TYPE $(MOD_TYPE) is incorrect for module $(MOD_NAME). Must be lib or app)
401endif
402
403ifeq ("$(MOD_TARGET)", "")
404 MOD_TARGET = $(MOD_NAME)
405endif
406
407ifeq ("$(OS)", "posix")
408 EXTRA_DEFINES += -D_XOPEN_SOURCE=600
409 LIBS = -lrt -lpthread -lm
410endif
411
412# Make sure that paths in EXTRA_INCLUDES are absolute
413ifneq ("$(EXTRA_INCLUDES)", "")
414 # Make sure that each directory is an absolute path
415 EXTRA_INCS = $(addprefix -I, $(abspath $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_INCLUDES)))))
416endif
417ifneq ("$(EXTRA_ASINCLUDES)", "")
418 # Make sure that each directory is an absolute path
419 EXTRA_ASINCS = $(addprefix -I, $(abspath $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_ASINCLUDES)))))
420endif
421ifneq ("$(EXTRA_asINCLUDES)", "")
422 # Make sure that each directory is an absolute path
423 EXTRA_asINCS = $(addprefix -I, $(abspath $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_asINCLUDES)))))
424endif
425ifeq ("$(USE_LINT)", "y")
426 USE_LINT := yes
427endif
428ifeq ("$(USE_LINT)", "yes")
429 EXTRA_DEFINES += -DUSE_LINT
430endif
431
432EXTRA_DEFINES += $(USER_EXTRA_DEFINES) $(USER_EXTRA_$(UC_SUBSYSTEM)_DEFINES)
433EXTRA_CFLAGS += $(USER_EXTRA_CFLAGS) $(USER_EXTRA_$(UC_SUBSYSTEM)_CFLAGS)
434CFLAGS += $(ARCH_CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES)
435ASFLAGS += $(ARCH_FLAGS) $(EXTRA_ASFLAGS) $(EXTRA_ASINCS) $(EXTRA_ASDEFINES)
436asFLAGS += $(ARCH_FLAGS) $(EXTRA_asFLAGS) $(EXTRA_asINCS) $(EXTRA_asDEFINES)
437LFLAGS += $(ARCH_FLAGS) $(EXTRA_LFLAGS)
438DEP_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES)
439CLANG_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES) $(CLANG_OPTS)