BAL and Maple Release 2.2

Signed-off-by: Shad Ansari <developer@Carbon.local>
diff --git a/bal_release/mk/Makefile.config b/bal_release/mk/Makefile.config
new file mode 100644
index 0000000..169a649
--- /dev/null
+++ b/bal_release/mk/Makefile.config
@@ -0,0 +1,439 @@
+# 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", "linux_lib", "shared_lib"
+#			 Note: 
+#				For library module it is possible to specify "unitest" target in 
+#				mk/$(SUBSYSTEM)/modules.core / .apps
+#				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_bal_srcs - list of .c that have to be generated as part of the build from bal.objset
+# gen_bal_hdrs - list of .h that have to be generated as part of the build from bal.objset
+# gen_omci_srcs - list of .c that have to be generated as part of the build from omci.objset
+# gen_omci_hdrs - list of .h that have to be generated as part of the build from omci.objset
+# gen_omci_stack_srcs - list of .c that have to be generated as part of the build from omci_me_datamodel.csv
+# gen_omci_stack_hdrs - list of .h that have to be generated as part of the build from omci_me_datamodel.csv
+# 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_DEPS_OPT - similar to MOD_DEPS, but dependencies are optional and might not be present in the source tree.
+# 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
+# MOD_POST_BUILD - optional commands that should be executed after successful module build
+# 
+# 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 (core/apps)
+# ALL_LIB_MODULES - list of all lib modules in the current subsystem (core/apps)
+# ALL_APP_MODULES - list of all app modules in the current subsystem (core/apps)
+# 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 CLI support is not required
+# ENABLE_LOG - set "n" if 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" or "shared_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 for "lib" module and 
+#		$(OUT_DIR)/lib$(TARGET_LIB).so for "shared_lib"
+# MOD_TARGET - module target name, including path. By default it is 
+#	$(OUT_DIR)/$(MOD_NAME) for "app" modules
+#	$(TARGET_LIB_FNAME) for "lib" and "shared_lib" modules
+# CODEGEN_OUTPUT_DIR - output directory containing generated files
+
+TOOLCHAIN    ?= gcc
+OS           ?= posix
+DEBUG        ?= y
+BLD_DEP      ?= gcc
+USE_CLANG 	 ?= n
+
+export SHELL := /bin/bash
+
+export BOARD
+export TOOLCHAIN
+export OS
+export DEBUG
+export BLD_DEP
+export OS_KERNEL
+
+V ?= 0
+ifeq (x"$(V)", x"0")
+    SILENT_BUILD = @
+endif
+
+SRC_DIR		     = $(TOP_DIR)/$(MOD_DIR)
+OUT_DIR_BASE 	?= $(TOP_DIR)/build/$(SUBSYSTEM)
+OUT_DIR      	:= $(OUT_DIR_BASE)/$(MOD_DIR)
+
+#
+# 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
+
+ifneq ("$(BUILD_NC_AGENT)", "y")
+    override NC_AGENT := none
+endif
+
+# Include optional subsystem-specific configuration
+-include mk/$(SUBSYSTEM)/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
+
+CONFIG_DIR      = src/common/config
+OS_PLATFORM_DIR = src/$(SUBSYSTEM)/platform
+
+# CLI and logger support
+ENABLE_CLI ?= y
+ENABLE_LOG ?= y
+BAL_MONOLITHIC ?= y
+
+export ENABLE_CLI
+export ENABLE_LOG
+export BAL_MONOLITHIC
+
+#
+### 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)/src/datamodel/bin/codegen
+CODEGEN_EXE          = $(CODEGEN_DIR)/Teknovus.MetaStructure.CodeGenerator.exe
+
+OMCI_STACK_CODEGEN_INPUT_DIR = $(SRC_DIR)/me_codegen
+OMCI_STACK_CODEGEN_EXE = $(OUT_DIR)/omci_me_codegen
+
+BAL_MODEL_FILE		 = $(TOP_DIR)/src/datamodel/bal.objset
+OMCI_MODEL_FILE		 = $(TOP_DIR)/src/datamodel/omci.objset
+OMCI_STACK_MODEL_FILE = $(TOP_DIR)/src/datamodel/omci_me_datamodel.csv
+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_bal_srcs) $(gen_omci_srcs)
+    gen_bal_hdrs := 
+    gen_bal_srcs := 
+    gen_omci_hdrs := 
+    gen_omci_srcs := 
+    # Disable LINT and CLANG
+    USE_LINT = n
+    USE_CLANG = n
+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_bal_srcs)", "")
+    GEN_BAL_SRCS = $(strip $(gen_bal_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
+    _OBJS += $(GEN_BAL_SRCS:%.c=%.o)
+endif
+ifneq ("$(gen_bal_hdrs)", "")
+    GEN_BAL_HDRS = $(strip $(gen_bal_hdrs:%=$(CODEGEN_OUTPUT_DIR)/%))
+endif
+
+ifneq ("$(gen_omci_srcs)", "")
+    GEN_OMCI_SRCS = $(strip $(gen_omci_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
+    _OBJS += $(GEN_OMCI_SRCS:%.c=%.o)
+endif
+ifneq ("$(gen_omci_hdrs)", "")
+    GEN_OMCI_HDRS = $(strip $(gen_omci_hdrs:%=$(CODEGEN_OUTPUT_DIR)/%))
+endif
+
+ifneq ("$(gen_omci_stack_srcs)", "")
+    GEN_OMCI_STACK_SRCS = $(strip $(gen_omci_stack_srcs:%=$(CODEGEN_OUTPUT_DIR)/%))
+    _OBJS += $(GEN_OMCI_STACK_SRCS:%.c=%.o)
+endif
+ifneq ("$(gen_omci_stack_hdrs)", "")
+    GEN_OMCI_STACK_HDRS = $(strip $(gen_omci_stack_hdrs:%=$(CODEGEN_OUTPUT_DIR)/%))
+endif
+
+OBJS = $(strip $(_OBJS))
+
+GEN_SRCS = $(GEN_BAL_SRCS) $(GEN_OMCI_SRCS) $(GEN_OMCI_STACK_SRCS)
+GEN_HDRS = $(GEN_BAL_HDRS) $(GEN_OMCI_HDRS) $(GEN_OMCI_STACK_HDRS)
+
+# 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
+
+# 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)
+
+EXTRA_DEFINES   += -DBCM_SUBSYSTEM_$(UC_SUBSYSTEM) -DBCM_PLATFORM_$(UC_PLATFORM) -DBCM_OS_$(UC_OS)
+EXTRA_DEFINES   += -DBCM_SUBSYSTEM_HOST
+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
+
+ifneq ("$(CONFIG_MAC_RPC)", "n")
+EXTRA_DEFINES += -DCONFIG_MAC_RPC
+endif
+
+ifneq ("$(CONFIG_SWITCH_RPC)", "n")
+EXTRA_DEFINES += -DCONFIG_SWITCH_RPC
+endif
+
+ifneq ("$(BOARD)", "")
+EXTRA_DEFINES	+= -DBOARD=$(BOARD)
+endif
+
+ifeq ("$(BOARD)", "wrx")
+EXTRA_DEFINES	+= -DWRX_BUILD
+endif
+
+ifeq ("$(BUILD_OF_AGENT)", "y")
+EXTRA_DEFINES   += -DBUILD_OF_AGENT
+endif
+
+ifeq ("$(FORCE_PKTIN_SND)", "y")
+EXTRA_DEFINES   += -DFORCE_PKTIN_SND
+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
+
+ifeq ("$(BAL_MONOLITHIC)", "y")
+    EXTRA_DEFINES += -DBAL_MONOLITHIC
+endif
+
+EXTRA_INCLUDES  += -I$(SRC_DIR)
+EXTRA_INCLUDES  += -I$(TOP_SRC_DIR)/common/include -I$(OUT_DIR_BASE)/src/common/include
+
+OPT_DISABLE_$(UC_SUBSYSTEM) ?=n
+OPT_DISABLE := $(OPT_DISABLE_$(UC_SUBSYSTEM))
+
+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
+
+# 3rd party packages install location
+INSTALL_DIR ?= $(OUT_DIR_BASE)
+export INSTALL_DIR
+EXTRA_INCLUDES += -I$(INSTALL_DIR)/include
+
+PATH := $(INSTALL_DIR)/bin:$(PATH)
+export PATH
+
+# Shared library location
+SHARED_LIB_DIR ?= $(INSTALL_DIR)/lib
+export SHARED_LIB_DIR
+
+# Treat lib as shared lib if BUILD_SHARED_LIBS is y
+ifeq  ("$(BUILD_SHARED_LIBS)", "y")
+   export BUILD_SHARED_LIBS
+   ifeq  ("$(MOD_TYPE)", "lib")
+      MOD_TYPE = shared_lib
+   endif
+   EXTRA_LIBS_PATH += -L$(TOP_DIR)/$(LOCAL_MAPLE_SDK_DIR)/build/shared_libs
+endif
+EXTRA_LIBS_PATH += -L$(SHARED_LIB_DIR)
+
+# 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, $(abspath $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_INCLUDES)))))
+endif
+ifneq ("$(EXTRA_ASINCLUDES)", "")
+    # Make sure that each directory is an absolute path
+    EXTRA_ASINCS = $(addprefix -I, $(abspath $(subst -I,,$(subst $(TOP_DIR)/,,$(EXTRA_ASINCLUDES)))))
+endif
+ifneq ("$(EXTRA_asINCLUDES)", "")
+    # Make sure that each directory is an absolute path
+    EXTRA_asINCS = $(addprefix -I, $(abspath $(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)