samples/samples.mk
changeset 261 4b8cba298bf3
parent 230 13f12e53b1b7
child 286 983d9c3949e1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/samples.mk	Sun Jul 15 09:09:04 2007 +0000
     1.3 @@ -0,0 +1,71 @@
     1.4 +# Makefile to manage samples
     1.5 +
     1.6 +# Build the list of available samples
     1.7 +CT_TOP_SAMPLES := $(patsubst $(CT_TOP_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_TOP_DIR)/samples/*/crosstool.config))
     1.8 +CT_LIB_SAMPLES := $(filter-out $(CT_TOP_SAMPLES),$(patsubst $(CT_LIB_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_LIB_DIR)/samples/*/crosstool.config)))
     1.9 +
    1.10 +CT_SAMPLES := $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES)
    1.11 +
    1.12 +help-config::
    1.13 +	@echo  '  saveconfig     - Save current config as a preconfigured target'
    1.14 +
    1.15 +help-samples::
    1.16 +	@$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
    1.17 +
    1.18 +help-build::
    1.19 +	@echo  '  regtest        - Regtest-build all samples'
    1.20 +	@echo  '  regtest-local  - Regtest-build all local samples'
    1.21 +	@echo  '  regtest-global - Regtest-build all global samples'
    1.22 +
    1.23 +# How we do build one sample
    1.24 +PHONY += $(CT_SAMPLES)
    1.25 +$(CT_SAMPLES):
    1.26 +	@$(CT_NG) $(patsubst %,copy_config_%,$(@)) oldconfig
    1.27 +
    1.28 +$(patsubst %,copy_config_%,$(CT_SAMPLES)):
    1.29 +	@if [ -f $(CT_TOP_DIR)/samples/$(patsubst copy_config_%,%,$(@))/crosstool.config ]; then                    \
    1.30 +	      cp "$(CT_TOP_DIR)/samples/$(patsubst copy_config_%,%,$(@))/crosstool.config" "$(CT_TOP_DIR)/.config"; \
    1.31 +	 else                                                                                                       \
    1.32 +	      cp "$(CT_LIB_DIR)/samples/$(patsubst copy_config_%,%,$(@))/crosstool.config" "$(CT_TOP_DIR)/.config"; \
    1.33 +	 fi
    1.34 +
    1.35 +# And now for building all samples one after the other
    1.36 +PHONY += regtest regtest_local regtest_global
    1.37 +regtest: regtest-local regtest-global
    1.38 +
    1.39 +regtest-local: $(patsubst %,regtest_%,$(CT_TOP_SAMPLES))
    1.40 +
    1.41 +regtest-global: $(patsubst %,regtest_%,$(CT_LIB_SAMPLES))
    1.42 +
    1.43 +# One regtest per sample
    1.44 +# We could use a simple rule like: 'regtest: $(CT_SAMPLES)', but that doesn't
    1.45 +# work because we want to save the samples as well.
    1.46 +# Also, we don't want to see anylog at all, save for the elapsed time, and we
    1.47 +# want to save the log file in a specific place
    1.48 +# Furthermore, force the location where the toolchain will be installed.
    1.49 +# Finaly, we can't use 'make sample-name' as we need to provide default values
    1.50 +# if the options set has changed, but oldconfig does not like when stdin is
    1.51 +# not a terminal (eg. it is a pipe).
    1.52 +$(patsubst %,regtest_%,$(CT_SAMPLES)):
    1.53 +	@samp=$(patsubst regtest_%,%,$@)                                                                ;   \
    1.54 +	 echo -e "\rBuilding sample \"$${samp}\""                                                       &&  \
    1.55 +	 $(CT_NG) copy_config_$${samp}                                                                  &&  \
    1.56 +	 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
    1.57 +	 sed -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$${CT_TOP_DIR}/targets/tst/$${CT_TARGET}":;' .config  &&  \
    1.58 +	 sed -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config         &&  \
    1.59 +	 sed -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config                                          &&  \
    1.60 +	 sed -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config                                 &&  \
    1.61 +	 sed -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config                                        &&  \
    1.62 +	 sed -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config                                   &&  \
    1.63 +	 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
    1.64 +	 $(CT_NG) build                                                                                 &&  \
    1.65 +	 echo -e "\rSuccessfully built sample \"$${samp}\""                                             &&  \
    1.66 +	 echo -e "\rMaking tarball for sample \"$${samp}\""                                             &&  \
    1.67 +	 $(CT_NG) tarball                                                                               &&  \
    1.68 +	 echo -e "\rSuccessfully built tarball for sample \"$${samp}\""                                 ;   \
    1.69 +	 echo -e "\rCleaning sample \"$${samp}\""                                                       ;   \
    1.70 +	 $(CT_NG) distclean                                                                             ;   \
    1.71 +	 echo -e "\r"
    1.72 +
    1.73 +saveconfig:
    1.74 +	@$(CT_LIB_DIR)/scripts/saveSample.sh