1 # Makefile to manage samples
3 # ----------------------------------------------------------
4 # Build the list of available samples
5 CT_TOP_SAMPLES := $(patsubst $(CT_TOP_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_TOP_DIR)/samples/*/crosstool.config))
6 CT_LIB_SAMPLES := $(filter-out $(CT_TOP_SAMPLES),$(patsubst $(CT_LIB_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_LIB_DIR)/samples/*/crosstool.config)))
7 CT_SAMPLES := $(sort $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES))
9 # ----------------------------------------------------------
10 # This part deals with the samples help entries
13 @echo ' saveconfig - Save current config as a preconfigured target'
16 @echo ' list-samples - prints the list of all samples (for scripting)'
17 @echo ' show-<sample> - show a brief overview of <sample> (list below)'
18 @echo ' <sample> - preconfigure crosstool-NG with <sample> (list below)'
19 @$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
22 @echo ' regtest[.#] - Regtest-build all samples'
23 @echo ' regtest-local[.#] - Regtest-build all local samples'
24 @echo ' regtest-global[.#] - Regtest-build all global samples'
27 @echo ' wiki-samples - Print a DokuWiki table of samples'
29 # ----------------------------------------------------------
30 # This part deals with printing samples information
32 # Prints the details of a sample
33 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
34 $(patsubst %,show-%,$(CT_SAMPLES)):
35 @$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
37 # print the list of all available samples
40 @echo $(CT_SAMPLES) |sed -r -e 's/ /\n/g;' |sort
43 $(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
45 # ----------------------------------------------------------
46 # This part deals with saving/restoring samples
50 $(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
52 # The 'sample_dir' function prints the directory in which the sample is,
53 # searching first in local samples, then in global samples
55 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
58 # How we do recall one sample
59 PHONY += $(CT_SAMPLES)
61 $(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
62 $(SILENT)$(MAKE) -rf $(CT_NG) oldconfig
64 @echo '***********************************************************'
66 $(SILENT)( . $(call sample_dir,$@)/reported.by; \
67 echo "Initially reported by: $${reporter_name:-Yann E. MORIN}"; \
68 echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}"; \
69 if [ -n "$${reporter_comment}" ]; then \
72 printf "$${reporter_comment}\n"; \
75 echo '***********************************************************'; \
77 $(SILENT)if grep -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
79 echo 'WARNING! This sample may enable experimental features.'; \
80 echo ' Please be sure to review the configuration prior'; \
81 echo ' to building and using your toolchain!'; \
82 echo 'Now, you have been warned!'; \
84 echo '***********************************************************'; \
87 @echo 'Now configured for "$@"'
89 # ----------------------------------------------------------
90 # And now for building all samples one after the other
92 PHONY += regtest regtest_local regtest_global
93 regtest: regtest-local regtest-global
95 regtest-local: $(patsubst %,regtest_%,$(CT_TOP_SAMPLES))
97 regtest-global: $(patsubst %,regtest_%,$(CT_LIB_SAMPLES))
99 regtest.% regtest-local.% regtest-global.%:
100 $(SILENT)$(CT_NG) $(shell echo "$(@)" |sed -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
102 # One regtest per sample
103 # We could use a simple rule like: 'regtest: $(CT_SAMPLES)', but that doesn't
104 # work because we want to save the samples as well.
105 # Also, we don't want to see anylog at all, save for the elapsed time, and we
106 # want to save the log file in a specific place
107 # Furthermore, force the location where the toolchain will be installed.
108 # Finaly, we can't use 'make sample-name' as we need to provide default values
109 # if the options set has changed, but oldconfig does not like when stdin is
110 # not a terminal (eg. it is a pipe).
111 $(patsubst %,regtest_%,$(CT_SAMPLES)):
112 $(SILENT)samp=$(patsubst regtest_%,%,$@) ; \
113 echo -e "\rBuilding sample \"$${samp}\"" && \
114 $(CT_NG) copy_config_$${samp} && \
115 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1 && \
116 sed -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$${CT_TOP_DIR}/targets/tst/$${CT_TARGET}":;' .config && \
117 sed -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config && \
118 sed -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config && \
119 sed -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config && \
120 sed -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config && \
121 sed -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config && \
122 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1 && \
124 echo -e "\rSuccessfully built sample \"$${samp}\"" && \
125 echo -e "\rMaking tarball for sample \"$${samp}\"" && \
126 $(CT_NG) tarball && \
127 echo -e "\rSuccessfully built tarball for sample \"$${samp}\"" ; \
128 echo -e "\rCleaning sample \"$${samp}\"" ; \
129 $(CT_NG) distclean ; \