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