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