samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon May 26 21:49:36 2008 +0000 (2008-05-26)
changeset 539 c538627f69f1
parent 474 2904d77fe117
child 544 6b15ef33e8f2
permissions -rw-r--r--
Rework dumping the samples.

/trunk/scripts/showSamples.sh | 1 0 1 0 -
/trunk/samples/samples.mk | 10 7 3 0 +++++++---
2 files changed, 7 insertions(+), 4 deletions(-)
     1 # Makefile to manage samples
     2 
     3 # Build the list of available samples
     4 CT_TOP_SAMPLES := $(patsubst $(CT_TOP_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_TOP_DIR)/samples/*/crosstool.config))
     5 CT_LIB_SAMPLES := $(filter-out $(CT_TOP_SAMPLES),$(patsubst $(CT_LIB_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_LIB_DIR)/samples/*/crosstool.config)))
     6 
     7 CT_SAMPLES := $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES)
     8 
     9 help-config::
    10 	@echo  '  saveconfig         - Save current config as a preconfigured target'
    11 
    12 help-samples::
    13 	@echo  '  samples            - prints the list of all samples (for scripting)'
    14 	@echo  '  show-<sample>      - show a brief overview of <sample>'
    15 	@$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
    16 
    17 help-build::
    18 	@echo  '  regtest[.#]        - Regtest-build all samples'
    19 	@echo  '  regtest-local[.#]  - Regtest-build all local samples'
    20 	@echo  '  regtest-global[.#] - Regtest-build all global samples'
    21 
    22 $(patsubst %,show-%,$(CT_SAMPLES)):
    23 	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
    24 
    25 samples:
    26 	@echo $(CT_SAMPLES) |sed -r -e 's/ /\n/g;' |sort
    27 
    28 # How we do build one sample
    29 PHONY += $(CT_SAMPLES)
    30 $(CT_SAMPLES):
    31 	@echo  'Configuring for "$@"'
    32 	@$(CT_NG) $(patsubst %,copy_config_%,$(@)) oldconfig
    33 	@echo  'Execute "$(CT_NG) build" to build your toolchain'
    34 
    35 $(patsubst %,copy_config_%,$(CT_SAMPLES)):
    36 	@if [ -f $(CT_TOP_DIR)/samples/$(patsubst copy_config_%,%,$(@))/crosstool.config ]; then                    \
    37 	      cp "$(CT_TOP_DIR)/samples/$(patsubst copy_config_%,%,$(@))/crosstool.config" "$(CT_TOP_DIR)/.config"; \
    38 	 else                                                                                                       \
    39 	      cp "$(CT_LIB_DIR)/samples/$(patsubst copy_config_%,%,$(@))/crosstool.config" "$(CT_TOP_DIR)/.config"; \
    40 	 fi
    41 
    42 # And now for building all samples one after the other
    43 PHONY += regtest regtest_local regtest_global
    44 regtest: regtest-local regtest-global
    45 
    46 regtest-local: $(patsubst %,regtest_%,$(CT_TOP_SAMPLES))
    47 
    48 regtest-global: $(patsubst %,regtest_%,$(CT_LIB_SAMPLES))
    49 
    50 regtest.% regtest-local.% regtest-global.%:
    51 	@$(CT_NG) $(shell echo "$(@)" |sed -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
    52 
    53 # One regtest per sample
    54 # We could use a simple rule like: 'regtest: $(CT_SAMPLES)', but that doesn't
    55 # work because we want to save the samples as well.
    56 # Also, we don't want to see anylog at all, save for the elapsed time, and we
    57 # want to save the log file in a specific place
    58 # Furthermore, force the location where the toolchain will be installed.
    59 # Finaly, we can't use 'make sample-name' as we need to provide default values
    60 # if the options set has changed, but oldconfig does not like when stdin is
    61 # not a terminal (eg. it is a pipe).
    62 $(patsubst %,regtest_%,$(CT_SAMPLES)):
    63 	@samp=$(patsubst regtest_%,%,$@)                                                                ;   \
    64 	 echo -e "\rBuilding sample \"$${samp}\""                                                       &&  \
    65 	 $(CT_NG) copy_config_$${samp}                                                                  &&  \
    66 	 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
    67 	 sed -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$${CT_TOP_DIR}/targets/tst/$${CT_TARGET}":;' .config  &&  \
    68 	 sed -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config         &&  \
    69 	 sed -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config                                          &&  \
    70 	 sed -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config                                 &&  \
    71 	 sed -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config                                        &&  \
    72 	 sed -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config                                   &&  \
    73 	 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
    74 	 $(CT_NG) build                                                                                 &&  \
    75 	 echo -e "\rSuccessfully built sample \"$${samp}\""                                             &&  \
    76 	 echo -e "\rMaking tarball for sample \"$${samp}\""                                             &&  \
    77 	 $(CT_NG) tarball                                                                               &&  \
    78 	 echo -e "\rSuccessfully built tarball for sample \"$${samp}\""                                 ;   \
    79 	 echo -e "\rCleaning sample \"$${samp}\""                                                       ;   \
    80 	 $(CT_NG) distclean                                                                             ;   \
    81 	 echo -e "\r"
    82 
    83 saveconfig:
    84 	@$(CT_LIB_DIR)/scripts/saveSample.sh