1.1 --- a/samples/samples.mk Mon Oct 27 18:42:26 2008 +0000
1.2 +++ b/samples/samples.mk Sun Nov 16 21:55:46 2008 +0000
1.3 @@ -16,16 +16,18 @@
1.4 @echo ' list-samples - prints the list of all samples (for scripting)'
1.5 @echo ' show-<sample> - show a brief overview of <sample> (list below)'
1.6 @echo ' <sample> - preconfigure crosstool-NG with <sample> (list below)'
1.7 + @echo ' build-all[.#] - Build *all* samples (list below) and install in'
1.8 + @echo ' $${CT_PREFIX} (which you must set)'
1.9 + @echo ' Available samples:'
1.10 @$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
1.11
1.12 -help-build::
1.13 - @echo ' regtest[.#] - Regtest-build all samples'
1.14 - @echo ' regtest-local[.#] - Regtest-build all local samples'
1.15 - @echo ' regtest-global[.#] - Regtest-build all global samples'
1.16 -
1.17 help-distrib::
1.18 @echo ' wiki-samples - Print a DokuWiki table of samples'
1.19
1.20 +help-env::
1.21 + @echo ' CT_PREFIX - directory in which to auto-install samples'
1.22 + @echo ' (see action "build-all", above).'
1.23 +
1.24 # ----------------------------------------------------------
1.25 # This part deals with printing samples information
1.26
1.27 @@ -59,7 +61,7 @@
1.28 PHONY += $(CT_SAMPLES)
1.29 $(CT_SAMPLES):
1.30 $(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
1.31 - $(SILENT)$(MAKE) -rf $(CT_NG) oldconfig
1.32 + $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
1.33 @echo
1.34 @echo '***********************************************************'
1.35 @echo
1.36 @@ -87,44 +89,48 @@
1.37 @echo 'Now configured for "$@"'
1.38
1.39 # ----------------------------------------------------------
1.40 -# And now for building all samples one after the other
1.41 +# Some helper functions
1.42
1.43 -PHONY += regtest regtest_local regtest_global
1.44 -regtest: regtest-local regtest-global
1.45 +# Create the rule to build a sample
1.46 +# $1: sample tuple
1.47 +# $2: prefix
1.48 +define build_sample
1.49 + @$(ECHO) ' CP .config'
1.50 + $(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
1.51 + @$(ECHO) ' SED .config'
1.52 + $(SILENT)sed -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
1.53 + $(SILENT)sed -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
1.54 + $(SILENT)sed -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
1.55 + $(SILENT)sed -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
1.56 + $(SILENT)sed -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
1.57 + $(SILENT)sed -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
1.58 + $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
1.59 + @$(ECHO) ' BUILD $(1)'
1.60 + $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) build
1.61 +endef
1.62
1.63 -regtest-local: $(patsubst %,regtest_%,$(CT_TOP_SAMPLES))
1.64 +# ----------------------------------------------------------
1.65 +# Build samples for use (not regtest!)
1.66
1.67 -regtest-global: $(patsubst %,regtest_%,$(CT_LIB_SAMPLES))
1.68 +# Check that PREFIX is set if building samples
1.69 +ifneq ($(strip $(MAKECMDGOALS)),)
1.70 +ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
1.71
1.72 -regtest.% regtest-local.% regtest-global.%:
1.73 - $(SILENT)$(CT_NG) $(shell echo "$(@)" |sed -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
1.74 +ifeq ($(strip $(CT_PREFIX)),)
1.75 +$(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
1.76 +endif
1.77
1.78 -# One regtest per sample
1.79 -# We could use a simple rule like: 'regtest: $(CT_SAMPLES)', but that doesn't
1.80 -# work because we want to save the samples as well.
1.81 -# Also, we don't want to see anylog at all, save for the elapsed time, and we
1.82 -# want to save the log file in a specific place
1.83 -# Furthermore, force the location where the toolchain will be installed.
1.84 -# Finaly, we can't use 'make sample-name' as we need to provide default values
1.85 -# if the options set has changed, but oldconfig does not like when stdin is
1.86 -# not a terminal (eg. it is a pipe).
1.87 -$(patsubst %,regtest_%,$(CT_SAMPLES)):
1.88 - $(SILENT)samp=$(patsubst regtest_%,%,$@) ; \
1.89 - echo -e "\rBuilding sample \"$${samp}\"" && \
1.90 - $(CT_NG) copy_config_$${samp} && \
1.91 - yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1 && \
1.92 - sed -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$${CT_TOP_DIR}/targets/tst/$${CT_TARGET}":;' .config && \
1.93 - sed -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config && \
1.94 - sed -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config && \
1.95 - sed -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config && \
1.96 - sed -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config && \
1.97 - sed -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config && \
1.98 - yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1 && \
1.99 - $(CT_NG) build && \
1.100 - echo -e "\rSuccessfully built sample \"$${samp}\"" && \
1.101 - echo -e "\rMaking tarball for sample \"$${samp}\"" && \
1.102 - $(CT_NG) tarball && \
1.103 - echo -e "\rSuccessfully built tarball for sample \"$${samp}\"" ; \
1.104 - echo -e "\rCleaning sample \"$${samp}\"" ; \
1.105 - $(CT_NG) distclean ; \
1.106 - echo -e "\r"
1.107 +endif # MAKECMDGOALS contains a build sample rule
1.108 +endif # MAKECMDGOALS != ""
1.109 +
1.110 +# Build a single sample
1.111 +$(patsubst %,build-%,$(CT_SAMPLES)):
1.112 + $(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
1.113 +
1.114 +# Build al samples
1.115 +build-all: $(patsubst %,build-%,$(CT_SAMPLES))
1.116 +
1.117 +# Build all samples, overiding the number of // jobs per sample
1.118 +build-all.%:
1.119 + $(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |sed -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
1.120 +