samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Mon May 07 21:37:59 2012 +0200 (2012-05-07)
changeset 2982 1e35d2fa54d7
parent 2981 80151a249b85
child 3012 95173b196a88
permissions -rw-r--r--
samples: rework show-tuple

Now that we are using defconfig files, the samples do not contain
the full configuration, so we can not simply parse them to show
their content.

Instead, we must fake recalling a sample, and parse the generated
.config file.

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