samples/samples.mk
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Mar 29 00:15:32 2010 +0200 (2010-03-29)
changeset 1864 758d5137fe87
parent 1789 dcfe244fc65a
child 1876 a6a4beab3125
permissions -rw-r--r--
scripts/populate: optimise search loop

Curently, populate will iterate over all ELF (shared objects|executables)
to look for missing NEEDED DSOs, adding to the list at every iterations
of the search loop.

Instead of looking again at previously handled ELF files, recursively
resolve every ELf files.

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