blob: 38187660a8726bbe52efb4bc7550dceeb17d1f99 [file] [log] [blame]
# It is included from the central Makefile once for each subsystem (e.g., "core" and "agent")
# PARAMATER: SUBSYSTEM
UC_SUBSYSTEM = $(shell echo $(SUBSYSTEM) | tr a-z A-Z)
export BUILD_TARGET = $(SUBSYSTEM)
export BIN_RELEASE_FILE_PREFIX ?= release.bin.$(SUBSYSTEM).$(BUILD_VERSION_PREFIX)
export OUT_$(UC_SUBSYSTEM)_DIR ?= $(OUT_DIR)/$(SUBSYSTEM)
# Combine modules.$(SUBSYSTEM).bal, modules.$(SUBSYSTEM).sdn_pal and modules.$(SUBSYSTEM).omci into a single file in the subsystem directory
define combine_modules
mkdir -p $(OUT_$(UC_SUBSYSTEM)_DIR); \
rm -rf $1; \
touch $1; \
for mod_file in $2; do cat $$mod_file >> $1; done;
endef
# Create $(SUBSYSTEM)/modules.$(SUBSYSTEM).omci and $(SUBSYSTEM)/modules.$(SUBSYSTEM).sdn_pal if they doesn't exist, as empty files.
# This is relevant when compiling from source release package extraction.
$(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).omci: | phonytarget
touch $@
$(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).sdn_pal: | phonytarget
touch $@
phonytarget:
# ORDER IS IMPORTANT - OMCI should come before BAL
$(OUT_$(UC_SUBSYSTEM)_DIR)/modules.core: $(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).omci $(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).bal
$(call combine_modules,$(OUT_$(UC_SUBSYSTEM)_DIR)/modules.core,$^)
# ORDER IS IMPORTANT - SDN_PAL should come after BAL
$(OUT_$(UC_SUBSYSTEM)_DIR)/modules.agent: $(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).bal $(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).omci $(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).sdn_pal
$(call combine_modules,$(OUT_$(UC_SUBSYSTEM)_DIR)/modules.agent,$^)
$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD): $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) \
$(MAKE_DIR)/Makefile.config $(MAKE_DIR)/Makefile.rules $(MAKE_DIR)/Makefile.template $(MAKE_DIR)/Makefile.main
@if ! test -f $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD); then\
if ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_* 2>/dev/null >/dev/null; then\
olddeps=`ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_*` ; \
old_board=`echo $$olddeps | sed 's@$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_@@'` ; \
$(BOLD_PRINT) "Previous build was for different board $$old_board. cleaning up..";\
$(MAKE) -s BOARD=$$old_board V=0 clean_$(SUBSYSTEM); \
rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/build/output/*; \
fi;\
fi
@$(BOLD_PRINT) "Generating list of $(SUBSYSTEM) modules for $(BUILD_TARGET)"
@rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_*
@rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)
@rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)
@rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)
@mkdir -p $(OUT_$(UC_SUBSYSTEM)_DIR)
@touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)
@touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)
@touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)
@for mod_dir in `awk '{print $$1}' $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)`; do\
if test "$$mod_dir" = "" ; then continue; fi; \
mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
if test "$$mod_name" = "" ; then continue; fi; \
mod_name=$${mod_name}_$(SUBSYSTEM);\
mod_type=`grep -e '^[[:space:]]*MOD_TYPE[[:space:]]*=' $$mod_dir/Makefile | awk -F= '{sub(/\r/,""); print $$2}' | sed -e 's/^[ \t]*//'`; \
echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM); \
if test "`echo -n $$mod_type | sed -e 's/linux_lib lib/lib/' | sed -e 's/lib linux_lib/lib/'`" = "lib" ; then\
echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM); \
fi;\
if test "$$mod_type" = "app" ; then\
echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM); \
fi;\
done
@touch $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD)
$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD): $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD)
@$(BOLD_PRINT) "Building $(BOARD) board environment for $(BUILD_TARGET)"
$(MAKE) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
-f $(MAKE_DIR)/Makefile.template board_env
@$(BOLD_PRINT) "Generating $(SUBSYSTEM) dependencies for $(BUILD_TARGET)"
@for mod_dir in `awk '{print $$1}' $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)`; do\
if test "$$mod_dir" = "" ; then continue; fi; \
mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
if test "$$mod_name" = "" ; then continue; fi; \
if ! $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
-f $(MAKE_DIR)/Makefile.template moddep; then exit 1;\
fi;\
done
@touch $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD)
@echo "$(BOARD_DIR)" > $(OUT_$(UC_SUBSYSTEM)_DIR)/.board_dir
.PHONY:
# Make sure that none of module Makefiles changed.
# If there is a change - we need to regenerate dependencies
_deps_$(SUBSYSTEM)_: $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD) .PHONY
@cat $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
if test "$$mod_dir" = "" ; then continue; fi; \
if test $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD) -ot $$mod_dir/Makefile; then\
echo $$mod_dir/Makefile changed, must regenerate dependencies.;\
echo PLEASE RE-RUN make;\
rm -f $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD);\
exit -1;\
fi;\
done
build_$(SUBSYSTEM): _deps_$(SUBSYSTEM)_
@$(BOLD_PRINT) "Building $(SUBSYSTEM) image for $(BUILD_TARGET)"
@cat $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
if test "$$mod_dir" = "" ; then continue; fi; \
mod_targets=`echo $$mod_dir_targ | awk '{print $$2 $$3 $$4 $$5}'`;\
if ! $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) \
ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
-f $(MAKE_DIR)/Makefile.template $$mod_targets; then exit 1;\
fi;\
done
@$(BOLD_PRINT) "Finished building $(SUBSYSTEM) image for $(BUILD_TARGET)"
clean_$(SUBSYSTEM): BOARD=$(shell ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_* 2>/dev/null | sed 's@$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_@@')
clean_$(SUBSYSTEM): $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)
@$(BOLD_PRINT) "Clean $(PLATFORM) $(SUBSYSTEM) BOARD=$(BOARD)"
@for mod_dir in `awk '{print $$1}' $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)`; do\
if test "$$mod_dir" = "" ; then continue; fi; \
$(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
-f $(MAKE_DIR)/Makefile.template clean_module;\
done
$(SILENT_BUILD)rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)
$(SILENT_BUILD)find $(SUBSYSTEM) -name '*~' -print0 2>/dev/null | xargs -0 rm -rf
$(SILENT_BUILD)find $(SUBSYSTEM) -name '*.ko' -print0 2>/dev/null | xargs -0 rm -rf
$(SILENT_BUILD)find $(SUBSYSTEM) -name '.*.cmd' -print0 2>/dev/null | xargs -0 rm -rf
$(SILENT_BUILD)find $(SUBSYSTEM) -name '*.o' -print0 2>/dev/null | xargs -0 rm -rf
$(SILENT_BUILD)find $(SUBSYSTEM) -name '*.mod.c' -print0 2>/dev/null | xargs -0 rm -rf
$(SILENT_BUILD)find $(SUBSYSTEM) -name modules.order -print0 2>/dev/null | xargs -0 rm -rf
$(SILENT_BUILD)find $(SUBSYSTEM) -name Module.symvers -print0 2>/dev/null| xargs -0 rm -rf
$(SILENT_BUILD)find $(SUBSYSTEM) -name .tmp_versions -print0 2>/dev/null | xargs -0 rm -rf
help_$(SUBSYSTEM):
@echo "$$PLATFORM $(SUBSYSTEM) modules:"
@cat $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
if test "$$mod_dir" = "" ; then continue; fi; \
mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
if test "$$mod_name" = "" ; then continue; fi; \
echo " " $${mod_name}_$(SUBSYSTEM);\
done
# Targets for building individual $(SUBSYSTEM) module
%_$(SUBSYSTEM):: _deps_$(SUBSYSTEM)_
@while read -r mod_dir_targ; do\
mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
if test "$$mod_dir" = "" ; then continue; fi; \
mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
if test "$$mod_name" = "" ; then continue; fi; \
mod_name=$${mod_name}_$(SUBSYSTEM);\
mod_targets=`echo $$mod_dir_targ | awk '{print $$2 $$3 $$4 $$5}'`;\
if test "$$mod_name" = "$@" ; then\
target_found=y;\
$(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) \
ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
-f $(MAKE_DIR)/Makefile.template $$mod_targets || exit 1;\
fi;\
done < $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM);\
if test "$$target_found" != "y" ; then\
echo No rule to make target $@;\
exit 1;\
fi
docs_$(SUBSYSTEM): _deps_$(SUBSYSTEM)_
mkdir -p $(OUT_DOCS_DIR)
$(SILENT_BUILD)$(MAKE) -C doxygen OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR)
bin_release_$(SUBSYSTEM): build_$(SUBSYSTEM)
$(SILENT_BUILD)$(MAKE_DIR)/bin_release.sh