samples/Makefile
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jul 09 20:55:32 2007 +0000 (2007-07-09)
changeset 229 9c5809b7fd23
parent 215 aa3b93c54c17
child 230 13f12e53b1b7
permissions -rw-r--r--
Separate clean actions from build actions;
Re-label "Preconfigured actions" to "Preconfigured toolchains";
Small eye-candy fix in the help text for liststeps.
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@176
    10
	@echo  '  saveconfig     - Save current config as a preconfigured target'
yann@176
    11
yann@176
    12
help-samples::
yann@182
    13
	@$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
yann@176
    14
yann@176
    15
help-build::
yann@176
    16
	@echo  '  regtest        - Regtest-build all samples'
yann@63
    17
yann@166
    18
# How we do build one sample
yann@182
    19
PHONY += $(CT_SAMPLES)
yann@166
    20
$(CT_SAMPLES):
yann@182
    21
	@$(MAKE) -f $(CT_MAKEFILE) $(patsubst %,%_copy_config,$(@)) oldconfig
yann@182
    22
yann@182
    23
$(patsubst %,%_copy_config,$(CT_SAMPLES)):
yann@182
    24
	@if [ -f $(CT_TOP_DIR)/samples/$(patsubst %_copy_config,%,$(@))/crosstool.config ]; then                    \
yann@182
    25
	      cp "$(CT_TOP_DIR)/samples/$(patsubst %_copy_config,%,$(@))/crosstool.config" "$(CT_TOP_DIR)/.config"; \
yann@182
    26
	 else                                                                                                       \
yann@182
    27
	      cp "$(CT_LIB_DIR)/samples/$(patsubst %_copy_config,%,$(@))/crosstool.config" "$(CT_TOP_DIR)/.config"; \
yann@182
    28
	 fi
yann@166
    29
yann@166
    30
# And now for building all samples one after the other
yann@166
    31
# We could use a simple rule like: 'regtest: $(CT_SAMPLES)', but that doesn't
yann@166
    32
# work because we want to save the samples as well.
yann@166
    33
# Also, we don't want to see anylog at all, save for the elapsed time, and we
yann@166
    34
# want to save the log file in a specific place
yann@166
    35
# Furthermore, force the location where the toolchain will be installed.
yann@166
    36
# Finaly, we can't use 'make sample-name' as we need to provide default values
yann@166
    37
# if the options set has changed, but oldconfig does not like when stdin is
yann@166
    38
# not a terminal (eg. it is a pipe).
yann@182
    39
PHONY += regtest
yann@166
    40
regtest:
yann@166
    41
	@for samp in $(CT_SAMPLES); do                                                                          \
yann@179
    42
	     echo -e "\rBuilding sample \"$${samp}\""                                                       &&  \
yann@215
    43
	     $(CT_NG) $${samp}_copy_config                                                                  &&  \
yann@215
    44
	     yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
yann@182
    45
	     sed -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$${CT_TOP_DIR}/targets/tst/$${CT_TARGET}":;' .config  &&  \
yann@166
    46
	     sed -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config         &&  \
yann@166
    47
	     sed -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config                                          &&  \
yann@166
    48
	     sed -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config                                 &&  \
yann@166
    49
	     sed -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config                                        &&  \
yann@166
    50
	     sed -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config                                   &&  \
yann@215
    51
	     yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
yann@215
    52
	     $(CT_NG) build                                                                                 &&  \
yann@228
    53
	     echo -e "\rSuccessfully built sample \"$${samp}\""                                             &&  \
yann@179
    54
	     echo -e "\rMaking tarball for sample \"$${samp}\""                                             &&  \
yann@228
    55
	     $(CT_NG) tarball                                                                               &&  \
yann@228
    56
	     echo -e "\rSuccessfully built tarball for sample \"$${samp}\""                                 ;   \
yann@182
    57
	     echo -e "\rCleaning sample \"$${samp}\""                                                       ;   \
yann@215
    58
	     $(CT_NG) distclean                                                                             ;   \
yann@228
    59
	     echo -e "\r"                                                                                   ;   \
yann@166
    60
	 done
yann@166
    61
yann@63
    62
saveconfig:
yann@189
    63
	@$(CT_LIB_DIR)/scripts/saveSample.sh