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)
57 $(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
59 # ----------------------------------------------------------
60 # This part deals with saving/restoring samples
68 saveconfig: .config samples
69 $(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
71 # The 'sample_dir' function prints the directory in which the sample is,
72 # searching first in local samples, then in global samples
74 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
77 # How we do recall one sample
78 PHONY += $(CT_SAMPLES)
80 $(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
81 $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
83 @echo '***********************************************************'
85 $(SILENT)( . $(call sample_dir,$@)/reported.by; \
86 echo "Initially reported by: $${reporter_name:-Yann E. MORIN}"; \
87 echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}"; \
88 if [ -n "$${reporter_comment}" ]; then \
91 printf "$${reporter_comment}\n"; \
94 echo '***********************************************************'; \
96 $(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
98 echo 'WARNING! This sample may enable experimental features.'; \
99 echo ' Please be sure to review the configuration prior'; \
100 echo ' to building and using your toolchain!'; \
101 echo 'Now, you have been warned!'; \
103 echo '***********************************************************'; \
106 @echo 'Now configured for "$@"'
108 # ----------------------------------------------------------
109 # Some helper functions
111 # Create the rule to build a sample
115 @$(ECHO) ' CONF $(1)'
116 $(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
117 $(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
118 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
119 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
120 $(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
121 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
122 $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
123 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
124 @$(ECHO) ' BUILD $(1)'
125 $(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
128 # ----------------------------------------------------------
129 # Build samples for use (not regtest!)
131 # Check that PREFIX is set if building samples
132 ifneq ($(strip $(MAKECMDGOALS)),)
133 ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
135 ifeq ($(strip $(CT_PREFIX)),)
136 $(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
139 endif # MAKECMDGOALS contains a build sample rule
140 endif # MAKECMDGOALS != ""
142 # Build a single sample
143 $(patsubst %,build-%,$(CT_SAMPLES)):
144 $(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
147 build-all: $(patsubst %,build-%,$(CT_SAMPLES))
149 # Build all samples, overiding the number of // jobs per sample
151 $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')