blob: 2ddef1eb9ea687ac86b598ba8c722b3ce2865ac8 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001# Main Makefile body
2# It is included in the central Makefile twice - for host and embedded subsystems
3# PARAMATER: SUBSYSTEM
4
5UC_SUBSYSTEM = $(shell echo $(SUBSYSTEM) | tr a-z A-Z)
6
7$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD): $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM) \
8 $(MAKE_DIR)/Makefile.config $(MAKE_DIR)/Makefile.rules $(MAKE_DIR)/Makefile.template $(MAKE_DIR)/Makefile.main
9 @if ! test -f $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD); then\
10 if ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_* 2>/dev/null >/dev/null; then\
11 olddeps=`ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_*` ; \
12 old_board=`echo $$olddeps | sed 's@$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_@@'` ; \
13 $(BOLD_PRINT) "Previous build was for different board $$old_board. cleaning up..";\
14 $(MAKE) -s BOARD=$$old_board V=0 clean_$(SUBSYSTEM); \
15 fi;\
16 fi
17 @$(BOLD_PRINT) "Generating list of $(SUBSYSTEM) modules for $(PLATFORM)"
18 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_*
19 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)
20 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)
21 @rm -fr $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)
22 @mkdir -p $(OUT_$(UC_SUBSYSTEM)_DIR)
23 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)
24 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)
25 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)
26 @for mod_dir in `awk '{print $$1}' $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM)`; do\
27 if test "$$mod_dir" = "" ; then continue; fi; \
28 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
29 if test "$$mod_name" = "" ; then continue; fi; \
30 mod_name=$${mod_name}_$(SUBSYSTEM);\
31 mod_type=`grep -e '^[[:space:]]*MOD_TYPE[[:space:]]*=' $$mod_dir/Makefile | awk -F= '{sub(/\r/,""); print $$2}' | sed -e 's/^[ \t]*//'`; \
32 echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM); \
33 if test "`echo -n $$mod_type | sed -e 's/linux_lib lib/lib/' | sed -e 's/lib linux_lib/lib/'`" = "lib" ; then\
34 echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM); \
35 fi;\
36 if test "$$mod_type" = "app" ; then\
37 echo -n "$$mod_name " >> $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM); \
38 fi;\
39 done
40 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD)
41
42$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD): $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD)
43 @$(BOLD_PRINT) "Building $(BOARD) board environment for $(PLATFORM)"
44 $(MAKE) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
45 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
46 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
47 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
48 -f $(MAKE_DIR)/Makefile.template board_env
49 @$(BOLD_PRINT) "Generating $(SUBSYSTEM) dependencies for $(PLATFORM)"
50 @for mod_dir in `awk '{print $$1}' $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM)`; do\
51 if test "$$mod_dir" = "" ; then continue; fi; \
52 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
53 if test "$$mod_name" = "" ; then continue; fi; \
54 if ! $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
55 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
56 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
57 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
58 -f $(MAKE_DIR)/Makefile.template moddep; then exit 1;\
59 fi;\
60 done
61 @touch $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD)
62
63.PHONY:
64
65# Make sure that none of module Makefiles changed.
66# If there is a change - we need to regenerate dependencies
67_deps_$(SUBSYSTEM)_: $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_$(BOARD) .PHONY
68 @cat $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
69 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
70 if test "$$mod_dir" = "" ; then continue; fi; \
71 if test $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD) -ot $$mod_dir/Makefile; then\
72 echo $$mod_dir/Makefile changed, must regenerate dependencies.;\
73 echo PLEASE RE-RUN make;\
74 rm -f $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_$(BOARD);\
75 exit -1;\
76 fi;\
77 done
78
79build_$(SUBSYSTEM): _deps_$(SUBSYSTEM)_
80 @$(BOLD_PRINT) "Building $(SUBSYSTEM) image for $(PLATFORM)"
81 @cat $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
82 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
83 if test "$$mod_dir" = "" ; then continue; fi; \
84 mod_targets=`echo $$mod_dir_targ | awk '{print $$2 $$3 $$4 $$5}'`;\
85 if ! $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) \
86 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
87 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
88 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
89 -f $(MAKE_DIR)/Makefile.template $$mod_targets; then exit 1;\
90 fi;\
91 done
92 @$(BOLD_PRINT) "Finished building $(SUBSYSTEM) image for $(PLATFORM)"
93
94clean_$(SUBSYSTEM): BOARD=$(shell ls $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_* 2>/dev/null | sed 's@$(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)_list_@@')
95
96clean_$(SUBSYSTEM):
97 @$(BOLD_PRINT) "Clean $(PLATFORM) $(SUBSYSTEM) BOARD=$(BOARD)"
98 @for mod_dir in `awk '{print $$1}' $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM)`; do\
99 if test "$$mod_dir" = "" ; then continue; fi; \
100 if ! $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) SKIP_DEPS=yes \
101 -f $(MAKE_DIR)/Makefile.template clean_module; then exit 1; fi;\
102 done
103 $(SILENT_BUILD)rm -f $(OUT_$(UC_SUBSYSTEM)_DIR)/Makefile.config.*
104 $(SILENT_BUILD)rm -f $(OUT_$(UC_SUBSYSTEM)_DIR)/.deps_$(SUBSYSTEM)*
105 $(SILENT_BUILD)rm -f $(OUT_$(UC_SUBSYSTEM)_DIR)/all_*modules.$(SUBSYSTEM)
106 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*~' -print0 2>/dev/null | xargs -0 rm -rf
107 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*.ko' -print0 2>/dev/null | xargs -0 rm -rf
108 $(SILENT_BUILD)find $(SUBSYSTEM) -name '.*.cmd' -print0 2>/dev/null | xargs -0 rm -rf
109 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*.o' -print0 2>/dev/null | xargs -0 rm -rf
110 $(SILENT_BUILD)find $(SUBSYSTEM) -name '*.mod.c' -print0 2>/dev/null | xargs -0 rm -rf
111 $(SILENT_BUILD)find $(SUBSYSTEM) -name modules.order -print0 2>/dev/null | xargs -0 rm -rf
112 $(SILENT_BUILD)find $(SUBSYSTEM) -name Module.symvers -print0 2>/dev/null | xargs -0 rm -rf
113 $(SILENT_BUILD)find $(SUBSYSTEM) -name .tmp_versions -print0 2>/dev/null | xargs -0 rm -rf
114
115help_$(SUBSYSTEM):
116 @echo "$$PLATFORM $(SUBSYSTEM) modules:"
117 @cat $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM) | while read -r mod_dir_targ; do\
118 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
119 if test "$$mod_dir" = "" ; then continue; fi; \
120 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
121 if test "$$mod_name" = "" ; then continue; fi; \
122 echo " " $${mod_name}_$(SUBSYSTEM);\
123 done
124
125# Targets for building individual $(SUBSYSTEM) module
126%_$(SUBSYSTEM):: _deps_$(SUBSYSTEM)_
127 @while read -r mod_dir_targ; do\
128 mod_dir=`echo $$mod_dir_targ | awk '{print $$1}'`;\
129 if test "$$mod_dir" = "" ; then continue; fi; \
130 mod_name=`$(MAKE) -s V=0 SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir SKIP_DEPS=yes -f $(MAKE_DIR)/Makefile.template module_name`;\
131 if test "$$mod_name" = "" ; then continue; fi; \
132 mod_name=$${mod_name}_$(SUBSYSTEM);\
133 mod_targets=`echo $$mod_dir_targ | awk '{print $$2 $$3 $$4 $$5}'`;\
134 if test "$$mod_name" = "$@" ; then\
135 target_found=y;\
136 $(MAKE) $(SILENT) SUBSYSTEM=$(SUBSYSTEM) MOD_DIR=$$mod_dir OUT_DIR_BASE=$(OUT_$(UC_SUBSYSTEM)_DIR) \
137 ALL_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_modules.$(SUBSYSTEM)`" \
138 ALL_LIB_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_lib_modules.$(SUBSYSTEM)`" \
139 ALL_APP_MODULES="`cat $(OUT_$(UC_SUBSYSTEM)_DIR)/all_app_modules.$(SUBSYSTEM)`" \
140 -f $(MAKE_DIR)/Makefile.template $$mod_targets || exit 1;\
141 fi;\
142 done < $(MAKE_DEVICE_DIR)/modules.$(SUBSYSTEM);\
143 if test "$$target_found" != "y" ; then\
144 echo No rule to make target $@;\
145 exit 1;\
146 fi
147
148docs_$(SUBSYSTEM): _deps_$(SUBSYSTEM)_
149 mkdir -p $(OUT_DOCS_DIR)
150 sed -e 's@%OUT_DOCS_DIR@$(OUT_DOCS_DIR)@g' -e 's@%MODEL_DIR@$(OUT_$(UC_SUBSYSTEM)_DIR)/common/model/$(PLATFORM)@g' \
151 -e 's@%API_DIR@$(TOP_DIR)/$(SUBSYSTEM)/api/$(PLATFORM)@g' doc_config/Doxyfile > $(OUT_DOCS_DIR)/Doxyfile
152 doxygen $(OUT_DOCS_DIR)/Doxyfile
153