samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun May 11 23:43:52 2014 +0200 (2014-05-11)
changeset 3320 78af1c99bc6d
parent 3168 9b991363c01c
child 3325 069f43a215cc
permissions -rw-r--r--
scripts/functions: add target_endian_le and target_endian_be

We currently define target_endian_el and target_endian_eb to be the
tuple extension depending on endianness, defined to be respectively
'el' or 'eb' according to the endianness.

Some architecture do not use 'el' or 'eb', but use 'le' or 'be'.

Provide that as well, as two new variables: target_endian_le and
target_endian_be.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Cody P Schafer <dev@codyps.com>
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@2982
    39
	@cp .config .config.sample
yann@2982
    40
	@$(CT_LIB_DIR)/scripts/showSamples.sh -v current
yann@2982
    41
	@rm -f .config.sample
yann@1788
    42
yann@1001
    43
# Prints the details of a sample
yann@1001
    44
PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
yann@2982
    45
$(patsubst %,show-%,$(CT_SAMPLES)): config_files
yann@2982
    46
	@KCONFIG_CONFIG=$$(pwd)/.config.sample	\
yann@3012
    47
	    $(CONF) --defconfig=$(call sample_dir,$(patsubst show-%,%,$(@)))/crosstool.config   \
yann@2982
    48
	            $(KCONFIG_TOP) >/dev/null
yann@539
    49
	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
yann@2982
    50
	@rm -f .config.sample
yann@539
    51
yann@1683
    52
# Prints the details of all samples
yann@1683
    53
PHONY += show-all
yann@1683
    54
show-all: $(patsubst %,show-%,$(CT_SAMPLES))
yann@1683
    55
yann@1001
    56
# print the list of all available samples
yann@544
    57
PHONY += list-samples
yann@3012
    58
list-samples: list-samples-pre $(patsubst %,list-%,$(CT_SAMPLES))
yann@3012
    59
	@echo ' L (Local)       : sample was found in current directory'
yann@3012
    60
	@echo ' G (Global)      : sample was installed with crosstool-NG'
yann@3012
    61
	@echo ' X (EXPERIMENTAL): sample may use EXPERIMENTAL features'
yann@3012
    62
	@echo ' B (BROKEN)      : sample is currently broken'
yann@3012
    63
yann@3012
    64
PHONY += list-samples-pre
yann@3012
    65
list-samples-pre: FORCE
yann@3012
    66
	@echo 'Status  Sample name'
yann@3012
    67
yann@3012
    68
PHONY += $(patsubst %,list-%,$(CT_SAMPLES))
yann@3012
    69
$(patsubst %,list-%,$(CT_SAMPLES)): config_files
yann@3012
    70
	@KCONFIG_CONFIG=$$(pwd)/.config.sample	\
yann@3012
    71
	    $(CONF) --defconfig=$(call sample_dir,$(patsubst list-%,%,$(@)))/crosstool.config   \
yann@3012
    72
	            $(KCONFIG_TOP) >/dev/null
yann@3012
    73
	@$(CT_LIB_DIR)/scripts/showSamples.sh $(patsubst list-%,%,$(@))
yann@3012
    74
	@rm -f .config.sample
yann@474
    75
yann@2053
    76
PHONY += list-samples-short
yann@2053
    77
list-samples-short: FORCE
yann@2053
    78
	$(SILENT)for s in $(CT_SAMPLES); do \
yann@3012
    79
	    printf "%s\n" "$${s}";          \
yann@2053
    80
	done
yann@2053
    81
yann@3168
    82
# Check one sample
yann@3168
    83
PHONY += $(patsubst %,check-%,$(CT_SAMPLES))
yann@3168
    84
$(patsubst %,check-%,$(CT_SAMPLES)): config_files
yann@3168
    85
	@export KCONFIG_CONFIG=$$(pwd)/.config.sample;                                  \
yann@3168
    86
	 CT_NG_SAMPLE=$(call sample_dir,$(patsubst check-%,%,$(@)))/crosstool.config;   \
yann@3168
    87
	 $(CONF) --defconfig=$${CT_NG_SAMPLE} $(KCONFIG_TOP) >/dev/null;                \
yann@3168
    88
	 $(CONF) --savedefconfig=$$(pwd)/.defconfig $(KCONFIG_TOP) >/dev/null;          \
yann@3168
    89
	 old_sha1=$$( sha1sum "$${CT_NG_SAMPLE}" |cut -d ' ' -f 1 );                    \
yann@3168
    90
	 new_sha1=$$( sha1sum .defconfig |cut -d ' ' -f 1 );                            \
yann@3168
    91
	 if [ $${old_sha1} != $${new_sha1} ]; then                                      \
yann@3171
    92
	    echo "$(patsubst check-%,%,$(@)) needs update:";                            \
yann@3171
    93
	    diff -du0 "$${CT_NG_SAMPLE}" .defconfig |tail -n +4;                        \
yann@3168
    94
	 fi
yann@3168
    95
	@rm -f .config.sample* .defconfig
yann@3168
    96
yann@3168
    97
check-samples: $(patsubst %,check-%,$(CT_SAMPLES))
yann@3168
    98
yann@2053
    99
PHONY += wiki-samples
yann@3012
   100
wiki-samples: wiki-samples-pre $(patsubst %,wiki-%,$(CT_SAMPLES)) wiki-samples-post
yann@3012
   101
yann@3012
   102
