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