samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Thu Dec 27 12:45:22 2012 +0100 (2012-12-27)
changeset 3152 b286c7993be5
parent 2982 1e35d2fa54d7
child 3168 9b991363c01c
permissions -rw-r--r--
scripts/addToolsVersion: properly handle .in vs. .in.2

While most components have their version in the .in file, some
have it in the .in.2 (eg. elf2flt).

Currently, to handle this case, we indiscriminately munge both files,
but this is wrong: in the elf2flt case, if we add a binutils version,
we do not want it to be added to elf2flt, and conversely.

So, for each tool, we need to explicitly know what file to munge.

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