wiki-samples-pre: FORCE
yann@3012
   103
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w
yann@3012
   104
yann@3012
   105
wiki-samples-post: FORCE
yann@3012
   106
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -W $(CT_SAMPLES)
yann@3012
   107
yann@3012
   108
$(patsubst %,wiki-%,$(CT_SAMPLES)): config_files
yann@3012
   109
	$(SILENT)KCONFIG_CONFIG=$$(pwd)/.config.sample	\
yann@3012
   110
	    $(CONF) --defconfig=$(call sample_dir,$(patsubst wiki-%,%,$(@)))/crosstool.config   \
yann@3012
   111
	            $(KCONFIG_TOP) >/dev/null
yann@3012
   112
	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(patsubst wiki-%,%,$(@))
yann@3012
   113
	$(SILENT)rm -f .config.sample
yann@1001
   114
yann@1001
   115
# ----------------------------------------------------------
yann@1001
   116
# This part deals with saving/restoring samples
yann@1001
   117
yann@1620
   118
PHONY += samples
yann@1620
   119
samples:
yann@1620
   120
	@$(ECHO) '  MKDIR $@'
yann@1620
   121
	$(SILENT)mkdir -p $@
yann@1620
   122
yann@1001
   123
# Save a sample
yann@1620
   124
saveconfig: .config samples
yann@1001
   125
	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
yann@1001
   126
yann@1001
   127
# The 'sample_dir' function prints the directory in which the sample is,
yann@1001
   128
# searching first in local samples, then in global samples
yann@1001
   129
define sample_dir
yann@1001
   130
$$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
yann@1001
   131
endef
yann@1001
   132
yann@933
   133
# How we do recall one sample
yann@182
   134
PHONY += $(CT_SAMPLES)
yann@2981
   135
$(CT_SAMPLES): config_files
yann@2981
   136
	@$(ECHO) "  CONF  $(KCONFIG_TOP)"
yann@2981
   137
	$(SILENT)$(CONF) --defconfig=$(call sample_dir,$@)/crosstool.config $(KCONFIG_TOP)
yann@935
   138
	@echo
yann@935
   139
	@echo  '***********************************************************'
yann@935
   140
	@echo
yann@940
   141
	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
yann@2725
   142
	   echo "Initially reported by: $${reporter_name}";                         \
yann@2725
   143
	   echo "URL: $${reporter_url}";                                            \
yann@935
   144
	   if [ -n "$${reporter_comment}" ]; then                                   \
yann@935
   145
	     echo  ;                                                                \
yann@935
   146
	     echo  "Comment:";                                                      \
yann@935
   147
	     printf "$${reporter_comment}\n";                                       \
yann@935
   148
	   fi;                                                                      \
yann@935
   149
	   echo  ;                                                                  \
yann@935
   150
	   echo  '***********************************************************';     \
yann@935
   151
	 )
yann@1159
   152
	$(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
yann@940
   153
	   echo  ;                                                                  \
yann@940
   154
	   echo  'WARNING! This sample may enable experimental features.';          \
yann@940
   155
	   echo  '         Please be sure to review the configuration prior';       \
yann@940
   156
	   echo  '         to building and using your toolchain!';                  \
yann@940
   157
	   echo  'Now, you have been warned!';                                      \
yann@940
   158
	   echo  ;                                                                  \
yann@940
   159
	   echo  '***********************************************************';     \
yann@822
   160
	 fi
yann@935
   161
	@echo
yann@933
   162
	@echo  'Now configured for "$@"'
yann@182
   163
yann@1001
   164
# ----------------------------------------------------------
yann@1025
   165
# Some helper functions
yann@166
   166
yann@1025
   167
# Create the rule to build a sample
yann@1025
   168
# $1: sample tuple
yann@1025
   169
# $2: prefix
yann@1025
   170
define build_sample
yann@1067
   171
	@$(ECHO) '  CONF  $(1)'
yann@1025
   172
	$(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
yann@1155
   173
	$(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
yann@1155
   174
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
yann@1155
   175
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
yann@1155
   176
	$(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
yann@1155
   177
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
yann@1155
   178
	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
yann@1067
   179
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
yann@1025
   180
	@$(ECHO) '  BUILD $(1)'
yann@1067
   181
	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
yann@1025
   182
endef
yann@230
   183
yann@1025
   184
# ----------------------------------------------------------
yann@1025
   185
# Build samples for use (not regtest!)
yann@230
   186
yann@1025
   187
# Check that PREFIX is set if building samples
yann@1025
   188
ifneq ($(strip $(MAKECMDGOALS)),)
yann@1025
   189
ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
yann@230
   190
yann@1025
   191
ifeq ($(strip $(CT_PREFIX)),)
yann@1025
   192
$(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
yann@1025
   193
endif
yann@333
   194
yann@1025
   195
endif # MAKECMDGOALS contains a build sample rule
yann@1025
   196
endif # MAKECMDGOALS != ""
yann@1025
   197
yann@1025
   198
# Build a single sample
yann@1025
   199
$(patsubst %,build-%,$(CT_SAMPLES)):
yann@1025
   200
	$(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
yann@1025
   201
yann@1025
   202
# Build al samples
yann@1025
   203
build-all: $(patsubst %,build-%,$(CT_SAMPLES))
yann@1025
   204
yann@1025
   205
# Build all samples, overiding the number of // jobs per sample
yann@1025
   206
build-all.%:
yann@1155
   207
	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
yann@1025
   208