Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | # 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 | |
| 63 | TOOLCHAIN ?= gcc |
| 64 | OS ?= posix |
| 65 | DEBUG ?= y |
| 66 | BLD_DEP ?= gcc |
| 67 | USE_CLANG ?= n |
| 68 | |
| 69 | export BOARD |
| 70 | export TOOLCHAIN |
| 71 | export OS |
| 72 | export DEBUG |
| 73 | export BLD_DEP |
| 74 | export OS_KERNEL |
| 75 | |
| 76 | V ?= 0 |
| 77 | ifeq (x"$(V)", x"0") |
| 78 | SILENT_BUILD = @ |
| 79 | endif |
| 80 | |
| 81 | # |
| 82 | # Compiler warning configuration |
| 83 | # Some extra warnings are always enabled. Others must be opted in on the module level |
| 84 | # |
| 85 | ENABLE_EXTRA_WARNINGS ?= y |
| 86 | export ENABLE_EXTRA_WARNINGS |
| 87 | |
| 88 | # Include optional platform-specific configuration |
| 89 | -include $(MAKE_DEVICE_DIR)/Makefile.$(SUBSYSTEM).config |
| 90 | |
| 91 | ENABLE_EPON ?= y |
| 92 | ENABLE_GPON ?= y |
| 93 | ENABLE_XGPON ?= y |
| 94 | |
| 95 | ENABLE_GPON_OR_XGPON = n |
| 96 | ifeq ("$(ENABLE_GPON)", "y") |
| 97 | ENABLE_GPON_OR_XGPON = y |
| 98 | endif |
| 99 | ifeq ("$(ENABLE_XGPON)", "y") |
| 100 | ENABLE_GPON_OR_XGPON = y |
| 101 | endif |
| 102 | export ENABLE_EPON |
| 103 | export ENABLE_GPON |
| 104 | export ENABLE_XGPON |
| 105 | export ENABLE_GPON_OR_XGPON |
| 106 | |
| 107 | SRC_DIR = $(TOP_DIR)/$(MOD_DIR) |
| 108 | |
| 109 | ifeq ("$(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 |
| 114 | else |
| 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) |
| 120 | endif |
| 121 | |
| 122 | # Host CLI and logger support |
| 123 | ENABLE_CLI ?= y |
| 124 | ENABLE_LOG ?= y |
| 125 | ENABLE_KT2 ?= n |
| 126 | |
| 127 | MOD_DEFS += -DUSE_DRIVER_CLI=1 -DFULL_DRIVER=1 -DCFE_DRIVER=0 |
| 128 | |
| 129 | export ENABLE_CLI |
| 130 | export ENABLE_LOG |
| 131 | export ENABLE_KT2 |
| 132 | |
| 133 | ifeq ("$(SUBSYSTEM)", "embedded") |
| 134 | override ENABLE_CLI = y |
| 135 | override ENABLE_LOG = y |
| 136 | endif |
| 137 | |
| 138 | # |
| 139 | ### Include module Makefile |
| 140 | # For MOD_CUSTOM only will be included in Makefile.rules second time for propagate custom rules |
| 141 | # |
| 142 | include $(SRC_DIR)/Makefile |
| 143 | |
| 144 | # Code-generator - related parameters |
| 145 | CODEGEN_INPUT_DIR = $(SRC_DIR)/codegen_templates |
| 146 | CODEGEN_OUTPUT_DIR = $(OUT_DIR) |
| 147 | CODEGEN_DIR = $(TOP_DIR)/bin/codegen |
| 148 | MODEL_FILE = $(TOP_DIR)/common/model/$(PLATFORM)/$(PLATFORM).objset |
| 149 | CODEGEN_EXE = $(CODEGEN_DIR)/Teknovus.MetaStructure.CodeGenerator.exe |
| 150 | MONO_VER ?= 4.3.2.467 |
| 151 | MONO_PATH ?= /opt/mono-$(MONO_VER)/bin/mono |
| 152 | |
| 153 | export SRC_DIR |
| 154 | export OUT_DIR_BASE |
| 155 | export OUT_DIR |
| 156 | export MODEL_OUT_DIR |
| 157 | |
| 158 | ifeq ("$(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 |
| 163 | endif |
| 164 | |
| 165 | # Treat "yes" and "y" the same |
| 166 | ifeq ("$(USE_CLANG)", "yes") |
| 167 | USE_CLANG := y |
| 168 | endif |
| 169 | ifeq ("$(USE_CLANG)", "y") |
| 170 | include $(MAKE_DIR)/clang.opts |
| 171 | endif |
| 172 | |
| 173 | # Disable code generation in release build |
| 174 | ifeq ("$(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 |
| 181 | endif |
| 182 | |
| 183 | SRCS = $(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 |
| 188 | ifeq ("$(COMPILE_ALL_IN_ONE_GO)", "y") |
| 189 | srcs_no_dir = $(notdir $(srcs)) |
| 190 | _OBJS = $(srcs_no_dir:%.c=$(OUT_DIR)/%.o) |
| 191 | else |
| 192 | _OBJS = $(srcs:%.c=$(OUT_DIR)/%.o) |
| 193 | endif |
| 194 | |
| 195 | as_SRCS = $(strip $(as_srcs:%=$(SRC_DIR)/%)) |
| 196 | as_OBJS = $(as_srcs:%.s=$(OUT_DIR)/%.o) |
| 197 | _OBJS += $(as_OBJS) |
| 198 | |
| 199 | AS_SRCS = $(strip $(AS_srcs:%=$(SRC_DIR)/%)) |
| 200 | AS_OBJS = $(AS_srcs:%.S=$(OUT_DIR)/%.o) |
| 201 | _OBJS += $(AS_OBJS) |
| 202 | |
| 203 | ifneq ("$(gen_srcs)", "") |
| 204 | GEN_SRCS = $(strip $(gen_srcs:%=$(CODEGEN_OUTPUT_DIR)/%)) |
| 205 | _OBJS += $(GEN_SRCS:%.c=%.o) |
| 206 | endif |
| 207 | OBJS = $(strip $(_OBJS)) |
| 208 | |
| 209 | # Add default dependency on OS abstraction |
| 210 | ifeq ("$(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_ |
| 215 | endif |
| 216 | |
| 217 | # Add default dependency on OS abstraction |
| 218 | ifneq ("$(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 |
| 230 | endif |
| 231 | |
| 232 | # GEN_OBJTAGS define which objects are generated. If not set explicitly, |
| 233 | # derive it from ENABLE_EPON, ENABLE_GPON, ENABLE_XGPON flags |
| 234 | ifeq ("$(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 |
| 247 | endif |
| 248 | |
| 249 | # Extra types filter |
| 250 | ifneq ("$(EXTRA_TYPES)", "") |
| 251 | EXTRA_TYPES := $(shell echo -n $(EXTRA_TYPES) | sed -e 's/ /\\|/g') |
| 252 | GEN_EXTRA_TYPES := -typeNameFilter=\^\($(EXTRA_TYPES)\)\$$ |
| 253 | endif |
| 254 | |
| 255 | OS_KERNEL ?= $(OS) |
| 256 | UC_PLATFORM = $(shell echo $(PLATFORM) | tr a-z A-Z) |
| 257 | UC_SUBSYSTEM = $(shell echo $(SUBSYSTEM) | tr a-z A-Z) |
| 258 | UC_OS = $(shell echo $(OS) | tr a-z A-Z) |
| 259 | UC_OS_KERNEL = $(shell echo $(OS_KERNEL) | tr a-z A-Z) |
| 260 | |
| 261 | BUILD_TIME = $(shell date +%s) |
| 262 | BUILD_TIME_ZONE = $(shell date +%:z) |
| 263 | EXTRA_CFLAGS += -DBUILD_TIME=$(BUILD_TIME) -DBUILD_TIME_ZONE='"$(BUILD_TIME_ZONE)"' |
| 264 | |
| 265 | EXTRA_DEFINES += -DBCM_SUBSYSTEM_$(UC_SUBSYSTEM) -DBCM_PLATFORM_$(UC_PLATFORM) -DBCM_OS_$(UC_OS) |
| 266 | EXTRA_DEFINES += -D$(UC_OS_KERNEL)_KERNEL_SPACE |
| 267 | ifeq ("$(ENABLE_EPON)", "y") |
| 268 | EXTRA_DEFINES += -DBCM_EPON |
| 269 | endif |
| 270 | ifeq ("$(ENABLE_GPON)", "y") |
| 271 | EXTRA_DEFINES += -DBCM_GPON |
| 272 | endif |
| 273 | ifeq ("$(ENABLE_XGPON)", "y") |
| 274 | EXTRA_DEFINES += -DBCM_XGPON |
| 275 | endif |
| 276 | |
| 277 | # Build unitests for simulation and from Jenkins jobs |
| 278 | UNITEST ?= n |
| 279 | |
| 280 | ifeq ("$(SIMULATION_BUILD)", "y") |
| 281 | EXTRA_DEFINES += -DSIMULATION_BUILD |
| 282 | UNITEST = y |
| 283 | endif |
| 284 | |
| 285 | ifeq ("$(JENKINS_BUILD)", "y") |
| 286 | UNITEST = y |
| 287 | endif |
| 288 | |
| 289 | EXTRA_INCLUDES += -I$(SRC_DIR) |
| 290 | |
| 291 | OPT_DISABLE_EMBEDDED ?= n |
| 292 | OPT_DISABLE_HOST ?=n |
| 293 | |
| 294 | ifeq ("OPT_DISABLE_$(UC_SUBSYSTEM)", "OPT_DISABLE_EMBEDDED") |
| 295 | OPT_DISABLE := $(OPT_DISABLE_EMBEDDED) |
| 296 | else |
| 297 | OPT_DISABLE := $(OPT_DISABLE_HOST) |
| 298 | endif |
| 299 | |
| 300 | ARCH_CFLAGS = $(ARCH_FLAGS) |
| 301 | ifeq ("$(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) |
| 306 | else |
| 307 | ARCH_CFLAGS += $(RELEASE_O_CFLAGS) |
| 308 | EXTRA_LFLAGS += $(RELEASE_O_LFLAGS) |
| 309 | EXTRA_ASFLAGS += $(RELEASE_O_ASFLAGS) |
| 310 | EXTRA_asFLAGS += $(RELEASE_O_asFLAGS) |
| 311 | endif |
| 312 | |
| 313 | # Treat lib as shared lib if BUILD_SHARED_LIBS is y |
| 314 | ifeq ("$(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 |
| 319 | endif |
| 320 | |
| 321 | # Calculate MOD_TARGET based on MOD_TYPE |
| 322 | ifeq ("$(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) |
| 328 | else 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) |
| 334 | else ifeq ("$(MOD_TYPE)", "app") |
| 335 | MOD_TARGET ?= $(OUT_DIR)/$(MOD_NAME) |
| 336 | else 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 |
| 347 | else ifeq ("$(MOD_TYPE)", "linux_lib") |
| 348 | MOD_TARGET ?= $(OUT_DIR_BASE)/$(MOD_NAME).linuxlib |
| 349 | else ifeq ("$(MOD_TYPE)", "_skip_") |
| 350 | MOD_TARGET = .dummy |
| 351 | else |
| 352 | $(error MOD_TYPE $(MOD_TYPE) is incorrect for module $(MOD_NAME). Must be lib or app) |
| 353 | endif |
| 354 | |
| 355 | ifeq ("$(MOD_TARGET)", "") |
| 356 | MOD_TARGET = $(MOD_NAME) |
| 357 | endif |
| 358 | |
| 359 | ifeq ("$(OS)", "posix") |
| 360 | EXTRA_DEFINES += -D_XOPEN_SOURCE=600 |
| 361 | LIBS = -lrt -lpthread -lm |
| 362 | endif |
| 363 | |
| 364 | # Make sure that paths in EXTRA_INCLUDES are absolute |
| 365 | ifneq ("$(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)))) |
| 368 | endif |
| 369 | ifneq ("$(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)))) |
| 372 | endif |
| 373 | ifneq ("$(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)))) |
| 376 | endif |
| 377 | ifeq ("$(USE_LINT)", "y") |
| 378 | USE_LINT := yes |
| 379 | endif |
| 380 | ifeq ("$(USE_LINT)", "yes") |
| 381 | EXTRA_DEFINES += -DUSE_LINT |
| 382 | endif |
| 383 | |
| 384 | EXTRA_DEFINES += $(USER_EXTRA_DEFINES) $(USER_EXTRA_$(UC_SUBSYSTEM)_DEFINES) |
| 385 | EXTRA_CFLAGS += $(USER_EXTRA_CFLAGS) $(USER_EXTRA_$(UC_SUBSYSTEM)_CFLAGS) |
| 386 | CFLAGS += $(ARCH_CFLAGS) $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES) |
| 387 | ASFLAGS += $(ARCH_FLAGS) $(EXTRA_ASFLAGS) $(EXTRA_ASINCS) $(EXTRA_ASDEFINES) |
| 388 | asFLAGS += $(ARCH_FLAGS) $(EXTRA_asFLAGS) $(EXTRA_asINCS) $(EXTRA_asDEFINES) |
| 389 | LFLAGS += $(ARCH_FLAGS) $(EXTRA_LFLAGS) |
| 390 | DEP_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES) |
| 391 | CLANG_FLAGS += $(EXTRA_CFLAGS) $(EXTRA_INCS) $(EXTRA_DEFINES) $(CLANG_OPTS) |