# Copyright (c) 2015 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Copyright (c) 2007-2008 Eliot Dresselhaus # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ###################################################################### # Collect makefile fragments ###################################################################### # Scripts require non-POSIX parts of bash SHELL := /bin/bash # Where this makefile lives MU_BUILD_ROOT_DIR = $(shell pwd) MU_BUILD_NAME = $(shell basename $(MU_BUILD_ROOT_DIR)) # Search path (e.g. multiple directories) where sources are found. SOURCE_PATH = # Pick up user's definitions for variables e.g. SOURCE_PATH, etc. -include build-config.mk MU_BUILD_ROOT_NAME = $(shell basename $(MU_BUILD_ROOT_DIR)) MU_BUILD_DATA_DIR_NAME = build-data ABSOLUTE_SOURCE_PATH = $(foreach d,$(SOURCE_PATH),$(shell cd $(d) && pwd)) SOURCE_PATH_BUILD_ROOT_DIRS = $(addsuffix /$(MU_BUILD_NAME),$(ABSOLUTE_SOURCE_PATH)) SOURCE_PATH_BUILD_DATA_DIRS = $(addsuffix /$(MU_BUILD_DATA_DIR_NAME),$(ABSOLUTE_SOURCE_PATH)) # For tools use build-root as source path, otherwise use given source path FIND_SOURCE_PATH = \ $(if $(is_build_tool), \ $(SOURCE_PATH_BUILD_ROOT_DIRS) $(MU_BUILD_ROOT_DIR), \ $(SOURCE_PATH_BUILD_DATA_DIRS)) # First search given source path, then default to build-root FULL_SOURCE_PATH = $(SOURCE_PATH_BUILD_DATA_DIRS) $(MU_BUILD_ROOT_DIR) # Misc functions is_in_fn = $(strip $(filter $(1),$(2))) last_fn = $(lastword $1) chop_fn = $(wordlist 2,$(words $1),x $1) uniq_fn = $(strip $(if $1,$(call uniq_fn,$(call chop_fn,$1)) \ $(if $(filter $(call last_fn,$1),$(call chop_fn,$1)),,$(call last_fn,$1)))) ifdef3_fn = $(if $(patsubst undefined,,$(origin $(1))),$(3),$(2)) ifdef_fn = $(call ifdef3_fn,$(1),$(2),$($(1))) _mu_debug = $(warning "$(1) = $($(1))") $(foreach d,$(FIND_SOURCE_PATH), \ $(eval _mu_package_mk_in_$(d) = $(shell find $(d)/packages/*.mk 2> /dev/null)) \ $(eval _mu_srcdirs_in_$(d) = \ $(shell find $(d)/.. \ -maxdepth 1 \ -type d \ -and -not -name ".." \ -and -not -name $(MU_BUILD_ROOT_NAME) \ -and -not -name $(MU_BUILD_DATA_DIR_NAME))) \ $(eval _mu_non_package_files_in_$(d) = \ $(shell find $(d)/packages \ -type f \ -and -not -name '*.mk' \ -and -not -name '*~' 2> /dev/null)) \ $(foreach p,$(patsubst %.mk,%,$(notdir $(_mu_package_mk_in_$(d)))), \ $(eval _mu_package_dir_$(p) = $(d)) \ $(eval _mu_package_mk_$(p) = $(d)/packages/$(p).mk) \ ) \ $(foreach p,$(notdir $(_mu_srcdirs_in_$(d))), \ $(eval _mu_package_srcdir_$(p) = $(shell cd $(d)/../$(p) && pwd)) \ ) \ ) # Find root directory for package based on presence of package .mk # makefile fragment on source path. _find_build_data_dir_for_package_fn = $(shell \ set -eu$(BUILD_DEBUG) ; \ for d in $(FIND_SOURCE_PATH) ; do \ f="$${d}/packages/$(1).mk" ; \ [[ -f $${f} ]] && echo `cd $${d} && pwd` && exit 0 ; \ done ; \ echo "") find_build_data_dir_for_package_fn = $(call ifdef_fn,_mu_package_dir_$(1),) # dir/PACKAGE _find_source_fn = $(shell \ set -eu$(BUILD_DEBUG) ; \ d="$(call find_build_data_dir_for_package_fn,$(1))" ; \ [[ -n "$${d}" ]] && d="$${d}/../$(1)" ; \ echo "$${d}") find_source_fn = $(call ifdef3_fn,_mu_package_dir_$(1),,$(_mu_package_dir_$(1))/../$(1)) # Find given FILE in source path as build-data/packages/FILE find_package_file_fn = $(shell \ set -eu$(BUILD_DEBUG) ; \ d="$(call find_build_data_dir_for_package_fn,$(1))" ; \ [[ -n "$${d}" ]] && d="$${d}/packages/$(2)" ; \ [[ -f "$${d}" ]] && echo "$${d}") # Find first FILE in source path with name PATH/build-data/FILE find_build_data_file_fn = $(shell \ set -eu$(BUILD_DEBUG) ; \ for d in $(FIND_SOURCE_PATH) ; do \ f="$${d}/$(1)" ; \ [[ -f $${f} ]] && echo `cd $${d} && pwd`/$(1) && exit 0 ; \ done ; \ echo "") ###################################################################### # ARCH, PLATFORM ###################################################################### NATIVE_ARCH = $(shell gcc -dumpmachine | sed -e 's/\([a-zA-Z_0-9]*\)-.*/\1/') # Find all platforms.mk that we can, including those from build-root $(foreach d,$(FULL_SOURCE_PATH), \ $(eval -include $(d)/platforms.mk)) # Platform should be defined somewhere by specifying $($(PLATFORM)_arch) ARCH = $(strip $($(PLATFORM)_arch)) ifeq ($(ARCH),) $(error "Unknown platform `$(PLATFORM)'") endif # map e.g. ppc7450 -> ppc BASIC_ARCH = \ ${shell case '$(ARCH)' in \ (native) echo $(NATIVE_ARCH) ;; \ (i*86*) echo i386 ;; \ (ppc*|powerpc*) echo ppc ;; \ (*) echo '$(ARCH)' ;; \ esac } # x86_64 can be either 32/64. set BIACH=32 to get 32 bit libraries. BIARCH = 64 aarch64_libdir = 64 x86_64_libdir = $(BIARCH) native_libdir = $($(NATIVE_ARCH)_libdir) # lib or lib64 depending arch_lib_dir = lib$($(BASIC_ARCH)_libdir) # OS to configure for. configure --host will be set to $(ARCH)-$(OS) # Allow per-platform overrides OS = $(strip $($(PLATFORM)_os)) ifeq ($(OS),) OS = mu-linux endif spu_target = spu native_target = is_native = $(if $(ARCH:native=),,true) not_native = $(if $(ARCH:native=),true,) ARCH_TARGET_tmp = $(call ifdef_fn,$(ARCH)_target,$(ARCH)-$(OS)) TARGET = $(call ifdef_fn,$(PLATFORM)_target,$(ARCH_TARGET_tmp)) TARGET_PREFIX = $(if $(not_native),$(TARGET)-,) # CPU microarchitecture detection. # Either set _march in build-data/platforms/.mk, # or detect and use the build-host instruction set MARCH = $(strip $($(PLATFORM)_march)) ifeq ($(MARCH),) ifneq ($(wildcard $(TOOL_INSTALL_DIR)/bin/$(TARGET)-gcc),) TARGET_GCC = $(TOOL_INSTALL_DIR)/bin/$(TARGET)-gcc else ifneq ($(wildcard $(MU_BUILD_ROOT_DIR)/tools/bin/$(TARGET)-gcc),) TARGET_GCC = $(MU_BUILD_ROOT_DIR)/tools/bin/$(TARGET)-gcc endif ifneq ($(TARGET_GCC),) MARCH = $(shell $(TARGET_GCC) -Q --help=target -march=native | grep march | sed -e 's/.*march=[[:space:]]*//') else MARCH = native endif else ifeq ($(MARCH),nehalem) override MARCH = corei7 else ifeq ($(MARCH),westmere) override MARCH = corei7 else ifeq ($(MARCH),sandybridge) override MARCH = corei7-avx else ifeq ($(MARCH),ivybridge) override MARCH = core-avx-i else ifeq ($(MARCH),haswell) override MARCH = core-avx2 endif endif export MARCH MTUNE = $(strip $($(PLATFORM)_mtune)) ifeq ($(MTUNE),) MTUNE = generic endif ###################################################################### # Generic build stuff ###################################################################### # The package we are currently working on PACKAGE = $* # Build/install tags. This lets you have different CFLAGS/CPPFLAGS/LDFLAGS # for e.g. debug versus optimized compiles. Each tag has its own set of build/install # areas. TAG = TAG_PREFIX = $(if $(TAG),$(TAG)-) # yes you need the space tag_var_with_added_space_fn = $(if $($(TAG)_TAG_$(1)),$($(TAG)_TAG_$(1)) ) # TAG=debug for debugging debug_TAG_CFLAGS = -g -O0 -DCLIB_DEBUG -DFORTIFY_SOURCE=2 -march=$(MARCH) \ -fstack-protector-all -fPIC debug_TAG_CXXFLAGS = -g -O0 -DCLIB_DEBUG -DFORTIFY_SOURCE=2 -march=$(MARCH) \ -fstack-protector-all -fPIC debug_TAG_LDFLAGS = -g -O0 -DCLIB_DEBUG -DFORTIFY_SOURCE=2 -march=$(MARCH) \ -fstack-protector-all -fPIC BUILD_PREFIX_package = build-$(TAG_PREFIX) BUILD_PREFIX_tool = build-tool-$(TAG_PREFIX) INSTALL_PREFIX = install-$(TAG_PREFIX) IMAGES_PREFIX = images-$(TAG_PREFIX) # Whether we are building a tool or not tool_or_package_fn = $(if $(is_build_tool),tool,package) # Directory where packages are built & installed BUILD_DIR = $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_$(call tool_or_package_fn))$(ARCH) INSTALL_DIR = $(MU_BUILD_ROOT_DIR)/$(INSTALL_PREFIX)$(ARCH) PLATFORM_IMAGE_DIR = $(MU_BUILD_ROOT_DIR)/$(IMAGES_PREFIX)$(PLATFORM) # $(call VAR,DEFAULT) override_var_with_default_fn = $(if $($(1)),$($(1)),$(2)) # $(call if_directory_exists_fn,D1,D2) returns D1 if it exists else D2 define if_directory_exists_fn $(shell if test -d $(1); then echo $(1); else echo $(2); fi) endef # $(call if_file_exists_fn,F1,F2) returns F1 if it exists else F2 define if_file_exists_fn $(shell if test -f $(1); then echo $(1); else echo $(2); fi) endef # Default VAR, package specified override of default PACKAGE_VAR package_var_fn = $(call override_var_with_default_fn,$(1)_$(2),$(1)) package_build_dir_fn = $(call package_var_fn,$(1),build_dir) package_install_dir_fn = \ $(if $(is_build_tool),$(TOOL_INSTALL_DIR),$(INSTALL_DIR)/$(call package_build_dir_fn,$(1))) PACKAGE_BUILD_DIR = \ $(BUILD_DIR)/$(call package_build_dir_fn,$(PACKAGE)) PACKAGE_INSTALL_DIR = \ $(call package_install_dir_fn,$(PACKAGE)) # Tools (gcc, binutils, glibc...) are installed here TOOL_INSTALL_DIR = $(MU_BUILD_ROOT_DIR)/tools # Target specific tools go here e.g. mu-build/tools/ppc-mu-linux TARGET_TOOL_INSTALL_DIR = $(TOOL_INSTALL_DIR)/$(TARGET) # Set BUILD_DEBUG to vx or x enable shell command tracing. BUILD_DEBUG = # Message from build system itself (as opposed to make or shell commands) build_msg_fn = echo "@@@@ $(1) @@@@" # Allow CCACHE_DIR to be overridden, e.g. in .../build-root/build-config.mk ifeq ($(CCACHE_DIR),) CCACHE_DIR=$(MU_BUILD_ROOT_DIR)/.ccache endif # Always prefer our own tools to those installed on system. # Note: ccache-bin must be before tool bin. # # Removed LD_LIBRARY_PATH from BUILD_ENV (drb, 10/31/17): # export LD_LIBRARY_PATH=$(TOOL_INSTALL_DIR)/lib64:$(TOOL_INSTALL_DIR)/lib # Reported to cause trouble. Only of historical interest, since we no longer # build a full tool chain from source. BUILD_ENV = \ export CCACHE_DIR=$(CCACHE_DIR) ; \
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
  Copyright (c) 2001, 2002, 2003 Eliot Dresselhaus

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef included_clib_vec_bootstrap_h
#define included_clib_vec_bootstrap_h

