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>
yann@166
     1
# Makefile to manage samples
yann@63
     2
yann@1001
     3
# ----------------------------------------------------------
yann@166
     4
# Build the list of available samples
yann@182
     5
CT_TOP_SAMPLES := $(patsubst $(CT_TOP_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_TOP_DIR)/samples/*/crosstool.config))
yann@182
     6
CT_LIB_SAMPLES := $(filter-out $(CT_TOP_SAMPLES),$(patsubst $(CT_LIB_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_LIB_DIR)/samples/*/crosstool.config)))
yann@1682
     7
CT_SAMPLES := $(shell echo $(sort $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES))  \
yann@2722
     8
                      |$(sed) -r -e 's/ /\n/g;'                         \
yann@2722
     9
                      |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'               \
yann@2722
    10
                      |sort                                             \
yann@2722
    11
                      |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'               \
yann@1682
    12
               )
yann@182
    13
yann@1001
    14
# ----------------------------------------------------------
yann@1001
    15
# This part deals with the samples help entries
yann@63
    16
yann@176
    17
help-config::
yann@333
    18
	@echo  '  saveconfig         - Save current config as a preconfigured target'
yann@176
    19
yann@176
    20
help-samples::
yann@544
    21
	@echo  '  list-samples       - prints the list of all samples (for scripting)'
yann@1876
    22
	@echo  '  show-<sample>      - show a brief overview of <sample> (list with list-samples)'
yann@1876
    23
	@echo  '  <sample>           - preconfigure crosstool-NG with <sample> (list with list-samples)'
yann@1876
    24
	@echo  '  build-all[.#]      - Build *all* samples (list with list-samples) and install in'
yann@1025
    25
	@echo  '                       $${CT_PREFIX} (which you must set)'
yann@176
    26
yann@560
    27
help-distrib::
yann@560
    28
	@echo  '  wiki-samples       - Print a DokuWiki table of samples'
yann@560
    29
yann@1025
    30
help-env::
yann@1876
    31
	@echo  '  CT_PREFIX=dir      - install samples in dir (see action "build-all", above).'
yann@1025
    32
yann@1001
    33
# ----------------------------------------------------------
yann@1001
    34
# This part deals with printing samples information
yann@1001
    35
yann@1788
    36
# Print the details of current configuration
yann@1788
    37
PHONY += show-config
yann@1788
    38
show-config: .config
yann@2982
    39
	@cp .config .config.sample
yann@2982
    40
	@$(CT_LIB_DIR)/scripts/showSamples.sh -v current
yann@2982
    41
	@rm -f .config.sample
yann@1788
    42
yann@1001
    43
# Prints the details of a sample
yann@1001
    44
PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
yann@2982
    45
$(patsubst %,show-%,$(CT_SAMPLES)): config_files
yann@2982
    46
	@KCONFIG_CONFIG=$$(pwd)/.config.sample	\
yann@3012
    47
	    $(CONF) --defconfig=$(call sample_dir,$(patsubst show-%,%,$(@)))/crosstool.config   \
yann@2982
    48
	            $(KCONFIG_TOP) >/dev/null
yann@539
    49
	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
yann@2982
    50
	@rm -f .config.sample
yann@539
    51
yann@1683
    52
# Prints the details of all samples
yann@1683
    53
PHONY += show-all
yann@1683
    54
show-all: $(patsubst %,show-%,$(CT_SAMPLES))
yann@1683
    55
yann@1001
    56
# print the list of all available samples
yann@544
    57
PHONY += list-samples
yann@3012
    58
list-samples: list-samples-pre $(patsubst %,list-%,$(CT_SAMPLES))
yann@3012
    59
	@echo ' L (Local)       : sample was found in current directory'
yann@3012
    60
	@echo ' G (Global)      : sample was installed with crosstool-NG'
yann@3012
    61
	@echo ' X (EXPERIMENTAL): sample may use EXPERIMENTAL features'
yann@3012
    62
	@echo ' B (BROKEN)      : sample is currently broken'
yann@3012
    63
yann@3012
    64
PHONY += list-samples-pre
yann@3012
    65
list-samples-pre: FORCE
yann@3012
    66
	@echo 'Status  Sample name'
yann@3012
    67
yann@3012
    68
PHONY += $(patsubst %,list-%,$(CT_SAMPLES))
yann@3012
    69
$(patsubst %,list-%,$(CT_SAMPLES)): config_files
yann@3012
    70
	@KCONFIG_CONFIG=$$(pwd)/.config.sample	\
yann@3012
    71
	    $(CONF) --defconfig=$(call sample_dir,$(patsubst list-%,%,$(@)))/crosstool.config   \
yann@3012
    72
	            $(KCONFIG_TOP) >/dev/null
yann@3012
    73
	@$(CT_LIB_DIR)/scripts/showSamples.sh $(patsubst list-%,%,$(@))
yann@3012
    74
	@rm -f .config.sample
yann@474
    75
yann@2053
    76
PHONY += list-samples-short
yann@2053
    77
list-samples-short: FORCE
yann@2053
    78
	$(SILENT)for s in $(CT_SAMPLES); do \
yann@3012
    79
	    printf "%s\n" "$${s}";          \
yann@2053
    80
	done
yann@2053
    81
yann@2053
    82
PHONY += wiki-samples
yann@3012
    83
wiki-samples: wiki-samples-pre $(patsubst %,wiki-%,$(CT_SAMPLES)) wiki-samples-post
yann@3012
    84
