blob: 38187660a8726bbe52efb4bc7550dceeb17d1f99 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001# It is included from the central Makefile once for each subsystem (e.g., "core" and "agent")
2# PARAMATER: SUBSYSTEM
3
4UC_SUBSYSTEM = $(shell echo $(SUBSYSTEM) | tr a-z A-Z)
5export BUILD_TARGET = $(SUBSYSTEM)
6export BIN_RELEASE_FILE_PREFIX ?= release.bin.$(SUBSYSTEM).$(BUILD_VERSION_PREFIX)
7export OUT_$(UC_SUBSYSTEM)_DIR ?= $(OUT_DIR)/$(SUBSYSTEM)
8
9# Combine modules.$(SUBSYSTEM).bal, modules.$(SUBSYSTEM).sdn_pal and modules.$(SUBSYSTEM).omci into a single file in the subsystem directory
10define combine_modules
11 mkdir -p $(OUT_$(UC_SUBSYSTEM)_DIR); \
12 rm -rf $1; \
13 touch $1; \
14 for mod_file in $2; do cat $$mod_file >> $1; done;
15endef
16
17# Create $(SUBSYSTEM)/modules.$(SUBSYSTEM).omci and $(SUBSYSTEM)/modules.$(SUBSYSTEM).sdn_pal if they doesn't exist, as empty files.
18# This is relevant when compiling from source release package extraction.
19$(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).omci: | phonytarget
20 touch $@
21$(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).sdn_pal: | phonytarget
22 touch $@
23
24phonytarget:
25
26# ORDER IS IMPORTANT - OMCI should come before BAL
27$(OUT_$(UC_SUBSYSTEM)_DIR)/modules.core: $(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).omci $(MAKE_DIR)/$(SUBSYSTEM)/modules.$(SUBSYSTEM).bal
28 $(call combine_modules,$(OUT_$(UC_SUBSYSTEM)_DIR)/modules.core,$^)
29
30# ORDER IS IMPORTANT - SDN_PAL should come after BAL
31$(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
32 $(call combine_modules,$(OUT_$(UC_SUBSYSTEM)_DIR)/modules.agent,$^)
33
34$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD): $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) \
35 $(MAKE_DIR)/Makefile.config $(MAKE_DIR)/Makefile.rules $(MAKE_DIR)/Makefile.template $(MAKE_DIR)/Makefile.main
36 @if ! test -f $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD); then\
37 if ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_* 2>/dev/null >/dev/null; then\
38 olddeps=`ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_*` ; \
39 old_board=`echo $$olddeps | sed 's@$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_@@'` ; \
40 $(BOLD_PRINT) "Previous build was for different board $$old_board. cleaning up..";\
41 $(MAKE) -s BOARD=$$old_board V=0 clean_$(SUBSYSTEM); \
42 rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/build/output/*; \
43 fi;\
44 fi
45 @$(BOLD_PRINT) "Generating list of $(SUBSYSTEM) modules for $(BUILD_TARGET)"
46 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_*
47 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)
48 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)
49 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)
50 @mkdir -p $(OUT_$(UC_SUBSYSTEM)_DIR)
51 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)
52 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)
53 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)
54 @for mod_dir in `awk '{print $$1}' $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)`; do\
55 if test "$$mod_dir" = "" ; then continue; fi; \
56 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
57 if test "$$mod_name" = "" ; then continue; fi; \
58 mod_name=$${mod_name}_$(SUBSYSTEM);\
59 mod_type=`grep -e '^[[:space:]]*MOD_TYPE[[:space:]]*=' $$mod_dir/Makefile | awk -F= '{sub(/\r/,""); print $$2}' | sed -e 's/^[ \t]*//'`; \
60 echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM); \
61 if test "`echo -n $$mod_type | sed -e 's/linux_lib lib/lib/' | sed -e 's/lib linux_lib/lib/'`" = "lib" ; then\
62 echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM); \
63 fi;\
64 if test "$$mod_type" = "app" ; then\
65 echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM); \
66 fi;\
67 done
68 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD)
69
70$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD): $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD)
71 @$(BOLD_PRINT) "Building $(BOARD) board environment for $(BUILD_TARGET)"
72 $(MAKE) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
73 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
74 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
75 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
76 -f $(MAKE_DIR)/Makefile.template board_env
77 @$(BOLD_PRINT) "Generating $(SUBSYSTEM) dependencies for $(BUILD_TARGET)"
78 @for mod_dir in `awk '{print $$1}' $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)`; do\
79 if test "$$mod_dir" = "" ; then continue; fi; \
80 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
81 if test "$$mod_name" = "" ; then continue; fi; \
82 if ! $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
83 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
84 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
85 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
86 -f $(MAKE_DIR)/Makefile.template moddep; then exit 1;\
87 fi;\
88 done
89 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD)
90 @echo "$(BOARD_DIR)" > $(OUT_$(UC_SUBSYSTEM)_DIR)/.board_dir
91
92.PHONY:
93
94# Make sure that none of module Makefiles changed.
95# If there is a change - we need to regenerate dependencies
96_deps_$(SUBSYSTEM)_: $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD) .PHONY
97 @cat $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
98 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
99 if test "$$mod_dir" = "" ; then continue; fi; \
100 if test $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD) -ot $$mod_dir/Makefile; then\
101 echo $$mod_dir/Makefile changed, must regenerate dependencies.;\
102 echo PLEASE RE-RUN make;\
103 rm -f $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD);\
104 exit -1;\
105 fi;\
106 done
107
108build_$(SUBSYSTEM): _deps_$(SUBSYSTEM)_
109 @$(BOLD_PRINT) "Building $(SUBSYSTEM) image for $(BUILD_TARGET)"
110 @cat $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
111 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
112 if test "$$mod_dir" = "" ; then continue; fi; \
113 mod_targets=`echo $$mod_dir_targ | awk '{print $$2 $$3 $$4 $$5}'`;\
114 if ! $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) \
115 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
116 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
117 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
118 -f $(MAKE_DIR)/Makefile.template $$mod_targets; then exit 1;\
119 fi;\
120 done
121 @$(BOLD_PRINT) "Finished building $(SUBSYSTEM) image for $(BUILD_TARGET)"
122
123clean_$(SUBSYSTEM): BOARD=$(shell ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_* 2>/dev/null | sed 's@$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_@@')
124
125clean_$(SUBSYSTEM): $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)
126 @$(BOLD_PRINT) "Clean $(PLATFORM) $(SUBSYSTEM) BOARD=$(BOARD)"
127 @for mod_dir in `awk '{print $$1}' $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM)`; do\
128 if test "$$mod_dir" = "" ; then continue; fi; \
129 $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
130 -f $(MAKE_DIR)/Makefile.template clean_module;\
131 done
132 $(SILENT_BUILD)rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)
133 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*~' -print0 2>/dev/null | xargs -0 rm -rf
134 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*.ko' -print0 2>/dev/null | xargs -0 rm -rf
135 $(SILENT_BUILD)find $(SUBSYSTEM) -name '.*.cmd' -print0 2>/dev/null | xargs -0 rm -rf
136 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*.o' -print0 2>/dev/null | xargs -0 rm -rf
137 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*.mod.c' -print0 2>/dev/null | xargs -0 rm -rf
138 $(SILENT_BUILD)find $(SUBSYSTEM) -name modules.order -print0 2>/dev/null | xargs -0 rm -rf
139 $(SILENT_BUILD)find $(SUBSYSTEM) -name Module.symvers -print0 2>/dev/null| xargs -0 rm -rf
140 $(SILENT_BUILD)find $(SUBSYSTEM) -name .tmp_versions -print0 2>/dev/null | xargs -0 rm -rf
141
142help_$(SUBSYSTEM):
143 @echo "$$PLATFORM $(SUBSYSTEM) modules:"
144 @cat $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
145 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
146 if test "$$mod_dir" = "" ; then continue; fi; \
147 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
148 if test "$$mod_name" = "" ; then continue; fi; \
149 echo " " $${mod_name}_$(SUBSYSTEM);\
150 done
151
152# Targets for building individual $(SUBSYSTEM) module
153%_$(SUBSYSTEM):: _deps_$(SUBSYSTEM)_
154 @while read -r mod_dir_targ; do\
155 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
156 if test "$$mod_dir" = "" ; then continue; fi; \
157 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
158 if test "$$mod_name" = "" ; then continue; fi; \
159 mod_name=$${mod_name}_$(SUBSYSTEM);\
160 mod_targets=`echo $$mod_dir_targ | awk '{print $$2 $$3 $$4 $$5}'`;\
161 if test "$$mod_name" = "$@" ; then\
162 target_found=y;\
163 $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) \
164 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
165 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
166 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
167 -f $(MAKE_DIR)/Makefile.template $$mod_targets || exit 1;\
168 fi;\
169 done < $(OUT_$(UC_SUBSYSTEM)_DIR)/modules.$(SUBSYSTEM);\
170 if test "$$target_found" != "y" ; then\
171 echo No rule to make target $@;\
172 exit 1;\
173 fi
174
175docs_$(SUBSYSTEM): _deps_$(SUBSYSTEM)_
176 mkdir -p $(OUT_DOCS_DIR)
177 $(SILENT_BUILD)$(MAKE) -C doxygen OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR)
178
179bin_release_$(SUBSYSTEM): build_$(SUBSYSTEM)
180 $(SILENT_BUILD)$(MAKE_DIR)/bin_release.sh