/** \file
    Vector bootstrap header file
*/

/* Bootstrap include so that #include <vppinfra/mem.h> can include e.g.
   <vppinfra/mheap.h> which depends on <vppinfra/vec.h>. */

/** \brief vector header structure

   Bookkeeping header preceding vector elements in memory.
   User header information may preceed standard vec header.
   If you change u32 len -> u64 len, single vectors can
   exceed 2**32 elements. Clib heaps are vectors. */

typedef struct
{
#if CLIB_VEC64 > 0
  u64 len;
#else
  u32 len; /**< Number of elements in vector (NOT its allocated length). */
  u32 dlmalloc_header_offset;	/**< offset to memory allocator offset  */
#endif
  u8 vector_data[0];  /**< Vector data . */
} vec_header_t;

/** \brief Find the vector header

    Given the user's pointer to a vector, find the corresponding
    vector header

    @param v pointer to a vector
    @return pointer to the vector's vector_header_t
*/
#define _vec_find(v)	((vec_header_t *) (v) - 1)

#define _vec_round_size(s) \
  (((s) + sizeof (uword) - 1) &~ (sizeof (uword) - 1))

always_inline uword
vec_header_bytes (uword header_bytes)
{
  return round_pow2 (header_bytes + sizeof (vec_header_t),
		     sizeof (vec_header_t));
}

