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 @export current_tuple=$(shell $(MAKE) -rf "$(CT_NG)" show-tuple ); \
40 $(CT_LIB_DIR)/scripts/showSamples.sh -v current
42 # Prints the details of a sample
43 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
44 $(patsubst %,show-%,$(CT_SAMPLES)):
45 @$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
47 # Prints the details of all samples
49 show-all: $(patsubst %,show-%,$(CT_SAMPLES))
51 # print the list of all available samples
54 $(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
56 PHONY += list-samples-short
57 list-samples-short: FORCE
58 $(SILENT)for s in $(CT_SAMPLES); do \
64 $(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
66 # ----------------------------------------------------------
67 # This part deals with saving/restoring samples
75 saveconfig: .config samples
76 $(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
78 # The 'sample_dir' function prints the directory in which the sample is,
79 # searching first in local samples, then in global samples
81 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
84 # How we do recall one sample
85 PHONY += $(CT_SAMPLES)
87 $(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
88 $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
90 @echo '***********************************************************'
92 $(SILENT)( . $(call sample_dir,$@)/reported.by; \
93 echo "Initially reported by: $${reporter_name}"; \
94 echo "URL: $${reporter_url}"; \
95 if [ -n "$${reporter_comment}" ]; then \
98 printf "$${reporter_comment}\n"; \
101 echo '***********************************************************'; \
103 $(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
105 echo 'WARNING! This sample may enable experimental features.'; \
106 echo ' Please be sure to review the configuration prior'; \
107 echo ' to building and using your toolchain!'; \
108 echo 'Now, you have been warned!'; \
110 echo '***********************************************************'; \
113 @echo 'Now configured for "$@"'
115 # ----------------------------------------------------------
116 # Some helper functions
118 # Create the rule to build a sample
122 @$(ECHO) ' CONF $(1)'
123 $(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
124 $(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
125 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
126 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
127 $(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
128 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
129 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
130 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
131 @$(ECHO) ' BUILD $(1)'
132 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
135 # ----------------------------------------------------------
136 # Build samples for use (not regtest!)
138 # Check that PREFIX is set if building samples
139 ifneq ($(strip $(MAKECMDGOALS)),)
140 ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
142 ifeq ($(strip $(CT_PREFIX)),)
143 $(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
146 endif # MAKECMDGOALS contains a build sample rule
147 endif # MAKECMDGOALS != ""
149 # Build a single sample
150 $(patsubst %,build-%,$(CT_SAMPLES)):
151 $(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
154 build-all: $(patsubst %,build-%,$(CT_SAMPLES))
156 # Build all samples, overiding the number of // jobs per sample
158 $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')