samples/samples.mk
author Zhenqiang Chen <zhenqiang.chen@linaro.org>
Fri Nov 18 11:32:50 2011 +0800 (2011-11-18)
branch1.13
changeset 2841 64fe22ca6e6f
parent 2722 ca0322db584f
child 2981 80151a249b85
permissions -rw-r--r--
cc/gcc: Apply CT_CC_GCC_DISABLE_PCH to do_cc_core.

Otherwise, users have to input --disable-libstdcxx-pch option
when building bare-metal CANADIAN C++ compiler.

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