/** \brief Find a user vector header

    Finds the user header of a vector with unspecified alignment given
    the user pointer to the vector.
*/

always_inline void *
vec_header (void *v, uword header_bytes)
{
  return v - vec_header_bytes (header_bytes);
}

/** \brief Find the end of user vector header

    Finds the end of the user header of a vector with unspecified
    alignment given the user pointer to the vector.
*/

always_inline void *
vec_header_end (void *v, uword header_bytes)
{
  return v + vec_header_bytes (header_bytes);
}

always_inline uword
vec_aligned_header_bytes (uword header_bytes, uword align)
{
  return round_pow2 (header_bytes + sizeof (vec_header_t), align);
}

always_inline void *
vec_aligned_header (void *v, uword header_bytes, uword align)
{
  return v - vec_aligned_header_bytes (header_bytes, align);
}

always_inline void *
vec_aligned_header_end (void *v, uword header_bytes, uword align)
{
  return v + vec_aligned_header_bytes (header_bytes, align);
}


/** \brief Number of elements in vector (lvalue-capable)

   _vec_len (v) does not check for null, but can be used as a lvalue
   (e.g. _vec_len (v) = 99).
*/

#define _vec_len(v)	(_vec_find(v)->len)

/** \brief Number of elements in vector (rvalue-only, NULL tolerant)

    vec_len (v) checks for NULL, but cannot be used as an lvalue.
    If in doubt, use vec_len...
*/

