5 kx
5 kx # include once
5 kx ifndef CORE_MK
5 kx
5 kx #######
5 kx ####### helpful variables
5 kx #######
5 kx
5 kx comma := ,
5 kx empty :=
5 kx space := $(empty) $(empty)
5 kx
5 kx
5 kx #######
5 kx ####### Set up TOP_BUILD_DIR, TOP_BUILD_DIR_ABS and BUILDSYSTEM variables
5 kx #######
5 kx
5 kx ifndef MAKEFILE_LIST
5 kx
5 kx # Work-around for GNU make pre-3.80, which lacks MAKEFILE_LIST and $(eval ...)
5 kx
5 kx TOP_BUILD_DIR := $(shell perl -e 'for ($$_ = "$(CURDIR)"; ! -d "$$_/build-system"; s!(.*)/(.*)!\1!) { $$q .= "../"; } chop $$q; print "$$q"')
5 kx ifeq ($(TOP_BUILD_DIR),)
5 kx TOP_BUILD_DIR=.
5 kx endif
5 kx export TOP_BUILD_DIR_ABS := $(shell perl -e 'for ($$_ = "$(CURDIR)"; ! -d "$$_/build-system"; s!(.*)/(.*)!\1!) { } print')
5 kx export BUILDSYSTEM := $(TOP_BUILD_DIR_ABS)/build-system
5 kx
5 kx else
5 kx
5 kx # Normal operation for GNU make 3.80 and above
5 kx
5 kx __pop = $(patsubst %/,%,$(dir $(1)))
5 kx __tmp := $(call __pop,$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
5 kx # Special case for build-system/Makefile
5 kx ifeq ($(__tmp),.)
5 kx __tmp := ../$(notdir $(CURDIR))
5 kx endif
5 kx
5 kx ifndef TOP_BUILD_DIR
5 kx TOP_BUILD_DIR := $(call __pop,$(__tmp))
5 kx endif
5 kx
5 kx ifndef TOP_BUILD_DIR_ABS
5 kx TOP_BUILD_DIR_ABS := $(CURDIR)
5 kx ifneq ($(TOP_BUILD_DIR),.)
5 kx $(foreach ,$(subst /, ,$(TOP_BUILD_DIR)),$(eval TOP_BUILD_DIR_ABS := $(call __pop,$(TOP_BUILD_DIR_ABS))))
5 kx endif
5 kx export TOP_BUILD_DIR_ABS
5 kx endif
5 kx
5 kx ifndef BUILDSYSTEM
5 kx export BUILDSYSTEM := $(TOP_BUILD_DIR_ABS)/$(notdir $(__tmp))
5 kx endif
5 kx
5 kx endif
5 kx
5 kx #######
5 kx ####### Set up SOURCE PACKAGE directory:
5 kx #######
5 kx
5 kx export SRC_PACKAGE_DIR := sources
5 kx export SRC_PACKAGE_PATH := $(TOP_BUILD_DIR)/$(SRC_PACKAGE_DIR)
5 kx export SRC_PACKAGE_PATH_ABS := $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)
5 kx
5 kx
5 kx
5 kx #######
5 kx ####### Config:
5 kx #######
5 kx
5 kx include $(BUILDSYSTEM)/config.mk
5 kx
5 kx TOOLCHAIN_ALL = $(strip $(foreach t, $(filter TOOLCHAIN_%, \
5 kx $(filter-out TOOLCHAIN_ALL \
5 kx TOOLCHAIN_NAMES \
5 kx TOOLCHAIN_DIR \
5 kx TOOLCHAIN_PATH \
5 kx TOOLCHAIN_VERSION, \
5 kx $(.VARIABLES))), $($(t))))
5 kx
5 kx TOOLCHAIN_NAMES = $(filter-out $(TOOLCHAIN_NOARCH), $(TOOLCHAIN_ALL))
5 kx
5 kx COMPONENT_TOOLCHAINS = $(TOOLCHAIN_ALL)
5 kx
5 kx
5 kx #######
5 kx ####### Set up targets etc
5 kx #######
5 kx
5 kx ifneq ($(wildcard $(BUILDSYSTEM)/targets-config.mk),)
5 kx include $(BUILDSYSTEM)/targets-config.mk
5 kx else
5 kx include $(BUILDSYSTEM)/targets-config.mk.template
5 kx endif
5 kx
5 kx # Reading targets-config.mk:
5 kx
5 kx # BUILD_NOARCH always enabled:
5 kx BUILD_NOARCH = true
5 kx
5 kx enabled = $(filter BUILD_%, $(filter-out BUILD_TARGETS BUILD_ARCH, $(.VARIABLES)))
5 kx
5 kx toolchain_filter = $(strip $(foreach t, \
5 kx $(strip $(foreach b, \
5 kx $(enabled), $(if $(filter true, $($(b))), \
5 kx $(subst BUILD_, TOOLCHAIN_, $(b))))), $($(t))))
5 kx
5 kx
5 kx # If no TOOLCHAIN set
5 kx ifeq ($(TOOLCHAIN),)
5 kx
5 kx # COMPONENT_TARGETS must have a value specified in the Makefile
5 kx ifeq ($(COMPONENT_TARGETS),)
5 kx $(error Error: COMPONENT_TARGETS must have a value)
5 kx endif
5 kx
5 kx # End if no TARGET set
5 kx endif
5 kx
5 kx # Error ff TOOLCHAIN is invalid
5 kx ifneq ($(TOOLCHAIN),)
5 kx ifeq ($(filter $(TOOLCHAIN), $(TOOLCHAIN_ALL)),)
5 kx $(error Error: TOOLCHAIN is invalid)
5 kx endif
5 kx endif
5 kx
5 kx
5 kx #######
5 kx ####### Filter out disabled targets
5 kx #######
5 kx
5 kx COMPONENT_TARGETS := $(filter $(toolchain_filter), $(COMPONENT_TARGETS))
5 kx
5 kx
5 kx #######
5 kx ####### Targets setup:
5 kx #######
5 kx
5 kx COMPONENT_TOOLCHAINS := $(filter $(COMPONENT_TARGETS),$(COMPONENT_TOOLCHAINS))
5 kx
5 kx
5 kx #
5 kx # TARGET, TOOLCHAIN_PATH variables should be set up for each makefile
5 kx #
5 kx
5 kx # If toolchain version is not exported then we use default one
5 kx ifeq ($(TOOLCHAIN_VERSION),)
5 kx TOOLCHAIN_VERSION = $(TOOLCHAINS_VERSION)
5 kx endif
5 kx
5 kx #
5 kx # Setup current toolchain variables
5 kx #
5 kx
5 kx TOOLCHAIN_DIR = $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_DIR)
5 kx TOOLCHAIN_PATH = $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_PATH)/$(TOOLCHAIN_VERSION)
5 kx TARGET = $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_ARCH)
5 kx
5 kx
5 kx #######
5 kx ####### Configuration:
5 kx #######
5 kx
5 kx # Build environment:
5 kx
5 kx DEST_DIR_ABS = $(TOP_BUILD_DIR_ABS)/dist
5 kx
5 kx ifeq ($(NEEDS_ABS_PATHS),)
5 kx DEST_DIR = $(TOP_BUILD_DIR)/dist
5 kx else
5 kx DEST_DIR = $(DEST_DIR_ABS)
5 kx endif
5 kx
5 kx TARGET_DEST_DIR = $(DEST_DIR)/$(TOOLCHAIN)
5 kx
5 kx
5 kx ################################################################
5 kx # Check the list of available targets for current Makefile
5 kx #
5 kx __available_targets = \
5 kx $(foreach arch, $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'), \
5 kx $(if $(FLAVOURS), \
5 kx $(foreach flavour, $(FLAVOURS), \
5 kx .target_$(arch)_$(flavour) \
5 kx ) .target_$(arch), \
5 kx .target_$(arch) \
5 kx ) \
5 kx )
5 kx
5 kx __available_targets := $(strip $(__available_targets))
5 kx __available_targets := $(sort $(__available_targets))
5 kx #
5 kx #
5 kx ################################################################
5 kx
5 kx
5 kx
5 kx #######
5 kx ####### Number of CPU cores:
5 kx #######
5 kx
5 kx NUMPROCS := 1
5 kx OS := $(shell uname -s)
5 kx
5 kx ifeq ($(OS),Linux)
5 kx NUMPROCS := $(shell grep -c ^processor /proc/cpuinfo)
5 kx endif
5 kx
5 kx
5 kx #######
5 kx ####### Parallel control:
5 kx #######
5 kx
5 kx ifneq ($(NO_PARALLEL),)
5 kx MAKEFLAGS += -j1
5 kx .NOTPARALLEL:
5 kx endif
5 kx
5 kx ifeq ($(VERBOSE),)
5 kx guiet = @
5 kx else
5 kx quiet =
5 kx endif
5 kx
5 kx
5 kx
5 kx #######
5 kx ####### Default PREFIX:
5 kx #######
5 kx
5 kx PREFIX ?= $(DEST_DIR)
5 kx
5 kx
5 kx #######
5 kx ####### Setup ccache:
5 kx #######
5 kx
5 kx ifeq ($(NO_CCACHE),)
5 kx CCACHE = /usr/bin/ccache$(space)
5 kx
5 kx ifeq ($(wildcard $(CCACHE)),)
5 kx $(info )
5 kx $(info #######)
5 kx $(info ####### Please install 'ccache' package)
5 kx $(info ####### or disable ccache with "NO_CCACHE=1 make ...")
5 kx $(info #######)
5 kx $(info )
5 kx $(error Error: ccache not found)
5 kx endif
5 kx
5 kx ifeq ($(wildcard $(CACHED_CC_OUTPUT)),)
5 kx $(info )
5 kx $(info #######)
5 kx $(info ####### Please create directory $(CACHED_CC_OUTPUT) for cached compiler output)
5 kx $(info ####### or disable ccache with "NO_CCACHE=1 make ...")
5 kx $(info #######)
5 kx $(info )
5 kx $(error Error: cached compiler output directory doesn't exist)
5 kx endif
5 kx
5 kx export CCACHE_BASEDIR = $(TOP_BUILD_DIR_ABS)
5 kx export CCACHE_DIR = $(CACHED_CC_OUTPUT)
5 kx export CCACHE_UMASK = 000
5 kx
5 kx unexport CCACHE_PREFIX
5 kx else
5 kx CCACHE =
5 kx endif
5 kx
5 kx
5 kx
5 kx #######
5 kx ####### Cleanup files:
5 kx #######
5 kx
5 kx CLEANUP_FILES += .dist.*
5 kx CLEANUP_FILES += $(addprefix ., $(TOOLCHAIN))
5 kx CLEANUP_FILES += .*requires*
5 kx CLEANUP_FILES += $(SRC_DIR)
5 kx CLEANUP_FILES += $(SRC_DIR).back.??????
5 kx
5 kx
5 kx #######
5 kx ####### Build rules:
5 kx #######
5 kx
5 kx all: BUILD_TREE := true
5 kx export BUILD_TREE
5 kx
5 kx all:
5 kx @$(MAKE) local_all
5 kx
5 kx #
5 kx # clean is equal to local_clean
5 kx #
5 kx clean:
5 kx @$(MAKE) local_clean
5 kx
5 kx
5 kx __quick_targets := help configure_targets local_clean downloads_clean targets-config.mk $(HACK_TARGETS)
5 kx
5 kx
5 kx #
5 kx # GLOBAL setup targets:
5 kx # ====================
5 kx # These targets are built before all targets. For example, source tarballs
5 kx # have to be downloaded before starting the build.
5 kx #
5 kx # NOTE:
5 kx # BUILDSYSTEM is a setup target for other directories and the BUILDSYSTEM
5 kx # requires only '.sources' target as a setup target.
5 kx #
5 kx ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
5 kx ifeq ($(shell pwd),$(BUILDSYSTEM))
5 kx __setup_targets = .sources
5 kx else
5 kx __setup_targets = .sources .build_system
5 kx endif
5 kx endif
5 kx
5 kx
5 kx
5 kx .setup:
5 kx ifeq ($(__final__),)
5 kx .setup: $(__setup_targets)
5 kx else
5 kx .setup: .makefile
5 kx endif
5 kx
5 kx
5 kx # Check if Makefile has been changed:
5 kx
5 kx .makefile: Makefile
5 kx ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
5 kx ifneq ($(if $(MAKECMDGOALS),$(filter-out $(__quick_targets),$(MAKECMDGOALS)),true),)
5 kx @touch $@
5 kx ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
5 kx @echo -e "\n======= New makefile ($(<F)), clean! ======="
5 kx @$(MAKE) dist_clean
5 kx @if $(MAKE) local_clean ; then true ; else rm -f $@ ; fi
5 kx else
5 kx @if $(MAKE) download_clean ; then true ; else rm -f $@; fi
5 kx endif
5 kx endif
5 kx endif
5 kx
5 kx
5 kx
5 kx #######
5 kx ####### Build directory dependencies into .src_requires which
5 kx ####### is used as a Makefile for srource tarballs downloading
5 kx #######
5 kx
5 kx .sources: .src_requires
5 kx
5 kx .src_requires_depend: .src_requires ;
5 kx
5 kx .src_requires: .makefile
5 kx ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
5 kx ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
5 kx ifeq ($(__final__),)
5 kx @echo ""
5 kx @echo -e "################################################################"
5 kx @echo -e "#######"
5 kx @echo -e "####### Start of building source requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))':"
5 kx @echo -e "#######"
5 kx @$(BUILDSYSTEM)/build_src_requires $(TOP_BUILD_DIR_ABS)
5 kx @__final__= TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN_NOARCH) FLAVOUR= -f .src_requires
5 kx @echo -e "#######"
5 kx @echo -e "####### End of building source requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))'."
5 kx @echo -e "#######"
5 kx @echo -e "################################################################"
5 kx @echo ""
5 kx @touch $@
5 kx @touch .src_requires_depend
5 kx endif
5 kx endif
5 kx endif
5 kx
5 kx
5 kx
5 kx .build_system:
5 kx ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
5 kx ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
5 kx ifeq ($(shell pwd | grep $(BUILDSYSTEM)),)
5 kx @echo -e "################################################################"
5 kx @echo -e "#######"
5 kx @echo -e "####### Start to Check the BUILDSYSTEM is ready:"
5 kx @echo -e "#######"
5 kx @( cd $(BUILDSYSTEM) ; __final__= $(MAKE) TOOLCHAIN=$(TOOLCHAIN_HOST) FLAVOUR= all )
5 kx @echo -e "#######"
5 kx @echo -e "####### End of checking the BUILDSYSTEM."
5 kx @echo -e "#######"
5 kx @echo -e "################################################################"
5 kx endif
5 kx endif
5 kx endif
5 kx
5 kx
5 kx
5 kx #######
5 kx ####### Clean up default rules (not depend of TOOLCHAIN):
5 kx #######
5 kx
5 kx dist_clean:
5 kx @if [ -f .dist ]; then $(BUILDSYSTEM)/dist_clean $(DEST_DIR); rm .dist; fi
5 kx
5 kx
5 kx # NOTE:
5 kx # ====
5 kx # Do not create directories with names that match the names of architectures!!!
5 kx #
5 kx tree_clean: .tree_clean
5 kx
5 kx .tree_clean:
5 kx @echo "Tree Clean..."
5 kx @$(BUILDSYSTEM)/tree_clean $(addprefix ., $(TOOLCHAIN_NAMES)) $(TOP_BUILD_DIR_ABS)
5 kx
5 kx
5 kx #######
5 kx ####### Clean all downloaded source tarballs
5 kx #######
5 kx
5 kx downloads_clean: .downloads_clean
5 kx
5 kx .downloads_clean:
5 kx @echo ""
5 kx @echo -e "#######"
5 kx @echo -e "####### Cleaning Up all downloaded sources..."
5 kx @echo -e "#######"
5 kx @$(BUILDSYSTEM)/downloads_clean $(addprefix ., $(TOOLCHAIN_NOARCH)) $(BUILDSYSTEM)/3pp/sources
5 kx ifneq ($(wildcard $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)),)
5 kx @$(BUILDSYSTEM)/downloads_clean $(addprefix ., $(TOOLCHAIN_NOARCH)) $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)
5 kx endif
5 kx
5 kx help:
5 kx @echo ""
5 kx @echo -e "You can build and install software using command line such as follow:"
5 kx @echo ""
5 kx @echo -e " $$ [TOOLCHAIN_VERSION=version] [TOOLCHAIN=toolchain] [FLAVOUR=flavour] make [goal]"
5 kx @echo ""
5 kx @echo -e "The following MAKE goals are available:"
5 kx @echo ""
5 kx @echo -e " all - perform make build and install software in the all"
5 kx @echo -e " required directories which defined by REQUIRES"
5 kx @echo -e " variable in the local Makefile;"
5 kx @echo -e " local_all - build and install software prepared onlu by local"
5 kx @echo -e " Makefile;"
5 kx @echo -e " dist_clean,"
5 kx @echo -e " local_dist_clean - remove distribution packages from target directory"
5 kx @echo -e " defined by PRODUCTS_DEST_DIR variable. Note that"
5 kx @echo -e " is depends from targets defined by COMPONENT_TARGETS"
5 kx @echo -e " variable or command line;"
5 kx @echo -e " clean,"
5 kx @echo -e " local_clean - clean up all built targets by this Makefile;"
5 kx @echo ""
5 kx @echo -e " If the one from above goals has prefix 'local_' then this goal affects only"
5 kx @echo -e " current directory. Otherwise this goal will be performed for all required"
5 kx @echo -e " directories which defined by REQUIRES variable."
5 kx @echo ""
5 kx @echo -e " configure_targets - select toolchains you want to built."
5 kx @echo -e " This command edits the targets-config.mk file;"
5 kx @echo ""
5 kx @echo -e " tree_clean - clean up whole sourses tree excluding downloaded"
5 kx @echo -e " source tarballs;"
5 kx @echo -e " downloads_clean - remove all sourse tarball from 'sourses' directory;"
5 kx @echo ""
5 kx @echo -e "Local Makefile is prepared for following target toolchains:"
5 kx @echo ""
5 kx @for toolchain in $(COMPONENT_TARGETS) ; do \
5 kx echo -e " $$toolchain"; \
5 kx done
5 kx @echo ""
5 kx @echo -e "Enjoy."
5 kx @echo ""
5 kx
5 kx configure_targets: $(BUILDSYSTEM)/targets-config.mk
5 kx @BUILDSYSTEM=$(BUILDSYSTEM) \
5 kx CONFIG=$(BUILDSYSTEM)/targets-config.mk \
5 kx CONSTANTS=$(BUILDSYSTEM)/config.mk \
5 kx $(BUILDSYSTEM)/configure-targets
5 kx
5 kx
5 kx #######
5 kx ####### Source archive and patch handling
5 kx #######
5 kx
5 kx # Patch dependency:
5 kx PATCHES_DEP = $(foreach patch,$(PATCHES),\
5 kx $(shell $(BUILDSYSTEM)/apply_patches $(patch) -dep-))
5 kx
5 kx SRC_DIR_BASE = $(dir $(SRC_DIR))
5 kx
5 kx # Unpack SRC_ARCHIVE in SRC_DIR and backup old SRC_DIR:
5 kx UNPACK_SRC_ARCHIVE = \
5 kx @echo "Expanding $(SRC_ARCHIVE)"; \
5 kx if [ -d $(SRC_DIR) ]; then mv $(SRC_DIR) $$(mktemp -d $(SRC_DIR).bak.XXXXXX); fi; \
5 kx mkdir -p $(SRC_DIR_BASE); \
5 kx $(if $(findstring .rpm,$(SRC_ARCHIVE)), \
5 kx cd $(SRC_DIR_BASE) && rpm2cpio $(SRC_ARCHIVE) | cpio -id --quiet, \
5 kx $(if $(findstring .zip,$(SRC_ARCHIVE)), \
5 kx unzip -q -d $(SRC_DIR_BASE) $(SRC_ARCHIVE), \
5 kx tar $(if $(findstring .bz2,$(SRC_ARCHIVE)),-xjf, \
5 kx $(if $(findstring .xz,$(SRC_ARCHIVE)),-xJf, \
5 kx $(if $(findstring .txz,$(SRC_ARCHIVE)),-xJf,-xzf))) \
5 kx $(SRC_ARCHIVE) -C $(SRC_DIR_BASE))); \
5 kx chmod -R u+w $(SRC_DIR)
5 kx
5 kx # Apply patches in PATCHES on SRC_DIR_BASE:
5 kx APPLY_PATCHES = $(quiet)$(foreach patch,$(PATCHES),\
5 kx $(BUILDSYSTEM)/apply_patches $(patch) $(SRC_DIR_BASE) &&) true
5 kx
5 kx # Apply optional patches in OPT_PATCHES on SRC_DIR_BASE:
5 kx APPLY_OPT_PATCHES = $(quiet)$(foreach patch,$(OPT_PATCHES),\
5 kx $(BUILDSYSTEM)/apply_patches $(patch) $(SRC_DIR_BASE) &&) true
5 kx
5 kx
5 kx # Example rule:
5 kx #
5 kx # src_done = $(SRC_DIR)/.source-done
5 kx #
5 kx # $(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
5 kx # $(UNPACK_SRC_ARCHIVE)
5 kx # $(APPLY_PATCHES)
5 kx # <other stuff that needs to be done to the source,
5 kx # should be empty in most cases>
5 kx # @touch $@
5 kx
5 kx
5 kx ################################################################
5 kx #######
5 kx ####### Include files with references to BUILD-SYSTEM scripts:
5 kx #######
5 kx
5 kx -include $(BUILDSYSTEM)/sbin/.config
5 kx
5 kx #######
5 kx ####### References to BUILD-SYSTEM scripts.
5 kx #######
5 kx ################################################################
5 kx
5 kx
5 kx
5 kx
5 kx ################################################################
5 kx #
5 kx # No '__final__' target selected:
5 kx # ==============================
5 kx #
5 kx # Parse TOOLCHAIN, HARDWARE, FLAVOUR selected in command line
5 kx # and build the list of '__final__' targets.
5 kx #
5 kx ifeq ($(__final__),)
5 kx
5 kx #
5 kx # The FLAVOUR can be defined in command line.
5 kx # If command line defines empty flavour FLAVOUR= then
5 kx # we define that variable is set but has no values.
5 kx #
5 kx __cmdline_flavour_defined = $(if $(filter FLAVOUR,$(.VARIABLES)),true,false)
5 kx ifeq ($(__cmdline_flavour_defined),true)
5 kx __cmdline_flavour_value = $(FLAVOUR)
5 kx else
5 kx __cmdline_flavour_value =
5 kx endif
5 kx
5 kx
5 kx ##################################################
5 kx # -----------+---------+-------------------+-----
5 kx # TOOLCHAIN | FLAVOUR | FLAVOUR has VALUE | REF
5 kx # -----------+---------+-------------------+-----
5 kx # defined | defined | no | (0)
5 kx # defined | defined | yes | (1)
5 kx # defined | ~ | ~ | (2)
5 kx # ~ | defined | no | (3)
5 kx # ~ | defined | yes | (4)
5 kx # ~ | ~ | ~ | (5)
5 kx # -----------+---------+-------------------+-----
5 kx ##################################################
5 kx
5 kx ifeq ($(TOOLCHAIN),)
5 kx ifeq ($(__cmdline_flavour_defined),false)
5 kx ifeq ($(FLAVOUR),)
5 kx # (5) then we loop over all available flavours
5 kx __target_args = $(__available_targets)
5 kx endif
5 kx else
5 kx ifneq ($(FLAVOUR),)
5 kx # (4) then we use only one defined flavour
5 kx __target_args = $(foreach toolchain, \
5 kx $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'), \
5 kx .target_$(toolchain)_$(FLAVOUR) \
5 kx )
5 kx else
5 kx # (3) then we define flavour as empty
5 kx __target_args = $(foreach toolchain, \
5 kx $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'), \
5 kx .target_$(toolchain) \
5 kx )
5 kx endif
5 kx endif
5 kx else
5 kx ifeq ($(__cmdline_flavour_defined),false)
5 kx ifeq ($(FLAVOUR),)
5 kx # (2) then we loop over all available flavours
5 kx __target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g') $(if $(FLAVOURS), $(foreach flavour, $(FLAVOURS), .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(flavour)),)
5 kx endif
5 kx else
5 kx ifneq ($(FLAVOUR),)
5 kx # (1) then we use only one defined flavour
5 kx __target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(FLAVOUR)
5 kx else
5 kx # (0) then we define flavour as empty
5 kx __target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')
5 kx endif
5 kx endif
5 kx endif
5 kx
5 kx
5 kx __target_args := $(strip $(__target_args))
5 kx
5 kx
5 kx __targets = $(filter $(__target_args), $(__available_targets))
5 kx
5 kx # Now we have to sort targets for that the main targets should be built before flavours!
5 kx __targets := $(sort $(__targets))
5 kx
5 kx
5 kx ifeq ($(__targets),)
5 kx $(error Error: Selected combination [TOOLCHAIN=$(TOOLCHAIN), FLAVOUR=$(FLAVOUR)] is invalid for this Makefile)
5 kx endif
5 kx
5 kx
5 kx $(__targets): .setup
5 kx
5 kx local_all: GOAL = local_all
5 kx local_all: $(__targets)
5 kx
5 kx local_clean: GOAL = local_clean
5 kx local_clean: $(__targets)
5 kx
5 kx
5 kx .target_%: TOOLCHAIN = $(shell echo $(word 2, $(subst _, , $@)) | sed -e 's/x86-64/x86_64/g')
5 kx .target_%: FLAVOUR = $(word 3, $(subst _, , $@))
5 kx .target_%:
5 kx @echo ""
5 kx @echo "======="
5 kx @echo "======= TOOLCHAIN: $(TOOLCHAIN); FLAVOUR =$(if $(FLAVOUR), $(FLAVOUR)); ====="
5 kx @echo "======="
5 kx @__final__=true $(MAKE) TOOLCHAIN=$(TOOLCHAIN) FLAVOUR=$(FLAVOUR) $(GOAL)
5 kx
5 kx else
5 kx #
5 kx ################################################################
5 kx #
5 kx # The '__final__' target is defined, run the build process.
5 kx
5 kx
5 kx # Target is selected, build it
5 kx
5 kx ifneq ($(NO_CREATE_DIST_FILES),true)
5 kx local_all: CREATE_DIST_FILES = 1
5 kx endif
5 kx
5 kx ifneq ($(findstring $(TOOLCHAIN),$(TOOLCHAIN_NAMES)),)
5 kx ifeq ($(shell pwd),$(BUILDSYSTEM))
5 kx $(shell mkdir -p .$(TOOLCHAIN))
5 kx else
5 kx $(shell mkdir -p .$(TOOLCHAIN)$(if $(FLAVOUR),/$(FLAVOUR)))
5 kx endif
5 kx endif
5 kx
5 kx # TOOLCHAIN/FLAVOUR depended directories
5 kx
5 kx ifneq ($(TOOLCHAIN),$(TOOLCHAIN_NOARCH))
5 kx ifeq ($(shell pwd),$(BUILDSYSTEM))
5 kx targetflavour = .$(TOOLCHAIN)
5 kx else
5 kx targetflavour = .$(TOOLCHAIN)$(if $(FLAVOUR),/$(FLAVOUR))
5 kx endif
5 kx else
5 kx targetflavour = $(CURDIR)
5 kx endif
5 kx
5 kx TARGET_BUILD_DIR = $(targetflavour)
5 kx
5 kx
5 kx
5 kx ifeq ($(BUILD_TREE),true)
5 kx _tree := .tree_all
5 kx else
5 kx _tree := .requires_tree
5 kx endif
5 kx
5 kx
5 kx local_all: $(_tree) install
5 kx
5 kx local_clean:
5 kx
5 kx
5 kx .tree_all: $(TARGET_BUILD_DIR)/.requires
5 kx ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
5 kx ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
5 kx @echo -e "################################################################"
5 kx @echo -e "#######"
5 kx ifeq ($(shell pwd),$(BUILDSYSTEM))
5 kx @echo -e "####### Start of building requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))':"
5 kx else
5 kx @echo -e "####### Start of building requires for TOOLCHAIN=$(TOOLCHAIN) FLAVOUR=$(FLAVOUR) in '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))':"
5 kx endif
5 kx @echo -e "#######"
5 kx ifeq ($(shell pwd),$(BUILDSYSTEM))
5 kx @__final__=true TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN_HOST) FLAVOUR= -f $(TARGET_BUILD_DIR)/.requires
5 kx else
5 kx @__final__=true TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN) FLAVOUR= -f $(TARGET_BUILD_DIR)/.requires
5 kx endif
5 kx @echo -e "#######"
5 kx @echo -e "####### End of building requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))'."
5 kx @echo -e "#######"
5 kx @echo -e "################################################################"
5 kx endif
5 kx endif
5 kx
5 kx
5 kx .requires_tree: $(TARGET_BUILD_DIR)/.requires
5 kx
5 kx #######
5 kx ####### Build directory dependencies into $(TARGET_BUILD_DIR)/.requires
5 kx ####### file which is used as a Makefile for tree builds.
5 kx #######
5 kx
5 kx $(TARGET_BUILD_DIR)/.requires_depend: $(TARGET_BUILD_DIR)/.requires ;
5 kx
5 kx $(TARGET_BUILD_DIR)/.requires: .makefile
5 kx ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
5 kx ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
5 kx ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
5 kx ifeq ($(shell pwd),$(BUILDSYSTEM))
5 kx @$(BUILDSYSTEM)/build_requires $(TOP_BUILD_DIR_ABS) $(TOOLCHAIN_HOST) ; wait
5 kx else
5 kx @$(BUILDSYSTEM)/build_requires $(TOP_BUILD_DIR_ABS) $(TOOLCHAIN) $(FLAVOUR) ; wait
5 kx endif
5 kx endif
5 kx endif
5 kx endif
5 kx
5 kx
5 kx
5 kx
5 kx ################################################################
5 kx #######
5 kx ####### Waiting for build whole required tree:
5 kx #######
5 kx
5 kx $(BUILD_TARGETS): | $(_tree)
5 kx
5 kx #######
5 kx ####### End of waiting for build whole required tree.
5 kx #######
5 kx ################################################################
5 kx
5 kx $(PRODUCT_TARGETS) : | $(BUILD_TARGETS)
5 kx
5 kx
5 kx #######
5 kx ####### Install:
5 kx #######
5 kx
5 kx install: .install
5 kx @if [ "$$(echo .dist*)" != ".dist*" ]; then \
5 kx sort -o .dist.tmp -u .dist* && mv .dist.tmp .dist; \
5 kx fi
5 kx @rm -f .dist.*
5 kx
5 kx
5 kx .install: .install_builds .install_products
5 kx
5 kx
5 kx
5 kx
5 kx .install_builds: $(BUILD_TARGETS)
5 kx # Do nothing
5 kx
5 kx .install_products: DO_CREATE_DIST_FILES = $(CREATE_DIST_FILES)
5 kx export DO_CREATE_DIST_FILES
5 kx
5 kx .install_products: $(PRODUCT_TARGETS)
5 kx ifdef PRODUCT_TARGETS
5 kx @$(BUILDSYSTEM)/install_targets $^ $(PREFIX)/products
5 kx endif
5 kx
5 kx
5 kx
5 kx
5 kx #######
5 kx ####### Clean up default rules:
5 kx #######
5 kx
5 kx clean: local_clean
5 kx
5 kx local_clean: .local_clean
5 kx
5 kx .local_clean:
5 kx ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
5 kx ifneq ($(wildcard .$(TOOLCHAIN)),)
5 kx @echo "Cleaning... $(TOOLCHAIN)"
5 kx @rm -rf $(CLEANUP_FILES)
5 kx endif
5 kx endif
5 kx
5 kx
5 kx -include .src_requires_depend
5 kx -include $(TARGET_BUILD_DIR)/.requires_depend
5 kx
5 kx
5 kx endif
5 kx #
5 kx # end of ifeq ($(__final__),)
5 kx #
5 kx ################################################################
5 kx
5 kx ### Declare some targets as phony
5 kx
5 kx .PHONY: .target*
5 kx .PHONY: .setup .sources .build_system .gnat_tools
5 kx
5 kx .PHONY: .tree_all .requites_tree
5 kx
5 kx .PHONY: all local_all .clean local_clean clean
5 kx .PHONY: .install
5 kx
5 kx .PHONY: help
5 kx .PHONY: downloads_clean
5 kx .PHONY: .downloads_clean
5 kx
5 kx .SUFFIXES:
5 kx
5 kx
5 kx
5 kx CORE_MK = 1
5 kx endif