samples/samples.mk
author "Titus von Boxberg" <tvb377@gmx.de>
Wed Feb 03 00:24:24 2010 +0100 (2010-02-03)
changeset 1813 26974c3670fd
parent 1789 dcfe244fc65a
child 1876 a6a4beab3125
permissions -rw-r--r--
scripts/samples: use the computed '$(sed)', not 'sed'
     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                       |LC_ALL=C 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 below)'
    23 	@echo  '  <sample>           - preconfigure crosstool-NG with <sample> (list below)'
    24 	@echo  '  build-all[.#]      - Build *all* samples (list below) and install in'
    25 	@echo  '                       $${CT_PREFIX} (which you must set)'
    26 	@echo  '  Available samples:'
    27 	@$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
    28 
    29 help-distrib::
    30 	@echo  '  wiki-samples       - Print a DokuWiki table of samples'
    31 
    32 help-env::
    33 	@echo  '  CT_PREFIX          - directory in which to auto-install samples'
    34 	@echo  '                       (see action "build-all", above).'
    35 
    36 # ----------------------------------------------------------
    37 # This part deals with printing samples information
    38 
    39 # Print the details of current configuration
    40 PHONY += show-config
    41 show-config: .config
    42 	@export current_tuple=$(shell $(MAKE) -rf "$(CT_NG)" show-tuple );  \
    43 	$(CT_LIB_DIR)/scripts/showSamples.sh -v current
    44 
    45 # Prints the details of a sample
    46 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
    47 $(patsubst %,show-%,$(CT_SAMPLES)):
    48 	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
    49 
    50 # Prints the details of all samples
    51 PHONY += show-all
    52 show-all: $(patsubst %,show-%,$(CT_SAMPLES))
    53 
    54 # print the list of all available samples
    55 PHONY += list-samples
    56 list-samples: FORCE
    57 	@echo $(CT_SAMPLES) |$(sed) -r -e 's/ /\n/g;' |sed -r -e 's/(.*),(.*)/\2 \(host: \1\)/;'
    58 
    59 wiki-samples:
    60 	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
    61 
    62 # ----------------------------------------------------------
    63 # This part deals with saving/restoring samples
    64 
    65 PHONY += samples
    66 samples:
    67 	@$(ECHO) '  MKDIR $@'
    68 	$(SILENT)mkdir -p $@
    69 
    70 # Save a sample
    71 saveconfig: .config samples
    72 	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
    73 
    74 # The 'sample_dir' function prints the directory in which the sample is,
    75 # searching first in local samples, then in global samples
    76 define sample_dir
    77 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
    78 endef
    79 
    80 # How we do recall one sample
    81 PHONY += $(CT_SAMPLES)
    82 $(CT_SAMPLES):
    83 	$(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
    84 	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
    85 	@echo
    86 	@echo  '***********************************************************'
    87 	@echo
    88 	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
    89 	   echo "Initially reported by: $${reporter_name:-Yann E. MORIN}";          \
    90 	   echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}";              \
    91 	   if [ -n "$${reporter_comment}" ]; then                                   \
    92 	     echo  ;                                                                \
    93 	     echo  "Comment:";                                                      \
    94 	     printf "$${reporter_comment}\n";                                       \
    95 	   fi;                                                                      \
    96 	   echo  ;                                                                  \
    97 	   echo  '***********************************************************';     \
    98 	 )
    99 	$(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
   100 	   echo  ;                                                                  \
   101 	   echo  'WARNING! This sample may enable experimental features.';          \
   102 	   echo  '         Please be sure to review the configuration prior';       \
   103 	   echo  '         to building and using your toolchain!';                  \
   104 	   echo  'Now, you have been warned!';                                      \
   105 	   echo  ;                                                                  \
   106 	   echo  '***********************************************************';     \
   107 	 fi
   108 	@echo
   109 	@echo  'Now configured for "$@"'
   110 
   111 # ----------------------------------------------------------
   112 # Some helper functions
   113 
   114 # Create the rule to build a sample
   115 # $1: sample tuple
   116 # $2: prefix
   117 define build_sample
   118 	@$(ECHO) '  CONF  $(1)'
   119 	$(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
   120 	$(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
   121 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
   122 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
   123 	$(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
   124 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
   125 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
   126 	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
   127 	@$(ECHO) '  BUILD $(1)'
   128 	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
   129 endef
   130 
   131 # ----------------------------------------------------------
   132 # Build samples for use (not regtest!)
   133 
   134 # Check that PREFIX is set if building samples
   135 ifneq ($(strip $(MAKECMDGOALS)),)
   136 ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
   137 
   138 ifeq ($(strip $(CT_PREFIX)),)
   139 $(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
   140 endif
   141 
   142 endif # MAKECMDGOALS contains a build sample rule
   143 endif # MAKECMDGOALS != ""
   144 
   145 # Build a single sample
   146 $(patsubst %,build-%,$(CT_SAMPLES)):
   147 	$(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
   148 
   149 # Build al samples
   150 build-all: $(patsubst %,build-%,$(CT_SAMPLES))
   151 
   152 # Build all samples, overiding the number of // jobs per sample
   153 build-all.%:
   154 	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
   155