samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Jan 29 22:43:28 2010 +0100 (2010-01-29)
changeset 1755 30d91bfc1f2a
parent 1683 09ae4c09ba83
child 1788 9547490131d9
permissions -rw-r--r--
binutils/elf2flt: activate elf2flt build

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