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