samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 17 23:06:02 2010 +0100 (2010-01-17)
changeset 1740 c57458bb354d
parent 1683 09ae4c09ba83
child 1788 9547490131d9
permissions -rw-r--r--
configure: do not require hg when configuring in an hg clone

When configuring in an hg clone, we need hg to compute the version string.
It can happen that users do not have Mercurial (eg. if they got a snapshot
rather that they did a full clone). In this case, we can still run, of
course, so simply fill the version string with a sufficiently explicit
value, that does not require hg. The date is a good candidate.
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@1001
    39
# Prints the details of a sample
yann@1001
    40
PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
yann@539
    41
$(patsubst %,show-%,$(CT_SAMPLES)):
yann@539
    42
	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
yann@539
    43
yann@1683
    44
# Prints the details of all samples
yann@1683
    45
PHONY += show-all
yann@1683
    46
show-all: $(patsubst %,show-%,$(CT_SAMPLES))
yann@1683
    47
yann@1001
    48
# print the list of all available samples
yann@544
    49
PHONY += list-samples
yann@1618
    50
list-samples: FORCE
yann@1684
    51
	@echo $(CT_SAMPLES) |$(sed) -r -e 's/ /\n/g;' |sed -r -e 's/(.*),(.*)/\2 \(host: \1\)/;'
yann@474
    52
yann@1001
    53
wiki-samples:
yann@1001
    54
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
yann@1001
    55
yann@1001
    56
# ----------------------------------------------------------
yann@1001
    57
# This part deals with saving/restoring samples
yann@1001
    58
yann@1620
    59
PHONY += samples
yann@1620
    60
samples:
yann@1620
    61
	@$(ECHO) '  MKDIR $@'
yann@1620
    62
	$(SILENT)mkdir -p $@
yann@1620
    63
yann@1001
    64
# Save a sample
yann@1620
    65
saveconfig: .config samples
yann@1001
    66
	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
yann@1001
    67
yann@1001
    68
# The 'sample_dir' function prints the directory in which the sample is,
yann@1001
    69
# searching first in local samples, then in global samples
yann@1001
    70
define sample_dir
yann@1001
    71
$$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
yann@1001
    72
endef
yann@1001
    73
yann@933
    74
# How we do recall one sample
yann@182
    75
PHONY += $(CT_SAMPLES)
yann@166
    76
$(CT_SAMPLES):
yann@940
    77
	$(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
yann@1025
    78
	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
yann@935
    79
	@echo
yann@935
    80
	@echo  '***********************************************************'
yann@935
    81
	@echo
yann@940
    82
	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
yann@935
    83
	   echo "Initially reported by: $${reporter_name:-Yann E. MORIN}";          \
yann@935
    84
	   echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}";              \
yann@935
    85
	   if [ -n "$${reporter_comment}" ]; then                                   \
yann@935
    86
	     echo  ;                                                                \
yann@935
    87
	     echo  "Comment:";                                                      \
yann@935
    88
	     printf "$${reporter_comment}\n";                                       \
yann@935
    89
	   fi;                                                                      \
yann@935
    90
	   echo  ;                                                                  \
yann@935
    91
	   echo  '***********************************************************';     \
yann@935
    92
	 )
yann@1159
    93
	$(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
yann@940
    94
	   echo  ;                                                                  \
yann@940
    95
	   echo  'WARNING! This sample may enable experimental features.';          \
yann@940
    96
	   echo  '         Please be sure to review the configuration prior';       \
yann@940
    97
	   echo  '         to building and using your toolchain!';                  \
yann@940
    98
	   echo  'Now, you have been warned!';                                      \
yann@940
    99
	   echo  ;                                                                  \
yann@940
   100
	   echo  '***********************************************************';     \
yann@822
   101
	 fi
yann@935
   102
	@echo
yann@933
   103
	@echo  'Now configured for "$@"'
yann@182
   104
yann@1001
   105
# ----------------------------------------------------------
yann@1025
   106
# Some helper functions
yann@166
   107
yann@1025
   108
# Create the rule to build a sample
yann@1025
   109
# $1: sample tuple
yann@1025
   110
# $2: prefix
yann@1025
   111
define build_sample
yann@1067
   112
	@$(ECHO) '  CONF  $(1)'
yann@1025
   113
	$(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
yann@1155
   114
	$(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
yann@1155
   115
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
yann@1155
   116
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
yann@1155
   117
	$(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
yann@1155
   118
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
yann@1155
   119
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
yann@1067
   120
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
yann@1025
   121
	@$(ECHO) '  BUILD $(1)'
yann@1067
   122
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
yann@1025
   123
endef
yann@230
   124
yann@1025
   125
# ----------------------------------------------------------
yann@1025
   126
# Build samples for use (not regtest!)
yann@230
   127
yann@1025
   128
# Check that PREFIX is set if building samples
yann@1025
   129
ifneq ($(strip $(MAKECMDGOALS)),)
yann@1025
   130
ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
yann@230
   131
yann@1025
   132
ifeq ($(strip $(CT_PREFIX)),)
yann@1025
   133
$(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
yann@1025
   134
endif
yann@333
   135
yann@1025
   136
endif # MAKECMDGOALS contains a build sample rule
yann@1025
   137
endif # MAKECMDGOALS != ""
yann@1025
   138
yann@1025
   139
# Build a single sample
yann@1025
   140
$(patsubst %,build-%,$(CT_SAMPLES)):
yann@1025
   141
	$(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
yann@1025
   142
yann@1025
   143
# Build al samples
yann@1025
   144
build-all: $(patsubst %,build-%,$(CT_SAMPLES))
yann@1025
   145
yann@1025
   146
# Build all samples, overiding the number of // jobs per sample
yann@1025
   147
build-all.%:
yann@1155
   148
	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
yann@1025
   149