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 := $(shell echo $(sort $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES)) \
8 |$(sed) -r -e 's/ /\n/g;' \
9 |$(sed) -r -e 's/(.*),(.*)/\2,\1/;' \
11 |$(sed) -r -e 's/(.*),(.*)/\2,\1/;' \
14 # ----------------------------------------------------------
15 # This part deals with the samples help entries
18 @echo ' saveconfig - Save current config as a preconfigured target'
21 @echo ' list-samples - prints the list of all samples (for scripting)'
22 @echo ' show-<sample> - show a brief overview of <sample> (list with list-samples)'
23 @echo ' <sample> - preconfigure crosstool-NG with <sample> (list with list-samples)'
24 @echo ' build-all[.#] - Build *all* samples (list with list-samples) and install in'
25 @echo ' $${CT_PREFIX} (which you must set)'
28 @echo ' wiki-samples - Print a DokuWiki table of samples'
31 @echo ' CT_PREFIX=dir - install samples in dir (see action "build-all", above).'
33 # ----------------------------------------------------------
34 # This part deals with printing samples information
36 # Print the details of current configuration
39 @cp .config .config.sample
40 @$(CT_LIB_DIR)/scripts/showSamples.sh -v current
43 # Prints the details of a sample
44 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
45 $(patsubst %,show-%,$(CT_SAMPLES)): config_files
46 @KCONFIG_CONFIG=$$(pwd)/.config.sample \
47 $(CONF) --defconfig=$(call sample_dir,$(patsubst show-%,%,$(@)))/crosstool.config \
48 $(KCONFIG_TOP) >/dev/null
49 @$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
52 # Prints the details of all samples
54 show-all: $(patsubst %,show-%,$(CT_SAMPLES))
56 # print the list of all available samples
59 $(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
61 PHONY += list-samples-short
62 list-samples-short: FORCE
63 $(SILENT)for s in $(CT_SAMPLES); do \
69 $(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
71 # ----------------------------------------------------------
72 # This part deals with saving/restoring samples
80 saveconfig: .config samples
81 $(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
83 # The 'sample_dir' function prints the directory in which the sample is,
84 # searching first in local samples, then in global samples
86 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
89 # How we do recall one sample
90 PHONY += $(CT_SAMPLES)
91 $(CT_SAMPLES): config_files
92 @$(ECHO) " CONF $(KCONFIG_TOP)"
93 $(SILENT)$(CONF) --defconfig=$(call sample_dir,$@)/crosstool.config $(KCONFIG_TOP)
95 @echo '***********************************************************'
97 $(SILENT)( . $(call sample_dir,$@)/reported.by; \
98 echo "Initially reported by: $${reporter_name}"; \
99 echo "URL: $${reporter_url}"; \
100 if [ -n "$${reporter_comment}" ]; then \
103 printf "$${reporter_comment}\n"; \
106 echo '***********************************************************'; \
108 $(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
110 echo 'WARNING! This sample may enable experimental features.'; \
111 echo ' Please be sure to review the configuration prior'; \
112 echo ' to building and using your toolchain!'; \
113 echo 'Now, you have been warned!'; \
115 echo '***********************************************************'; \
118 @echo 'Now configured for "$@"'
120 # ----------------------------------------------------------
121 # Some helper functions
123 # Create the rule to build a sample
127 @$(ECHO) ' CONF $(1)'
128 $(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
129 $(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
130 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
131 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
132 $(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
133 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
134 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
135 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
136 @$(ECHO) ' BUILD $(1)'
137 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
140 # ----------------------------------------------------------
141 # Build samples for use (not regtest!)
143 # Check that PREFIX is set if building samples
144 ifneq ($(strip $(MAKECMDGOALS)),)
145 ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
147 ifeq ($(strip $(CT_PREFIX)),)
148 $(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
151 endif # MAKECMDGOALS contains a build sample rule
152 endif # MAKECMDGOALS != ""
154 # Build a single sample
155 $(patsubst %,build-%,$(CT_SAMPLES)):
156 $(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
159 build-all: $(patsubst %,build-%,$(CT_SAMPLES))
161 # Build all samples, overiding the number of // jobs per sample
163 $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')