samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Oct 27 18:42:26 2008 +0000 (2008-10-27)
changeset 1001 c8ac48ba1411
parent 940 f0f9ba3f98f2
child 1025 fc64f85e41cc
permissions -rw-r--r--
Enhance the make fragments:
- comment the different parts
- re-order the code so that it is homogeneous amogst fragments
- eye-candy in some existing comments

/trunk/tools/tools.mk | 17 15 2 0 +++++++++++++++--
/trunk/steps.mk | 38 26 12 0 ++++++++++++++++++++++++++------------
/trunk/samples/samples.mk | 41 28 13 0 ++++++++++++++++++++++++++++-------------
/trunk/config/config.mk | 2 1 1 0 +-
4 files changed, 70 insertions(+), 28 deletions(-)
     1 # Makefile to manage samples
     2 
     3 # ----------------------------------------------------------
     4 # Build the list of available samples
     5 CT_TOP_SAMPLES := $(patsubst $(CT_TOP_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_TOP_DIR)/samples/*/crosstool.config))
     6 CT_LIB_SAMPLES := $(filter-out $(CT_TOP_SAMPLES),$(patsubst $(CT_LIB_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_LIB_DIR)/samples/*/crosstool.config)))
     7 CT_SAMPLES := $(sort $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES))
     8 
     9 # ----------------------------------------------------------
    10 # This part deals with the samples help entries
    11 
    12 help-config::
    13 	@echo  '  saveconfig         - Save current config as a preconfigured target'
    14 
    15 help-samples::
    16 	@echo  '  list-samples       - prints the list of all samples (for scripting)'
    17 	@echo  '  show-<sample>      - show a brief overview of <sample> (list below)'
    18 	@echo  '  <sample>           - preconfigure crosstool-NG with <sample> (list below)'
    19 	@$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
    20 
    21 help-build::
    22 	@echo  '  regtest[.#]        - Regtest-build all samples'
    23 	@echo  '  regtest-local[.#]  - Regtest-build all local samples'
    24 	@echo  '  regtest-global[.#] - Regtest-build all global samples'
    25 
    26 help-distrib::
    27 	@echo  '  wiki-samples       - Print a DokuWiki table of samples'
    28 
    29 # ----------------------------------------------------------
    30 # This part deals with printing samples information
    31 
    32 # Prints the details of a sample
    33 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
    34 $(patsubst %,show-%,$(CT_SAMPLES)):
    35 	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
    36 
    37 # print the list of all available samples
    38 PHONY += list-samples
    39 list-samples: .FORCE
    40 	@echo $(CT_SAMPLES) |sed -r -e 's/ /\n/g;' |sort
    41 
    42 wiki-samples:
    43 	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
    44 
    45 # ----------------------------------------------------------
    46 # This part deals with saving/restoring samples
    47 
    48 # Save a sample
    49 saveconfig:
    50 	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
    51 
    52 # The 'sample_dir' function prints the directory in which the sample is,
    53 # searching first in local samples, then in global samples
    54 define sample_dir
    55 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
    56 endef
    57 
    58 # How we do recall one sample
    59 PHONY += $(CT_SAMPLES)
    60 $(CT_SAMPLES):
    61 	$(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
    62 	$(SILENT)$(MAKE) -rf $(CT_NG) oldconfig
    63 	@echo
    64 	@echo  '***********************************************************'
    65 	@echo
    66 	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
    67 	   echo "Initially reported by: $${reporter_name:-Yann E. MORIN}";          \
    68 	   echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}";              \
    69 	   if [ -n "$${reporter_comment}" ]; then                                   \
    70 	     echo  ;                                                                \
    71 	     echo  "Comment:";                                                      \
    72 	     printf "$${reporter_comment}\n";                                       \
    73 	   fi;                                                                      \
    74 	   echo  ;                                                                  \
    75 	   echo  '***********************************************************';     \
    76 	 )
    77 	$(SILENT)if grep -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then    \
    78 	   echo  ;                                                                  \
    79 	   echo  'WARNING! This sample may enable experimental features.';          \
    80 	   echo  '         Please be sure to review the configuration prior';       \
    81 	   echo  '         to building and using your toolchain!';                  \
    82 	   echo  'Now, you have been warned!';                                      \
    83 	   echo  ;                                                                  \
    84 	   echo  '***********************************************************';     \
    85 	 fi
    86 	@echo
    87 	@echo  'Now configured for "$@"'
    88 
    89 # ----------------------------------------------------------
    90 # And now for building all samples one after the other
    91 
    92 PHONY += regtest regtest_local regtest_global
    93 regtest: regtest-local regtest-global
    94 
    95 regtest-local: $(patsubst %,regtest_%,$(CT_TOP_SAMPLES))
    96 
    97 regtest-global: $(patsubst %,regtest_%,$(CT_LIB_SAMPLES))
    98 
    99 regtest.% regtest-local.% regtest-global.%:
   100 	$(SILENT)$(CT_NG) $(shell echo "$(@)" |sed -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
   101 
   102 # One regtest per sample
   103 # We could use a simple rule like: 'regtest: $(CT_SAMPLES)', but that doesn't
   104 # work because we want to save the samples as well.
   105 # Also, we don't want to see anylog at all, save for the elapsed time, and we
   106 # want to save the log file in a specific place
   107 # Furthermore, force the location where the toolchain will be installed.
   108 # Finaly, we can't use 'make sample-name' as we need to provide default values
   109 # if the options set has changed, but oldconfig does not like when stdin is
   110 # not a terminal (eg. it is a pipe).
   111 $(patsubst %,regtest_%,$(CT_SAMPLES)):
   112 	$(SILENT)samp=$(patsubst regtest_%,%,$@)                                                        ;   \
   113 	 echo -e "\rBuilding sample \"$${samp}\""                                                       &&  \
   114 	 $(CT_NG) copy_config_$${samp}                                                                  &&  \
   115 	 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
   116 	 sed -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$${CT_TOP_DIR}/targets/tst/$${CT_TARGET}":;' .config  &&  \
   117 	 sed -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config         &&  \
   118 	 sed -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config                                          &&  \
   119 	 sed -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config                                 &&  \
   120 	 sed -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config                                        &&  \
   121 	 sed -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config                                   &&  \
   122 	 yes "" |$(CT_NG) defoldconfig >/dev/null 2>&1                                                  &&  \
   123 	 $(CT_NG) build                                                                                 &&  \
   124 	 echo -e "\rSuccessfully built sample \"$${samp}\""                                             &&  \
   125 	 echo -e "\rMaking tarball for sample \"$${samp}\""                                             &&  \
   126 	 $(CT_NG) tarball                                                                               &&  \
   127 	 echo -e "\rSuccessfully built tarball for sample \"$${samp}\""                                 ;   \
   128 	 echo -e "\rCleaning sample \"$${samp}\""                                                       ;   \
   129 	 $(CT_NG) distclean                                                                             ;   \
   130 	 echo -e "\r"