samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Mon May 07 21:37:59 2012 +0200 (2012-05-07)
changeset 2982 1e35d2fa54d7
parent 2981 80151a249b85
child 3012 95173b196a88
permissions -rw-r--r--
samples: rework show-tuple

Now that we are using defconfig files, the samples do not contain
the full configuration, so we can not simply parse them to show
their content.

Instead, we must fake recalling a sample, and parse the generated
.config file.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
     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 := $(shell echo $(sort $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES))  \
     8                       |$(sed) -r -e 's/ /\n/g;'                         \
     9                       |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'               \
    10                       |sort                                             \
    11                       |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'               \
    12                )
    13 
    14 # ----------------------------------------------------------
    15 # This part deals with the samples help entries
    16 
    17 help-config::
    18 	@echo  '  saveconfig         - Save current config as a preconfigured target'
    19 
    20 help-samples::
    21 	@echo  '  list-samples       - prints the list of all samples (for scripting)'
    22 	@echo  '  show-<sample>      - show a brief overview of <sample> (list with list-samples)'
    23 	@echo  '  <sample>           - preconfigure crosstool-NG with <sample> (list with list-samples)'
    24 	@echo  '  build-all[.#]      - Build *all* samples (list with list-samples) and install in'
    25 	@echo  '                       $${CT_PREFIX} (which you must set)'
    26 
    27 help-distrib::
    28 	@echo  '  wiki-samples       - Print a DokuWiki table of samples'
    29 
    30 help-env::
    31 	@echo  '  CT_PREFIX=dir      - install samples in dir (see action "build-all", above).'
    32 
    33 # ----------------------------------------------------------
    34 # This part deals with printing samples information
    35 
    36 # Print the details of current configuration
    37 PHONY += show-config
    38 show-config: .config
    39 	@cp .config .config.sample
    40 	@$(CT_LIB_DIR)/scripts/showSamples.sh -v current
    41 	@rm -f .config.sample
    42 
    43 # Prints the details of a sample
    44 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
    45 $(patsubst %,show-%,$(CT_SAMPLES)): config_files
    46 	@KCONFIG_CONFIG=$$(pwd)/.config.sample	\
    47 	    $(CONF) --defconfig=$(call sample_dir,$(patsubst show-%,%,$(@)))/crosstool.config \
    48 	            $(KCONFIG_TOP) >/dev/null
    49 	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
    50 	@rm -f .config.sample
    51 
    52 # Prints the details of all samples
    53 PHONY += show-all
    54 show-all: $(patsubst %,show-%,$(CT_SAMPLES))
    55 
    56 # print the list of all available samples
    57 PHONY += list-samples
    58 list-samples: FORCE
    59 	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
    60 
    61 PHONY += list-samples-short
    62 list-samples-short: FORCE
    63 	$(SILENT)for s in $(CT_SAMPLES); do \
    64 	    printf "$${s}\n";               \
    65 	done
    66 
    67 PHONY += wiki-samples
    68 wiki-samples:
    69 	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
    70 
    71 # ----------------------------------------------------------
    72 # This part deals with saving/restoring samples
    73 
    74 PHONY += samples
    75 samples:
    76 	@$(ECHO) '  MKDIR $@'
    77 	$(SILENT)mkdir -p $@
    78 
    79 # Save a sample
    80 saveconfig: .config samples
    81 	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
    82 
    83 # The 'sample_dir' function prints the directory in which the sample is,
    84 # searching first in local samples, then in global samples
    85 define sample_dir
    86 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
    87 endef
    88 
    89 # How we do recall one sample
    90 PHONY += $(CT_SAMPLES)
    91 $(CT_SAMPLES): config_files
    92 	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
    93 	$(SILENT)$(CONF) --defconfig=$(call sample_dir,$@)/crosstool.config $(KCONFIG_TOP)
    94 	@echo
    95 	@echo  '***********************************************************'
    96 	@echo
    97 	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
    98 	   echo "Initially reported by: $${reporter_name}";                         \
    99 	   echo "URL: $${reporter_url}";                                            \
   100 	   if [ -n "$${reporter_comment}" ]; then                                   \
   101 	     echo  ;                                                                \
   102 	     echo  "Comment:";                                                      \
   103 	     printf "$${reporter_comment}\n";                                       \
   104 	   fi;                                                                      \
   105 	   echo  ;                                                                  \
   106 	   echo  '***********************************************************';     \
   107 	 )
   108 	$(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
   109 	   echo  ;                                                                  \
   110 	   echo  'WARNING! This sample may enable experimental features.';          \
   111 	   echo  '         Please be sure to review the configuration prior';       \
   112 	   echo  '         to building and using your toolchain!';                  \
   113 	   echo  'Now, you have been warned!';                                      \
   114 	   echo  ;                                                                  \
   115 	   echo  '***********************************************************';     \
   116 	 fi
   117 	@echo
   118 	@echo  'Now configured for "$@"'
   119 
   120 # ----------------------------------------------------------
   121 # Some helper functions
   122 
   123 # Create the rule to build a sample
   124 # $1: sample tuple
   125 # $2: prefix
   126 define build_sample
   127 	@$(ECHO) '  CONF  $(1)'
   128 	$(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
   129 	$(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
   130 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
   131 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
   132 	$(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
   133 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
   134 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
   135 	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
   136 	@$(ECHO) '  BUILD $(1)'
   137 	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
   138 endef
   139 
   140 # ----------------------------------------------------------
   141 # Build samples for use (not regtest!)
   142 
   143 # Check that PREFIX is set if building samples
   144 ifneq ($(strip $(MAKECMDGOALS)),)
   145 ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
   146 
   147 ifeq ($(strip $(CT_PREFIX)),)
   148 $(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
   149 endif
   150 
   151 endif # MAKECMDGOALS contains a build sample rule
   152 endif # MAKECMDGOALS != ""
   153 
   154 # Build a single sample
   155 $(patsubst %,build-%,$(CT_SAMPLES)):
   156 	$(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
   157 
   158 # Build al samples
   159 build-all: $(patsubst %,build-%,$(CT_SAMPLES))
   160 
   161 # Build all samples, overiding the number of // jobs per sample
   162 build-all.%:
   163 	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
   164