#define vec_len(v)	((v) ? _vec_len(v) : 0)

/** \brief Reset vector length to zero
    NULL-pointer tolerant
*/

#define vec_reset_length(v) do { if (v) _vec_len (v) = 0; } while (0)

/** \brief Number of data bytes in vector. */

#define vec_bytes(v) (vec_len (v) * sizeof (v[0]))

/** \brief Total number of bytes that can fit in vector with current allocation. */

#define vec_capacity(v,b)							\
({										\
  void * _vec_capacity_v = (void *) (v);					\
  uword _vec_capacity_b = (b);							\
  _vec_capacity_b = sizeof (vec_header_t) + _vec_round_size (_vec_capacity_b);	\
  _vec_capacity_v ? clib_mem_size (_vec_capacity_v - _vec_capacity_b) : 0;	\
})

/** \brief Total number of elements that can fit into vector. */
#define vec_max_len(v) (vec_capacity(v,0) / sizeof (v[0]))

/** \brief End (last data address) of vector. */
#define vec_end(v)	((v) + vec_len (v))

/** \brief True if given pointer is within given vector. */
#define vec_is_member(v,e) ((e) >= (v) && (e) < vec_end (v))

/** \brief Get vector value at index i checking that i is in bounds. */
#define vec_elt_at_index(v,i)			\
({						\
  ASSERT ((i) < vec_len (v));			\
  (v) + (i);					\
})

