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 below)'
23 @echo ' <sample> - preconfigure crosstool-NG with <sample> (list below)'
24 @echo ' build-all[.#] - Build *all* samples (list below) and install in'
25 @echo ' $${CT_PREFIX} (which you must set)'
26 @echo ' Available samples:'
27 @$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
30 @echo ' wiki-samples - Print a DokuWiki table of samples'
33 @echo ' CT_PREFIX - directory in which to auto-install samples'
34 @echo ' (see action "build-all", above).'
36 # ----------------------------------------------------------
37 # This part deals with printing samples information
39 # Print the details of current configuration
42 @export current_tuple=$(shell $(MAKE) -rf "$(CT_NG)" show-tuple ); \
43 $(CT_LIB_DIR)/scripts/showSamples.sh -v current
45 # Prints the details of a sample
46 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
47 $(patsubst %,show-%,$(CT_SAMPLES)):
48 @$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
50 # Prints the details of all samples
52 show-all: $(patsubst %,show-%,$(CT_SAMPLES))
54 # print the list of all available samples
57 @echo $(CT_SAMPLES) |$(sed) -r -e 's/ /\n/g;' |sed -r -e 's/(.*),(.*)/\2 \(host: \1\)/;'
60 $(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
62 # ----------------------------------------------------------
63 # This part deals with saving/restoring samples
71 saveconfig: .config samples
72 $(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
74 # The 'sample_dir' function prints the directory in which the sample is,
75 # searching first in local samples, then in global samples
77 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
80 # How we do recall one sample
81 PHONY += $(CT_SAMPLES)
83 $(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
84 $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
86 @echo '***********************************************************'
88 $(SILENT)( . $(call sample_dir,$@)/reported.by; \
89 echo "Initially reported by: $${reporter_name:-Yann E. MORIN}"; \
90 echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}"; \
91 if [ -n "$${reporter_comment}" ]; then \
94 printf "$${reporter_comment}\n"; \
97 echo '***********************************************************'; \
99 $(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
101 echo 'WARNING! This sample may enable experimental features.'; \
102 echo ' Please be sure to review the configuration prior'; \
103 echo ' to building and using your toolchain!'; \
104 echo 'Now, you have been warned!'; \
106 echo '***********************************************************'; \
109 @echo 'Now configured for "$@"'
111 # ----------------------------------------------------------
112 # Some helper functions
114 # Create the rule to build a sample
118 @$(ECHO) ' CONF $(1)'
119 $(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
120 $(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
121 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
122 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
123 $(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
124 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
125 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
126 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
127 @$(ECHO) ' BUILD $(1)'
128 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
131 # ----------------------------------------------------------
132 # Build samples for use (not regtest!)
134 # Check that PREFIX is set if building samples
135 ifneq ($(strip $(MAKECMDGOALS)),)
136 ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
138 ifeq ($(strip $(CT_PREFIX)),)
139 $(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
142 endif # MAKECMDGOALS contains a build sample rule
143 endif # MAKECMDGOALS != ""
145 # Build a single sample
146 $(patsubst %,build-%,$(CT_SAMPLES)):
147 $(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
150 build-all: $(patsubst %,build-%,$(CT_SAMPLES))
152 # Build all samples, overiding the number of // jobs per sample
154 $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')