samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 31 15:57:22 2010 +0100 (2010-01-31)
changeset 1788 9547490131d9
parent 1684 93d751a8efd7
child 1789 dcfe244fc65a
permissions -rw-r--r--
scripts: add action to dump current configuration in humane-readable form
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@1682
     8
                      |sed -r -e 's/ /\n/g;'                            \
yann@1682
     9
                      |sed -r -e 's/(.*),(.*)/\2,\1/;'                  \
yann@1682
    10
                      |LC_ALL=C sort                                    \
yann@1682
    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@544
    22
	@echo  '  show-<sample>      - show a brief overview of <sample> (list below)'
yann@544
    23
	@echo  '  <sample>           - preconfigure crosstool-NG with <sample> (list below)'
yann@1025
    24
	@echo  '  build-all[.#]      - Build *all* samples (list below) and install in'
yann@1025
    25
	@echo  '                       $${CT_PREFIX} (which you must set)'
yann@1025
    26
	@echo  '  Available samples:'
yann@182
    27
	@$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
yann@176
    28
yann@560
    29
help-distrib::
yann@560
    30
	@echo  '  wiki-samples       - Print a DokuWiki table of samples'
yann@560
    31
yann@1025
    32
help-env::
yann@1025
    33
	@echo  '  CT_PREFIX          - directory in which to auto-install samples'
yann@1025
    34
	@echo  '                       (see action "build-all", above).'
yann@1025
    35
yann@1001
    36
# ----------------------------------------------------------
yann@1001
    37
# This part deals with printing samples information
yann@1001
    38
yann@1788
    39
# Print the details of current configuration
yann@1788
    40
PHONY += show-config
yann@1788
    41
show-config: .config
yann@1788
    42
	@$(CT_LIB_DIR)/scripts/showSamples.sh -v current
yann@1788
    43
yann@1001
    44
# Prints the details of a sample
yann@1001
    45
PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
yann@539
    46
$(patsubst %,show-%,$(CT_SAMPLES)):
yann@539
    47
	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
yann@539
    48
yann@1683
    49
# Prints the details of all samples
yann@1683
    50
PHONY += show-all
yann@1683
    51
show-all: $(patsubst %,show-%,$(CT_SAMPLES))
yann@1683
    52
yann@1001
    53
# print the list of all available samples
yann@544
    54
PHONY += list-samples
yann@1618
    55
list-samples: FORCE
yann@1684
    56
	@echo $(CT_SAMPLES) |$(sed) -r -e 's/ /\n/g;' |sed -r -e 's/(.*),(.*)/\2 \(host: \1\)/;'
yann@474
    57
yann@1001
    58
wiki-samples:
yann@1001
    59
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
yann@1001
    60
yann@1001
    61
# ----------------------------------------------------------
yann@1001
    62
# This part deals with saving/restoring samples
yann@1001
    63
yann@1620
    64
PHONY += samples
yann@1620
    65
samples:
yann@1620
    66
	@$(ECHO) '  MKDIR $@'
yann@1620
    67
	$(SILENT)mkdir -p $@
yann@1620
    68
yann@1001
    69
# Save a sample
yann@1620
    70
saveconfig: .config samples
yann@1001
    71
	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
yann@1001
    72
yann@1001
    73
# The 'sample_dir' function prints the directory in which the sample is,
yann@1001
    74
# searching first in local samples, then in global samples
yann@1001
    75
define sample_dir
yann@1001
    76
$$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
yann@1001
    77
endef
yann@1001
    78
yann@933
    79
# How we do recall one sample
yann@182
    80
PHONY += $(CT_SAMPLES)
yann@166
    81
$(CT_SAMPLES):
yann@940
    82
	$(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
yann@1025
    83
	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
yann@935
    84
	@echo
yann@935
    85
	@echo  '***********************************************************'
yann@935
    86
	@echo
yann@940
    87
	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
yann@935
    88
	   echo "Initially reported by: $${reporter_name:-Yann E. MORIN}";          \
yann@935
    89
	   echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}";              \
yann@935
    90
	   if [ -n "$${reporter_comment}" ]; then                                   \
yann@935
    91
	     echo  ;                                                                \
yann@935
    92
	     echo  "Comment:";                                                      \
yann@935
    93
	     printf "$${reporter_comment}\n";                                       \
yann@935
    94
	   fi;                                                                      \
yann@935
    95
	   echo  ;                                                                  \
yann@935
    96
	   echo  '***********************************************************';     \
yann@935
    97
	 )
yann@1159
    98
	$(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
yann@940
    99
	   echo  ;                                                                  \
yann@940
   100
	   echo  'WARNING! This sample may enable experimental features.';          \
yann@940
   101
	   echo  '         Please be sure to review the configuration prior';       \
yann@940
   102
	   echo  '         to building and using your toolchain!';                  \
yann@940
   103
	   echo  'Now, you have been warned!';                                      \
yann@940
   104
	   echo  ;                                                                  \
yann@940
   105
	   echo  '***********************************************************';     \
yann@822
   106
	 fi
yann@935
   107
	@echo
yann@933
   108
	@echo  'Now configured for "$@"'
yann@182
   109
yann@1001
   110
# ----------------------------------------------------------
yann@1025
   111
# Some helper functions
yann@166
   112
yann@1025
   113
# Create the rule to build a sample
yann@1025
   114
# $1: sample tuple
yann@1025
   115
# $2: prefix
yann@1025
   116
define build_sample
yann@1067
   117
	@$(ECHO) '  CONF  $(1)'
yann@1025
   118
	$(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
yann@1155
   119
	$(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
yann@1155
   120
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
yann@1155
   121
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
yann@1155
   122
	$(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
yann@1155
   123
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
yann@1155
   124
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
yann@1067
   125
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
yann@1025
   126
	@$(ECHO) '  BUILD $(1)'
yann@1067
   127
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
yann@1025
   128
endef
yann@230
   129
yann@1025
   130
# ----------------------------------------------------------
yann@1025
   131
# Build samples for use (not regtest!)
yann@230
   132
yann@1025
   133
# Check that PREFIX is set if building samples
yann@1025
   134
ifneq ($(strip $(MAKECMDGOALS)),)
yann@1025
   135
ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
yann@230
   136
yann@1025
   137
ifeq ($(strip $(CT_PREFIX)),)
yann@1025
   138
$(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
yann@1025
   139
endif
yann@333
   140
yann@1025
   141
endif # MAKECMDGOALS contains a build sample rule
yann@1025
   142
endif # MAKECMDGOALS != ""
yann@1025
   143
yann@1025
   144
# Build a single sample
yann@1025
   145
$(patsubst %,build-%,$(CT_SAMPLES)):
yann@1025
   146
	$(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
yann@1025
   147
yann@1025
   148
# Build al samples
yann@1025
   149
build-all: $(patsubst %,build-%,$(CT_SAMPLES))
yann@1025
   150
yann@1025
   151
# Build all samples, overiding the number of // jobs per sample
yann@1025
   152
build-all.%:
yann@1155
   153
	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
yann@1025
   154