/** \brief Get vector value at index i */
#define vec_elt(v,i) (vec_elt_at_index(v,i))[0]

/** \brief Vector iterator */
#define vec_foreach(var,vec) for (var = (vec); var < vec_end (vec); var++)

/** \brief Vector iterator (reverse) */
#define vec_foreach_backwards(var,vec) \
for (var = vec_end (vec) - 1; var >= (vec); var--)

/** \brief Iterate over vector indices. */
#define vec_foreach_index(var,v) for ((var) = 0; (var) < vec_len (v); (var)++)

/** \brief Iterate over vector indices (reverse). */
#define vec_foreach_index_backwards(var,v) \
  for ((var) = vec_len((v)) - 1; (var) >= 0; (var)--)

#endif /* included_clib_vec_bootstrap_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
basic_system \ $(ROOT_PACKAGES)) || exit 1; \ $(call build_msg_fn, Relocating ELF executables to run in $${d}) ; \ scripts/set-rpath $${d} $${d}/$(arch_lib_dir) ; \ : strip symbols from files ; \ if [ $${strip_symbols:-no} = 'yes' ] ; then \ $(call build_msg_fn, Stripping symbols from files) ; \ find $${d} -type f \ -exec \ $(TARGET_PREFIX)strip \ --strip-unneeded '{}' ';' \ >& /dev/null ; \ else \ $(call build_msg_fn, NOT stripping symbols) ; \ fi # readonly root squashfs image # Note: $(call build_msg_fn) does not seem to work inside of fakeroot so we use echo .PHONY: ro-image $(PLATFORM_IMAGE_DIR)/ro.img ro-image: $(patsubst %,%-find-source,$(ROOT_PACKAGES)) @$(BUILD_ENV) ; \ d=$(PLATFORM_IMAGE_DIR) ; \ mkdir -p $$d; \ ro_image=$$d/ro.img ; \ rm -f $${ro_image} ; \ tmp_dir="`mktemp -d $$d/ro-image-XXXXXX`" ; \ chmod 0755 $${tmp_dir} ; \ cd $${tmp_dir} ; \ trap "rm -rf $${tmp_dir}" err ; \ fakeroot /bin/bash -c "{ \ set -eu$(BUILD_DEBUG) ; \ $(MAKE) -C $(MU_BUILD_ROOT_DIR) IMAGE_INSTALL_DIR=$${tmp_dir} \ $(patsubst %,%-image_install, \ basic_system \ $(ROOT_PACKAGES)) ; \ : make dev directory ; \ $(linuxrc_makedev) ; \ echo @@@@ Relocating ELF executables to run in / @@@@ ; \ scripts/set-rpath /$(arch_lib_dir):/lib ; \ : strip symbols from files ; \ if [ '$${strip_symbols:-yes}' = 'yes' ] ; then \ echo @@@@ Stripping symbols from files @@@@ ; \ find $${tmp_dir} -type f \ -exec \ $(TARGET_PREFIX)strip \ --strip-unneeded '{}' ';' \ >& /dev/null ; \ else \ echo @@@@ NOT stripping symbols @@@@ ; \ fi ; \ if [ $${sign_executables:-yes} = 'yes' \ -a -n "$($(PLATFORM)_public_key)" ] ; then \ echo @@@@ Signing executables @@@@ ; \ find $${tmp_dir} -type f \ | xargs sign $($(PLATFORM)_public_key) \ $($(PLATFORM)_private_key_passphrase) ; \ fi ; \ : make read-only file system ; \ mksquashfs \ $${tmp_dir} $${ro_image} \ -no-exports -no-progress -no-recovery ; \ }" ; \ : cleanup tmp directory ; \ rm -rf $${tmp_dir} MKFS_JFFS2_BYTE_ORDER_x86_64 = -l MKFS_JFFS2_BYTE_ORDER_i686 = -l MKFS_JFFS2_BYTE_ORDER_ppc = -b MKFS_JFFS2_BYTE_ORDER_mips = -b MKFS_JFFS2_BYTE_ORDER_native = $(MKFS_JFFS2_BYTE_ORDER_$(NATIVE_ARCH)) MKFS_JFFS2_SECTOR_SIZE_IN_KBYTES = \ $(call ifdef_fn,$(PLATFORM)_jffs2_sector_size_in_kbytes,256) mkfs_fn_jffs2 = mkfs.jffs2 \ --eraseblock=$(MKFS_JFFS2_SECTOR_SIZE_IN_KBYTES)KiB \ --root=$(1) --output=$(2) \ $(MKFS_JFFS2_BYTE_ORDER_$(BASIC_ARCH)) # As things stand the actual initrd size parameter # is set in .../open-repo/build-data/packages/linuxrc.mk. EXT2_RW_IMAGE_SIZE=notused mkfs_fn_ext2 = \ e2fsimage -d $(1) -f $(2) -s $(EXT2_RW_IMAGE_SIZE) RW_IMAGE_TYPE=jffs2 make_rw_image_fn = \ $(call mkfs_fn_$(RW_IMAGE_TYPE),$(1),$(2)) rw_image_embed_ro_image_fn = \ mkdir -p proc initrd images ro rw union ; \ cp $(PLATFORM_IMAGE_DIR)/$(1) images/$(1) ; \ md5sum images/$(1) > images/$(1).md5 ; \ echo Built by $(LOGNAME) at `date` > images/$(1).stamp ; \ mkdir -p changes/$(1) # make sure RW_IMAGE_TYPE is a type we know how to build .PHONY: rw-image-check-type rw-image-check-type: @$(BUILD_ENV) ; \ if [ -z "$(make_rw_image_fn)" ] ; then \ $(call build_msg_fn,Unknown read/write fs image type; \ try RW_IMAGE_TYPE=ext2 or RW_IMAGE_TYPE=jffs2) ; \ exit 1; \ fi # read write image .PHONY: rw-image rw-image: rw-image-check-type ro-image @$(BUILD_ENV) ; \ d=$(PLATFORM_IMAGE_DIR) ; \ mkdir -p $$d ; \ rw_image="$$d/rw.$(RW_IMAGE_TYPE)" ; \ ro_image="ro.img" ; \ rm -f $$rw_image ; \ tmp_dir="`mktemp -d $$d/rw-image-XXXXXX`" ; \ chmod 0755 $${tmp_dir} ; \ cd $${tmp_dir} ; \ trap "rm -rf $${tmp_dir}" err ; \ fakeroot /bin/bash -c "{ \ set -eu$(BUILD_DEBUG) ; \ $(linuxrc_makedev) ; \ $(call rw_image_embed_ro_image_fn,$${ro_image}) ; \ $(call make_rw_image_fn,$${tmp_dir},$${rw_image}) ; \ }" ; \ : cleanup tmp directory ; \ rm -rf $${tmp_dir} images: linuxrc-install linux-install $(image_extra_dependencies) rw-image @$(BUILD_ENV) ; \ d=$(PLATFORM_IMAGE_DIR) ; \ cd $(BUILD_DIR)/linux-$(PLATFORM) ; \ i="" ; \ [[ -z $$i && -f bzImage ]] && i=bzImage ; \ [[ -z $$i && -f zImage ]] && i=zImage ; \ [[ -z $$i && -f linux ]] && i=linux ; \ [[ -z $$i && -f vmlinux ]] && i=vmlinux ; \ [[ -z $$i ]] \ && $(call build_msg_fn,no linux image to install \ in $(BUILD_DIR)/linux-$(PLATFORM)) \ && exit 1 ; \ cp $$i $$d ###################################################################### # Tool chain build/install ###################################################################### .PHONY: ccache-install ccache-install: $(MAKE) -C $(MU_BUILD_ROOT_DIR) ccache-build mkdir -p $(TOOL_INSTALL_DIR)/ccache-bin ln -sf $(MU_BUILD_ROOT_DIR)/build-tool-native/ccache/ccache \ $(TOOL_INSTALL_DIR)/ccache-bin/$(TARGET_PREFIX)gcc TOOL_MAKE = $(MAKE) is_build_tool=yes tool_make_target_fn = \ $(if $(strip $(NATIVE_TOOLS)), \ $(TOOL_MAKE) $(patsubst %,%-$(1),$(NATIVE_TOOLS)) ARCH=native || exit 1 ;) \ $(TOOL_MAKE) $(patsubst %,%-$(1),$(CROSS_TOOLS)) .PHONY: install-tools install-tools: $(call tool_make_target_fn,install) .PHONY: bootstrap-tools bootstrap-tools: $(TOOL_MAKE) make-install findutils-install git-install \ automake-install autoconf-install libtool-install fakeroot-install ###################################################################### # Clean ###################################################################### package_clean_script = \ @$(call build_msg_fn, Cleaning $* in $(PACKAGE_INSTALL_DIR)) ; \ $(BUILD_ENV) ; \ $(if $(is_build_tool),,rm -rf $(PACKAGE_INSTALL_DIR) ;) \ rm -rf $(TIMESTAMP_DIR)/$(call timestamp_name_fn,*) ; \ $(if $($(PACKAGE)_clean), \ $($(PACKAGE)_clean), \ $(PACKAGE_MAKE) clean) .PHONY: %-clean %-clean: $(package_clean_script) # Wipe e.g. remove build and install directories for packages. package_wipe_script = \ @message=$(if $(is_build_tool),"Wiping build $(PACKAGE)","Wiping build/install $(PACKAGE)") ; \ $(call build_msg_fn,$$message) ; \ $(BUILD_ENV) ; \ rm -rf $(if $(is_build_tool),$(PACKAGE_BUILD_DIR),$(PACKAGE_INSTALL_DIR) $(PACKAGE_BUILD_DIR)) .PHONY: %-wipe %-wipe: $(package_wipe_script) # Wipe entire build/install area for TAG and PLATFORM .PHONY: wipe-all wipe-all: @$(call build_msg_fn, Wiping $(BUILD_DIR) $(INSTALL_DIR)) ; \ $(BUILD_ENV) ; \ rm -rf $(BUILD_DIR) $(INSTALL_DIR) # Clean everything distclean: rm -rf $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_package)*/ rm -rf $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_tool)* rm -rf $(MU_BUILD_ROOT_DIR)/$(INSTALL_PREFIX)* rm -rf $(MU_BUILD_ROOT_DIR)/$(IMAGES_PREFIX)* rm -rf $(TOOL_INSTALL_DIR) rm -rf $(MU_BUILD_ROOT_DIR)/*.deb rm -rf $(MU_BUILD_ROOT_DIR)/*.rpm rm -rf $(MU_BUILD_ROOT_DIR)/*.changes rm -rf $(MU_BUILD_ROOT_DIR)/*.buildinfo