samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Aug 21 23:11:26 2011 +0200 (2011-08-21)
changeset 2623 e8e30025fcc5
parent 1876 a6a4beab3125
child 2722 ca0322db584f
permissions -rw-r--r--
configure: recognise and handle --program-transform-name

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