samples/samples.mk
author Remy Bohmer <linux@bohmer.net>
Sun Jul 11 22:23:34 2010 +0200 (2010-07-11)
changeset 2021 3e52a1510f87
parent 1813 26974c3670fd
child 2053 2238f1167eaa
permissions -rw-r--r--
debug/gdb: Fix compilation for Mingw hosts

GDB requires PDcurses instead of ncurses while running on Windows.
So, do not always compile ncurses in case GDB needs to build.

PDcurses is provided by an earlier build step and is not described in
this file.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
[yann.morin.1998@anciense.nib.fr: we already have a way to detect ncurses usage]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
     1 # Makefile to manage samples
     2 
     3 # ----------------------------------------------------------
     4 # Build the list of available samples
     5 CT_TOP_SAMPLES := $(patsubst $(CT_TOP_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_TOP_DIR)/samples/*/crosstool.config))
     6 CT_LIB_SAMPLES := $(filter-out $(CT_TOP_SAMPLES),$(patsubst $(CT_LIB_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_LIB_DIR)/samples/*/crosstool.config)))
     7 CT_SAMPLES := $(shell echo $(sort $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES))  \
     8                       |$(sed) -r -e 's/ /\n/g;'                            \
     9                       |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'                  \
    10                       |LC_ALL=C sort                                    \
    11                       |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'                  \
    12                )
    13 
    14 # ----------------------------------------------------------
    15 # This part deals with the samples help entries
    16 
    17 help-config::
    18 	@echo  '  saveconfig         - Save current config as a preconfigured target'
    19 
    20 help-samples::
    21 	@echo  '  list-samples       - prints the list of all samples (for scripting)'
    22 	@echo  '  show-<sample>      - show a brief overview of <sample> (list with list-samples)'
    23 	@echo  '  <sample>           - preconfigure crosstool-NG with <sample> (list with list-samples)'
    24 	@echo  '  build-all[.#]      - Build *all* samples (list with list-samples) and install in'
    25 	@echo  '                       $${CT_PREFIX} (which you must set)'
    26 
    27 help-distrib::
    28 	@echo  '  wiki-samples       - Print a DokuWiki table of samples'
    29 
    30 help-env::
    31 	@echo  '  CT_PREFIX=dir      - install samples in dir (see action "build-all", above).'
    32 
    33 # ----------------------------------------------------------
    34 # This part deals with printing samples information
    35 
    36 # Print the details of current configuration
    37 PHONY += show-config
    38 show-config: .config
    39 	@export current_tuple=$(shell $(MAKE) -rf "$(CT_NG)" show-tuple );  \
    40 	$(CT_LIB_DIR)/scripts/showSamples.sh -v current
    41 
    42 # Prints the details of a sample
    43 PHONY += $(patsubst %,show-%,$(CT_SAMPLES))
    44 $(patsubst %,show-%,$(CT_SAMPLES)):
    45 	@$(CT_LIB_DIR)/scripts/showSamples.sh -v $(patsubst show-%,%,$(@))
    46 
    47 # Prints the details of all samples
    48 PHONY += show-all
    49 show-all: $(patsubst %,show-%,$(CT_SAMPLES))
    50 
    51 # print the list of all available samples
    52 PHONY += list-samples
    53 list-samples: FORCE
    54 	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh $(CT_SAMPLES)
    55 
    56 wiki-samples:
    57 	$(SILENT)$(CT_LIB_DIR)/scripts/showSamples.sh -w $(CT_SAMPLES)
    58 
    59 # ----------------------------------------------------------
    60 # This part deals with saving/restoring samples
    61 
    62 PHONY += samples
    63 samples:
    64 	@$(ECHO) '  MKDIR $@'
    65 	$(SILENT)mkdir -p $@
    66 
    67 # Save a sample
    68 saveconfig: .config samples
    69 	$(SILENT)$(CT_LIB_DIR)/scripts/saveSample.sh
    70 
    71 # The 'sample_dir' function prints the directory in which the sample is,
    72 # searching first in local samples, then in global samples
    73 define sample_dir
    74 $$( [ -d $(CT_TOP_DIR)/samples/$(1) ] && echo "$(CT_TOP_DIR)/samples/$(1)" || echo "$(CT_LIB_DIR)/samples/$(1)")
    75 endef
    76 
    77 # How we do recall one sample
    78 PHONY += $(CT_SAMPLES)
    79 $(CT_SAMPLES):
    80 	$(SILENT)cp $(call sample_dir,$@)/crosstool.config .config
    81 	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) oldconfig
    82 	@echo
    83 	@echo  '***********************************************************'
    84 	@echo
    85 	$(SILENT)( . $(call sample_dir,$@)/reported.by;                             \
    86 	   echo "Initially reported by: $${reporter_name:-Yann E. MORIN}";          \
    87 	   echo "URL: $${reporter_url:-http://ymorin.is-a-geek.org/}";              \
    88 	   if [ -n "$${reporter_comment}" ]; then                                   \
    89 	     echo  ;                                                                \
    90 	     echo  "Comment:";                                                      \
    91 	     printf "$${reporter_comment}\n";                                       \
    92 	   fi;                                                                      \
    93 	   echo  ;                                                                  \
    94 	   echo  '***********************************************************';     \
    95 	 )
    96 	$(SILENT)if $(grep) -E '^CT_EXPERIMENTAL=y$$' .config >/dev/null 2>&1; then \
    97 	   echo  ;                                                                  \
    98 	   echo  'WARNING! This sample may enable experimental features.';          \
    99 	   echo  '         Please be sure to review the configuration prior';       \
   100 	   echo  '         to building and using your toolchain!';                  \
   101 	   echo  'Now, you have been warned!';                                      \
   102 	   echo  ;                                                                  \
   103 	   echo  '***********************************************************';     \
   104 	 fi
   105 	@echo
   106 	@echo  'Now configured for "$@"'
   107 
   108 # ----------------------------------------------------------
   109 # Some helper functions
   110 
   111 # Create the rule to build a sample
   112 # $1: sample tuple
   113 # $2: prefix
   114 define build_sample
   115 	@$(ECHO) '  CONF  $(1)'
   116 	$(SILENT)cp $(call sample_dir,$(1))/crosstool.config .config
   117 	$(SILENT)$(sed) -i -r -e 's:^(CT_PREFIX_DIR=).*$$:\1"$(2)":;' .config
   118 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config
   119 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config
   120 	$(SILENT)$(sed) -i -r -e 's:^(CT_LOG_LEVEL_MAX)=.*$$:\1="ERROR":;' .config
   121 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_TO_FILE).*$$:\1=y:;' .config
   122 	$(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_PROGRESS_BAR).*$$:\1=y:;' .config
   123 	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 oldconfig
   124 	@$(ECHO) '  BUILD $(1)'
   125 	$(SILENT)$(MAKE) -rf $(CT_NG) V=0 build
   126 endef
   127 
   128 # ----------------------------------------------------------
   129 # Build samples for use (not regtest!)
   130 
   131 # Check that PREFIX is set if building samples
   132 ifneq ($(strip $(MAKECMDGOALS)),)
   133 ifneq ($(strip $(filter $(patsubst %,build-%,$(CT_SAMPLES)) build-all,$(MAKECMDGOALS))),)
   134 
   135 ifeq ($(strip $(CT_PREFIX)),)
   136 $(error Please set 'CT_PREFIX' to where you want to install generated toolchain samples!)
   137 endif
   138 
   139 endif # MAKECMDGOALS contains a build sample rule
   140 endif # MAKECMDGOALS != ""
   141 
   142 # Build a single sample
   143 $(patsubst %,build-%,$(CT_SAMPLES)):
   144 	$(call build_sample,$(patsubst build-%,%,$@),$(CT_PREFIX)/$(patsubst build-%,%,$@))
   145 
   146 # Build al samples
   147 build-all: $(patsubst %,build-%,$(CT_SAMPLES))
   148 
   149 # Build all samples, overiding the number of // jobs per sample
   150 build-all.%:
   151 	$(SILENT)$(MAKE) -rf $(CT_NG) V=$(V) $(shell echo "$(@)" |$(sed) -r -e 's|^([^.]+)\.([[:digit:]]+)$$|\1 CT_JOBS=\2|;')
   152