samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jun 01 21:12:00 2008 +0000 (2008-06-01)
changeset 544 6b15ef33e8f2
parent 539 c538627f69f1
child 560 0ca969b84057
permissions -rw-r--r--
Rework a little bit the steps and samples help entries.

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