blob: 908239a41ea4a886cd6d0d5e7d1f5cc0bda6300d [file] [log] [blame]
# Common Makefile configuration
#
# The following variables must be set
# MOD_NAME - module name. Depending on MOD_TYPE can be encapsulated (e.g., MOD_NAME=os --> libos.a)
# MOD_TYPE - module type. Supported types currently are "lib", "app", "linux_module" and "linux_lib"
# Note:
# For library module it is possible to specify "unitest" target in
# $(MAKE_DEVICE_DIR)/modules.host / embedded.
# In this case unitest.c is compiled and linked with its module library.
# However, MOD_TYPE remains a "lib".
#
# The following variables are optional
# srcs - list of .c source files relative to SRC_DIR
# as_srcs - list of .s (lower case s) source files relative to SRC_DIR
# AS_srcs - list of .S (upper case .S) source files relative to SRC_DIR
# gen_srcs - list of .c that have to be generated as part of the build
# MOD_DEPS - list of modules the "current" module depends on. OS abstraction layer dependency
# (module "os") is always present implicitly. For example, api_cli module's Makefile
# includes the following line:
# MOD_DEPS = cli api utils model
# MOD_INC_DIRS - used when module exports includes in directory(s) other than the module directory
# MOD_DEFS - additional defines, including -D. the defines are added when compiling "this" module
# and all modules depending on it
# MOD_LIBS - additional libraries required by the module, including -l and -L
# MOD_CUSTOM - if set "y", default rule for building the module is NOT provided.
# In this case the rule for building $(MOD_TARGET) must be provided in module's Makefile
#
# The following variables are not required in most cases, but supported nonetheless
# EXTRA_CFLAGS - extra CFLAGS the module requires for compilation
# EXTRA_INCLUDES - extra include directories the module requires for compilation (with -I)
# EXTRA_LIBS_PATH - additional library search paths
# EXTRA_LIBS additional libraries to link with
#
# The following variables are pre-set and can be used in module-specific Makefile
# TOP_DIR - fully qualified top directory
# MOD_DIR - module directory relative to the top directory
# OUT_DIR_BASE - output directory base
# ALL_MODULES - list of all modules in the current subsystem (host/embedded)
# ALL_LIB_MODULES - list of all lib modules in the current subsystem (host/embedded)
# ALL_APP_MODULES - list of all app modules in the current subsystem (host/embedded)
# SIMULATION_BUILD - set "y" for simulation build (CROSS_COMPILE is empty)
# OS - OS
# ENABLE_EPON - set "y" if EPON mode is included
# ENABLE_GPON - set "y" if GPON mode is included
# ENABLE_XGPON - set "y" if XGPON mode is included
# ENABLE_GPON_OR_XGPON - set "y" if GPON or XGPON mode is included
# ENABLE_CLI - set "n" if host CLI support is not required
# ENABLE_LOG - set "n" if host logger support is not required
#
# USE_CLANG - set "y" to enable CLANG code pass for improved diagnostic
#
# The following variables are pre-set and can be used and/or overwritten in module-specific Makefile
# SRC_DIR - fully-qualified source directory
# OUT_DIR - module output directory
# TARGET_LIB - library name for "lib" module. By default it is $(MOD_NAME)
# TARGET_LIB_FNAME - module library file name including path. By default it is $(OUT_DIR)/lib$(TARGET_LIB).a
# MOD_TARGET - module target name, including path. By default it is
# $(OUT_DIR)/$(MOD_NAME) for "app" modules
# $(TARGET_LIB_FNAME) for "lib" modules
# CODEGEN_OUTPUT_DIR - output directory containing generated files
TOOLCHAIN ?= gcc
OS ?= posix
DEBUG ?= y
BLD_DEP ?= gcc
USE_CLANG ?= n
export BOARD
export TOOLCHAIN
export OS
export DEBUG
export BLD_DEP
export OS_KERNEL
V ?= 0
ifeq (x"$(V)", x"0")
SILENT_BUILD = @
endif
#
# Compiler warning configuration
# Some extra warnings are always enabled. Others must be opted in on the module level
#
ENABLE_EXTRA_WARNINGS ?= y
export ENABLE_EXTRA_WARNINGS
# Include optional platform-specific configuration
-include $(MAKE_DEVICE_DIR)/Makefile.$(SUBSYSTEM).config
ENABLE_EPON ?= y
ENABLE_GPON ?= y
ENABLE_XGPON ?= y
ENABLE_GPON_OR_XGPON = n
ifeq ("$(ENABLE_GPON)", "y")
ENABLE_GPON_OR_XGPON = y
endif
ifeq ("$(ENABLE_XGPON)", "y")
ENABLE_GPON_OR_XGPON = y
endif
export ENABLE_EPON
export ENABLE_GPON
export ENABLE_XGPON
export ENABLE_GPON_OR_XGPON
SRC_DIR = $(TOP_DIR)/$(MOD_DIR)
ifeq ("$(RELEASE_BUILD)", "y")
OUT_DIR_BASE ?= $(TOP_DIR)/build
OUT_DIR = $(OUT_DIR_BASE)/$(MOD_DIR)
MODEL_OUT_DIR= $(TOP_DIR)/host_driver/model
CONFIG_DIR = host_driver/config
else
OUT_DIR_BASE ?= $(TOP_DIR)/build/$(PLATFORM)/$(SUBSYSTEM)
OUT_DIR = $(OUT_DIR_BASE)/$(MOD_DIR)
MODEL_OUT_DIR= $(OUT_DIR_BASE)/common/model/$(PLATFORM)
CONFIG_DIR = $(SUBSYSTEM)/config
OS_PLATFORM_DIR = $(SUBSYSTEM)/os_abstraction/$(PLATFORM)
endif
# Host CLI and logger support
ENABLE_CLI ?= y
ENABLE_LOG ?= y
ENABLE_KT2 ?= n
MOD_DEFS += -DUSE_DRIVER_CLI=1 -DFULL_DRIVER=1 -DCFE_DRIVER=0
export ENABLE_CLI
export ENABLE_LOG
export ENABLE_KT2
ifeq ("$(SUBSYSTEM)", "embedded")
override ENABLE_CLI = y
override ENABLE_LOG = y
endif
#
### Include module Makefile
# For MOD_CUSTOM only will be included in Makefile.rules second time for propagate custom rules
#
include $(SRC_DIR)/Makefile
# Code-generator - related parameters
CODEGEN_INPUT_DIR = $(SRC_DIR)/codegen_templates
CODEGEN_OUTPUT_DIR = $(OUT_DIR)
CODEGEN_DIR = $(TOP_DIR)/bin/codegen
MODEL_FILE = $(TOP_DIR)/common/model/$(PLATFORM)/$(PLATFORM).objset
CODEGEN_EXE = $(CODEGEN_DIR)/Teknovus.MetaStructure.CodeGenerator.exe
MONO_VER ?= 4.3.2.467
MONO_PATH ?= /opt/mono-$(MONO_VER)/bin/mono
export SRC_DIR
export OUT_DIR_BASE
export OUT_DIR
export MODEL_OUT_DIR
ifeq ("$(wildcard $(MONO_PATH))", "")
# If we can't find Mono installed in the correct path, default to the current PATH version.
# In the future, we should always use Mono from a common tools directory.
# TODO: change this once the compiler/toolchain paths are better defined.
MONO_PATH = mono
endif
# Treat "yes" and "y" the same
ifeq ("$(USE_CLANG)", "yes")
USE_CLANG := y
endif
ifeq ("$(USE_CLANG)", "y")
include $(MAKE_DIR)/clang.opts
endif
# Disable code generation in release build
ifeq ("$(RELEASE_BUILD)", "y")
srcs := $(srcs) $(gen_srcs)
gen_srcs :=
# Disable LINT and CLANG
USE_LINT = n
USE_CLANG = n
EXTRA_DEFINES += -DRELEASE_BUILD
endif
SRCS = $(strip $(srcs:%=$(SRC_DIR)/%))
# In COMPILE_ALL_IN_ONE_GO mode all .c files of a module are compiled in
# a single invocation of BLD_CC compiler. In result, objects files are created
# in OUT_DIR even if module's .c files are spread in sub-directories
ifeq ("$(COMPILE_ALL_IN_ONE_GO)", "y")
srcs_no_dir = $(notdir $(srcs))
_OBJS = $(srcs_no_dir:%.c=$(OUT_DIR)/%.o)
else
_OBJS = $(srcs:%.c=$(OUT_DIR)/%.o)
endif
as_SRCS = $(strip $(as_srcs:%=$(SRC_DIR)/%))
as_OBJS = $(as_srcs:%.s=$(OUT_DIR)/%.o)
_OBJS += $(as_OBJS)
AS_SRCS = $(strip $(AS_srcs:%=$(SRC_DIR)/%))
AS_OBJS = $(AS_srcs:%.S=$(OUT_DIR)/%.o)
_OBJS += $(AS_OBJS)
ifneq ("$(gen_srcs)", "")
GEN_SRCS = $(strip $(gen_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
_OBJS += $(GEN_SRCS:%.c=%.o)
endif
OBJS = $(strip $(_OBJS))
# Add default dependency on OS abstraction
ifeq ("$(MOD_NAME)", "")
ifneq (x"$(V)", x"0")
$(info MOD_NAME is not set for $(SRC_DIR)/Makefile. Skipping..)
endif
MOD_TYPE = _skip_
endif
# Add default dependency on OS abstraction
ifneq ("$(MOD_SUPPRESS_OS_DEP), "y)
ifeq ("$(MOD_TYPE)", "linux_module")
_kernel = y
endif
ifeq ("$(MOD_TYPE)", "linux_lib")
_kernel = y
endif
ifeq ("$(_kernel)", "y")
MOD_DEPS := os_linux $(MOD_DEPS)
else
MOD_DEPS := os $(MOD_DEPS)
endif
endif
# GEN_OBJTAGS define which objects are generated. If not set explicitly,
# derive it from ENABLE_EPON, ENABLE_GPON, ENABLE_XGPON flags
ifeq ("$(GEN_OBJTAGS)", "")
ifeq ("$(ENABLE_EPON)", "y")
GEN_OBJTAGS := $(GEN_OBJTAGS),EPON,AE
endif
ifeq ("$(ENABLE_GPON)", "y")
GEN_OBJTAGS := $(GEN_OBJTAGS),GPON
endif
ifeq ("$(ENABLE_XGPON)", "y")
GEN_OBJTAGS := $(GEN_OBJTAGS),XGPON
endif
ifeq ("$(GEN_OBJTAGS)", "")
$(error At least one of ENABLE_EPON, ENABLE_GPON, ENABLE_XGPON must be set =y)
endif
endif
# Extra types filter
ifneq ("$(EXTRA_TYPES)", "")
EXTRA_TYPES := $(shell echo -n $(EXTRA_TYPES) | sed -e 's/ /\\|/g')
GEN_EXTRA_TYPES := -typeNameFilter=\^\($(EXTRA_TYPES)\)\$$
endif
OS_KERNEL ?= $(OS)
UC_PLATFORM = $(shell echo $(PLATFORM) | tr a-z A-Z)
UC_SUBSYSTEM = $(shell echo $(SUBSYSTEM) | tr a-z A-Z)
UC_OS = $(shell echo $(OS) | tr a-z A-Z)
UC_OS_KERNEL = $(shell echo $(OS_KERNEL) | tr a-z A-Z)
BUILD_TIME = $(shell date +%s)
BUILD_TIME_ZONE = $(shell date +%:z)
EXTRA_CFLAGS += -DBUILD_TIME=$(BUILD_TIME) -DBUILD_TIME_ZONE='"$(BUILD_TIME_ZONE)"'
EXTRA_DEFINES += -DBCM_SUBSYSTEM_$(UC_SUBSYSTEM) -DBCM_PLATFORM_$(UC_PLATFORM) -DBCM_OS_$(UC_OS)
EXTRA_DEFINES += -D$(UC_OS_KERNEL)_KERNEL_SPACE
ifeq ("$(ENABLE_EPON)", "y")
EXTRA_DEFINES += -DBCM_EPON
endif
ifeq ("$(ENABLE_GPON)", "y")
EXTRA_DEFINES += -DBCM_GPON
endif
ifeq ("$(ENABLE_XGPON)", "y")
EXTRA_DEFINES += -DBCM_XGPON
endif
# Build unitests for simulation and from Jenkins jobs
UNITEST ?= n
ifeq ("$(SIMULATION_BUILD)", "y")
EXTRA_DEFINES += -DSIMULATION_BUILD
UNITEST = y
endif
ifeq ("$(JENKINS_BUILD)", "y")
UNITEST = y
endif
EXTRA_INCLUDES += -I$(SRC_DIR)
OPT_DISABLE_EMBEDDED ?= n
OPT_DISABLE_HOST ?=n
ifeq ("OPT_DISABLE_$(UC_SUBSYSTEM)", "OPT_DISABLE_EMBEDDED")
OPT_DISABLE := $(OPT_DISABLE_EMBEDDED)
else
OPT_DISABLE := $(OPT_DISABLE_HOST)
endif
ARCH_CFLAGS = $(ARCH_FLAGS)
ifeq ("$(OPT_DISABLE)", "y")
ARCH_CFLAGS += $(DEBUG_O_CFLAGS)
EXTRA_LFLAGS += $(DEBUG_O_LFLAGS)
EXTRA_ASFLAGS += $(DEBUG_O_ASFLAGS)
EXTRA_asFLAGS += $(DEBUG_O_asLAGS)
else
ARCH_CFLAGS += $(RELEASE_O_CFLAGS)
EXTRA_LFLAGS += $(RELEASE_O_LFLAGS)
EXTRA_ASFLAGS += $(RELEASE_O_ASFLAGS)
EXTRA_asFLAGS += $(RELEASE_O_asFLAGS)
endif
# Treat lib as shared lib if BUILD_SHARED_LIBS is y
ifeq ("$(BUILD_SHARED_LIBS)", "y")
ifeq ("$(MOD_TYPE)", "lib")
MOD_TYPE = shared_lib
endif
SHARED_LIB_PATH ?= $(OUT_DIR_BASE)/shared_libs
endif
# Calculate MOD_TARGET based on MOD_TYPE
ifeq ("$(MOD_TYPE)", "lib")
ifneq ("$(OBJS)", "")
TARGET_LIB ?= $(MOD_NAME)
TARGET_LIB_FNAME ?= $(OUT_DIR)/lib$(TARGET_LIB).a
endif
MOD_TARGET ?= $(TARGET_LIB_FNAME)
else ifeq ("$(MOD_TYPE)", "shared_lib")
ifneq ("$(OBJS)", "")
TARGET_LIB ?= $(MOD_NAME)
TARGET_LIB_FNAME ?= $(OUT_DIR)/lib$(TARGET_LIB).so
endif
MOD_TARGET ?= $(TARGET_LIB_FNAME)
else ifeq ("$(MOD_TYPE)", "app")
MOD_TARGET ?= $(OUT_DIR)/$(MOD_NAME)
else ifeq ("$(MOD_TYPE)", "linux_module")
ifeq ("$(KERNELDIR)", "")
$(error KERNELDIR must be set in board profile)
endif
ifeq ("$(KERNEL_ARCH)", "")
$(error KERNEL_ARCH must be set in board profile)
endif
ifeq ("$(KERNEL_OUTDIR)", "")
KERNEL_OUTDIR := $(KERNELDIR)
endif
MOD_TARGET ?= $(SRC_DIR)/$(MOD_NAME).ko
else ifeq ("$(MOD_TYPE)", "linux_lib")
MOD_TARGET ?= $(OUT_DIR_BASE)/$(MOD_NAME).linuxlib
else ifeq ("$(MOD_TYPE)", "_skip_")
MOD_TARGET = .dummy
else
$(error MOD_TYPE $(MOD_TYPE) is incorrect for module $(MOD_NAME). Must be lib or app)
endif
ifeq ("$(MOD_TARGET)", "")
MOD_TARGET = $(MOD_NAME)
endif
ifeq ("$(OS)", "posix")
EXTRA_DEFINES += -D_XOPEN_SOURCE=600
LIBS = -lrt -lpthread -lm
endif
# Make sure that paths in EXTRA_INCLUDES are absolute
ifneq ("$(EXTRA_INCLUDES)", "")
# Make sure that each directory is an absolute path
EXTRA_INCS = $(addprefix -I$(TOP_DIR)/, $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_INCLUDES))))
endif
ifneq ("$(EXTRA_ASINCLUDES)", "")
# Make sure that each directory is an absolute path
EXTRA_ASINCS = $(addprefix -I$(TOP_DIR)/, $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_ASINCLUDES))))
endif
ifneq ("$(EXTRA_asINCLUDES)", "")
# Make sure that each directory is an absolute path
EXTRA_asINCS = $(addprefix -I$(TOP_DIR)/, $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_asINCLUDES))))
endif
ifeq ("$(USE_LINT)", "y")
USE_LINT := yes
endif
ifeq ("$(USE_LINT)", "yes")
EXTRA_DEFINES += -DUSE_LINT
endif
EXTRA_DEFINES += $(USER_EXTRA_DEFINES) $(USER_EXTRA_$(UC_SUBSYSTEM)_DEFINES)
EXTRA_CFLAGS += $(USER_EXTRA_CFLAGS) $(USER_EXTRA_$(UC_SUBSYSTEM)_CFLAGS)
CFLAGS += $(ARCH_CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES)
ASFLAGS += $(ARCH_FLAGS) $(EXTRA_ASFLAGS) $(EXTRA_ASINCS) $(EXTRA_ASDEFINES)
asFLAGS += $(ARCH_FLAGS) $(EXTRA_asFLAGS) $(EXTRA_asINCS) $(EXTRA_asDEFINES)
LFLAGS += $(ARCH_FLAGS) $(EXTRA_LFLAGS)
DEP_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES)
CLANG_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES) $(CLANG_OPTS)