yann@3012
    85
wiki-samples-pre: FORCE
yann@3012
    86
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w
yann@3012
    87
yann@3012
    88
wiki-samples-post: FORCE
yann@3012
    89
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -W $(CT_SAMPLES)
yann@3012
    90
yann@3012
    91
$(patsubst %,wiki-%,$(CT_SAMPLES)): config_files
yann@3012
    92
	$(SILENT)KCONFIG_CONFIG=$$(pwd)/.config.sample	\
yann@3012
    93
	    $(CONF) --defconfig=$(call sample_dir,$(patsubst wiki-%,%,$(@)))/crosstool.config   \
yann@3012
    94
	            $(KCONFIG_TOP) >/dev/null
yann@3012
    95
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(patsubst wiki-%,%,$(@))
yann@3012
    96
	$(SILENT)rm -f .config.sample
yann@1001
    97
yann@1001
    98
# ----------------------------------------------------------
yann@1001
    99
# This part deals with saving/restoring samples
yann@1001
   100
yann@1620
   101
PHONY += samples
yann@1620
   102
samples:
yann@1620
   103
	@$(ECHO) '  MKDIR $@'
yann@1620
   104
	$(SILENT)mkdir -p $@
yann@1620
   105
yann@1001
   106
# Save a sample
yann@1620
   107
saveconfig: .config samples
yann@1001
   108
	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
yann@1001
   109
yann@1001
   110
# The 'sample_dir' function prints the directory in which the sample is,
yann@1001
   111
# searching first in local samples, then in global samples
yann@1001
   112
define sample_dir
yann@1001
   113
$$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
yann@1001
   114
endef
yann@1001
   115
yann@933
   116
# How we do recall one sample
yann@182
   117
PHONY += $(CT_SAMPLES)
yann@2981
   118
$(CT_SAMPLES): config_files
yann@2981
   119
	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
yann@2981
   120
	$(SILENT)$(CONF) --defconfig=$(call sample_dir,$@)/crosstool.config $(KCONFIG_TOP)
yann@935
   121
	@echo
yann@935
   122
	@echo  '***********************************************************'
yann@935
   123
	@echo
yann@940
   124
	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
yann@2725
   125
	   echo "Initially reported by: $${reporter_name}";                         \
yann@2725
   126
	   echo "URL: $${reporter_url}";                                            \
yann@935
   127
	   if [ -n "$${reporter_comment}" ]; then                                   \
yann@935
   128
	     echo  ;                                                                \
yann@935
   129
	     echo  "Comment:";                                                      \
yann@935
   130
	     printf "$${reporter_comment}\n";                                       \
yann@935
   131
	   fi;                                                                      \
yann@935
   132
	   echo  ;                                                                  \
yann@935
   133
	   echo  '***********************************************************';     \
yann@935
   134
	 )
yann@1159
   135
	$(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
yann@940
   136
	   echo  ;                                                                  \
yann@940
   137
	   echo  'WARNING! This sample may enable experimental features.';          \
yann@940
   138
	   echo  '         Please be sure to review the configuration prior';       \
yann@940
   139
	   echo  '         to building and using your toolchain!';                  \
yann@940
   140
	   echo  'Now, you have been warned!';                                      \
yann@940
   141
	   echo  ;                                                                  \
yann@940
   142
	   echo  '***********************************************************';     \
yann@822
   143
	 fi
yann@935
   144
	@echo
yann@933
   145
	@echo  'Now configured for "$@"'
yann@182
   146
yann@1001
   147
# ----------------------------------------------------------
yann@1025
   148
# Some helper functions
yann@166
   149
yann@1025
   150
# Create the rule to build a sample
yann@1025
   151
# $1: sample tuple
yann@1025
   152
# $2: prefix
yann@1025
   153
define build_sample
yann@1067
   154
	@$(ECHO) '  CONF  $(1)'
yann@1025
   155
	$(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
yann@1155
   156
	$(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
yann@1155
   157
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
yann@1155
   158
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
yann@1155
   159
	$(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
yann@1155
   160
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
yann@1155
   161
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
yann@1067
   162
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
yann@1025
   163
	@$(ECHO) '  BUILD $(1)'
yann@1067
   164
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
yann@1025
   165
endef
yann@230
   166
yann@1025
   167
# ----------------------------------------------------------
yann@1025
   168
# Build samples for use (not regtest!)
yann@230
   169
yann@1025
   170
# Check that PREFIX is set if building samples
yann@1025
   171
ifneq ($(strip $(MAKECMDGOALS)),)
yann@1025
   172
ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
yann@230
   173
yann@1025
   174
ifeq ($(strip $(CT_PREFIX)),)
yann@1025
   175
$(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
yann@1025
   176
endif
yann@333
   177
yann@1025
   178
endif # MAKECMDGOALS contains a build sample rule
yann@1025
   179
endif # MAKECMDGOALS != ""
yann@1025
   180
yann@1025
   181
# Build a single sample
yann@1025
   182
$(patsubst %,build-%,$(CT_SAMPLES)):
yann@1025
   183
	$(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
yann@1025
   184
yann@1025
   185
# Build al samples
yann@1025
   186
build-all: $(patsubst %,build-%,$(CT_SAMPLES))
yann@1025
   187
yann@1025
   188
# Build all samples, overiding the number of // jobs per sample
yann@1025
   189
build-all.%:
yann@1155
   190
	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
yann@1025
   191