blob: d35b7a10aeb9f48a807b5b599be611ed1f886d45 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001# Copyright (c) 2015 Cisco and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14#
15# Copyright (c) 2007-2008 Eliot Dresselhaus
16#
17# Permission is hereby granted, free of charge, to any person obtaining
18# a copy of this software and associated documentation files (the
19# "Software"), to deal in the Software without restriction, including
20# without limitation the rights to use, copy, modify, merge, publish,
21# distribute, sublicense, and/or sell copies of the Software, and to
22# permit persons to whom the Software is furnished to do so, subject to
23# the following conditions:
24#
25# The above copyright notice and this permission notice shall be
26# included in all copies or substantial portions of the Software.
27#
28# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35#
36
37######################################################################
38# Collect makefile fragments
39######################################################################
40
41# Scripts require non-POSIX parts of bash
42SHELL := /bin/bash
43
44# Where this makefile lives
45MU_BUILD_ROOT_DIR = $(shell pwd)
46MU_BUILD_NAME = $(shell basename $(MU_BUILD_ROOT_DIR))
47
48# Search path (e.g. multiple directories) where sources are found.
49SOURCE_PATH =
50
51# Pick up user's definitions for variables e.g. SOURCE_PATH, etc.
52-include build-config.mk
53
54MU_BUILD_ROOT_NAME = $(shell basename $(MU_BUILD_ROOT_DIR))
55MU_BUILD_DATA_DIR_NAME = build-data
56
57ABSOLUTE_SOURCE_PATH = $(foreach d,$(SOURCE_PATH),$(shell cd $(d) && pwd))
58
59SOURCE_PATH_BUILD_ROOT_DIRS = $(addsuffix /$(MU_BUILD_NAME),$(ABSOLUTE_SOURCE_PATH))
60SOURCE_PATH_BUILD_DATA_DIRS = $(addsuffix /$(MU_BUILD_DATA_DIR_NAME),$(ABSOLUTE_SOURCE_PATH))
61
62# For tools use build-root as source path, otherwise use given source path
63FIND_SOURCE_PATH = \
64 $(if $(is_build_tool), \
65 $(SOURCE_PATH_BUILD_ROOT_DIRS) $(MU_BUILD_ROOT_DIR), \
66 $(SOURCE_PATH_BUILD_DATA_DIRS))
67
68# First search given source path, then default to build-root
69FULL_SOURCE_PATH = $(SOURCE_PATH_BUILD_DATA_DIRS) $(MU_BUILD_ROOT_DIR)
70
71# Misc functions
72is_in_fn = $(strip $(filter $(1),$(2)))
73last_fn = $(lastword $1)
74chop_fn = $(wordlist 2,$(words $1),x $1)
75uniq_fn = $(strip $(if $1,$(call uniq_fn,$(call chop_fn,$1)) \
76 $(if $(filter $(call last_fn,$1),$(call chop_fn,$1)),,$(call last_fn,$1))))
77ifdef3_fn = $(if $(patsubst undefined,,$(origin $(1))),$(3),$(2))
78ifdef_fn = $(call ifdef3_fn,$(1),$(2),$($(1)))
79
80_mu_debug = $(warning "$(1) = $($(1))")
81
82$(foreach d,$(FIND_SOURCE_PATH), \
83 $(eval _mu_package_mk_in_$(d) = $(shell find $(d)/packages/*.mk 2> /dev/null)) \
84 $(eval _mu_srcdirs_in_$(d) = \
85 $(shell find $(d)/.. \
86 -maxdepth 1 \
87 -type d \
88 -and -not -name ".." \
89 -and -not -name $(MU_BUILD_ROOT_NAME) \
90 -and -not -name $(MU_BUILD_DATA_DIR_NAME))) \
91 $(eval _mu_non_package_files_in_$(d) = \
92 $(shell find $(d)/packages \
93 -type f \
94 -and -not -name '*.mk' \
95 -and -not -name '*~' 2> /dev/null)) \
96 $(foreach p,$(patsubst %.mk,%,$(notdir $(_mu_package_mk_in_$(d)))), \
97 $(eval _mu_package_dir_$(p) = $(d)) \
98 $(eval _mu_package_mk_$(p) = $(d)/packages/$(p).mk) \
99 ) \
100 $(foreach p,$(notdir $(_mu_srcdirs_in_$(d))), \
101 $(eval _mu_package_srcdir_$(p) = $(shell cd $(d)/../$(p) && pwd)) \
102 ) \
103)
104
105# Find root directory for package based on presence of package .mk
106# makefile fragment on source path.
107_find_build_data_dir_for_package_fn = $(shell \
108 set -eu$(BUILD_DEBUG) ; \
109 for d in $(FIND_SOURCE_PATH) ; do \
110 f="$${d}/packages/$(1).mk" ; \
111 [[ -f $${f} ]] && echo `cd $${d} && pwd` && exit 0 ; \
112 done ; \
113 echo "")
114find_build_data_dir_for_package_fn = $(call ifdef_fn,_mu_package_dir_$(1),)
115
116# dir/PACKAGE
117_find_source_fn = $(shell \
118 set -eu$(BUILD_DEBUG) ; \
119 d="$(call find_build_data_dir_for_package_fn,$(1))" ; \
120 [[ -n "$${d}" ]] && d="$${d}/../$(1)" ; \
121 echo "$${d}")
122find_source_fn = $(call ifdef3_fn,_mu_package_dir_$(1),,$(_mu_package_dir_$(1))/../$(1))
123
124# Find given FILE in source path as build-data/packages/FILE
125find_package_file_fn = $(shell \
126 set -eu$(BUILD_DEBUG) ; \
127 d="$(call find_build_data_dir_for_package_fn,$(1))" ; \
128 [[ -n "$${d}" ]] && d="$${d}/packages/$(2)" ; \
129 [[ -f "$${d}" ]] && echo "$${d}")
130
131# Find first FILE in source path with name PATH/build-data/FILE
132find_build_data_file_fn = $(shell \
133 set -eu$(BUILD_DEBUG) ; \
134 for d in $(FIND_SOURCE_PATH) ; do \
135 f="$${d}/$(1)" ; \
136 [[ -f $${f} ]] && echo `cd $${d} && pwd`/$(1) && exit 0 ; \
137 done ; \
138 echo "")
139
140######################################################################
141# ARCH, PLATFORM
142######################################################################
143
144NATIVE_ARCH = $(shell gcc -dumpmachine | sed -e 's/\([a-zA-Z_0-9]*\)-.*/\1/')
145
146# Find all platforms.mk that we can, including those from build-root
147$(foreach d,$(FULL_SOURCE_PATH), \
148 $(eval -include $(d)/platforms.mk))
149
150# Platform should be defined somewhere by specifying $($(PLATFORM)_arch)
151ARCH = $(strip $($(PLATFORM)_arch))
152ifeq ($(ARCH),)
153 $(error "Unknown platform `$(PLATFORM)'")
154endif
155
156# map e.g. ppc7450 -> ppc
157BASIC_ARCH = \
158 ${shell case '$(ARCH)' in \
159 (native) echo $(NATIVE_ARCH) ;; \
160 (i*86*) echo i386 ;; \
161 (ppc*|powerpc*) echo ppc ;; \
162 (*) echo '$(ARCH)' ;; \
163 esac }
164
165# x86_64 can be either 32/64. set BIACH=32 to get 32 bit libraries.
166BIARCH = 64
167
Marco Varlese7ba44372017-09-03 19:04:46 +0200168aarch64_libdir = 64
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169x86_64_libdir = $(BIARCH)
170native_libdir = $($(NATIVE_ARCH)_libdir)
171
172# lib or lib64 depending
173arch_lib_dir = lib$($(BASIC_ARCH)_libdir)
174
175# OS to configure for. configure --host will be set to $(ARCH)-$(OS)
Dave Barach61efa142016-01-22 08:23:09 -0500176# Allow per-platform overrides
177
178OS = $(strip $($(PLATFORM)_os))
179ifeq ($(OS),)
180 OS = mu-linux
181endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182
183spu_target = spu
184native_target =
185
186is_native = $(if $(ARCH:native=),,true)
187not_native = $(if $(ARCH:native=),true,)
188
189ARCH_TARGET_tmp = $(call ifdef_fn,$(ARCH)_target,$(ARCH)-$(OS))
190TARGET = $(call ifdef_fn,$(PLATFORM)_target,$(ARCH_TARGET_tmp))
191TARGET_PREFIX = $(if $(not_native),$(TARGET)-,)
192
Dave Barach952ec0e2020-02-28 09:50:33 -0500193# CPU microarchitecture detection.
Ed Warnickecb9cada2015-12-08 15:45:58 -0700194# Either set <platform>_march in build-data/platforms/<platform>.mk,
195# or detect and use the build-host instruction set
196
197MARCH = $(strip $($(PLATFORM)_march))
198ifeq ($(MARCH),)
199 ifneq ($(wildcard $(TOOL_INSTALL_DIR)/bin/$(TARGET)-gcc),)
200 TARGET_GCC = $(TOOL_INSTALL_DIR)/bin/$(TARGET)-gcc
201 else ifneq ($(wildcard $(MU_BUILD_ROOT_DIR)/tools/bin/$(TARGET)-gcc),)
202 TARGET_GCC = $(MU_BUILD_ROOT_DIR)/tools/bin/$(TARGET)-gcc
203 endif
204 ifneq ($(TARGET_GCC),)
205 MARCH = $(shell $(TARGET_GCC) -Q --help=target -march=native | grep march | sed -e 's/.*march=[[:space:]]*//')
206 else
207 MARCH = native
208 endif
209else
210 ifeq ($(MARCH),nehalem)
211 override MARCH = corei7
212 else ifeq ($(MARCH),westmere)
213 override MARCH = corei7
214 else ifeq ($(MARCH),sandybridge)
215 override MARCH = corei7-avx
216 else ifeq ($(MARCH),ivybridge)
217 override MARCH = core-avx-i
218 else ifeq ($(MARCH),haswell)
219 override MARCH = core-avx2
220 endif
221endif
222export MARCH
223
Damjan Marion1c80e832016-05-11 23:07:18 +0200224MTUNE = $(strip $($(PLATFORM)_mtune))
225ifeq ($(MTUNE),)
226 MTUNE = generic
227endif
228
Ed Warnickecb9cada2015-12-08 15:45:58 -0700229######################################################################
230# Generic build stuff
231######################################################################
232
233# The package we are currently working on
234PACKAGE = $*
235
236# Build/install tags. This lets you have different CFLAGS/CPPFLAGS/LDFLAGS
237# for e.g. debug versus optimized compiles. Each tag has its own set of build/install
238# areas.
Dave Barach952ec0e2020-02-28 09:50:33 -0500239TAG =
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240TAG_PREFIX = $(if $(TAG),$(TAG)-)
241
242# yes you need the space
243tag_var_with_added_space_fn = $(if $($(TAG)_TAG_$(1)),$($(TAG)_TAG_$(1)) )
244
245# TAG=debug for debugging
Mohammed Hawarib78607b2021-01-22 14:30:56 +0100246debug_TAG_CFLAGS = -g -O0 -DCLIB_DEBUG -march=$(MARCH) \
Dave Barach459a11a2016-03-30 10:24:41 -0400247 -fstack-protector-all -fPIC
Mohammed Hawarib78607b2021-01-22 14:30:56 +0100248debug_TAG_CXXFLAGS = -g -O0 -DCLIB_DEBUG -march=$(MARCH) \
Neale Ranns5ee623e2018-01-10 07:27:17 -0800249 -fstack-protector-all -fPIC
Mohammed Hawarib78607b2021-01-22 14:30:56 +0100250debug_TAG_LDFLAGS = -g -O0 -DCLIB_DEBUG -march=$(MARCH) \
Dave Barach459a11a2016-03-30 10:24:41 -0400251 -fstack-protector-all -fPIC
Ed Warnickecb9cada2015-12-08 15:45:58 -0700252
253BUILD_PREFIX_package = build-$(TAG_PREFIX)
254BUILD_PREFIX_tool = build-tool-$(TAG_PREFIX)
255INSTALL_PREFIX = install-$(TAG_PREFIX)
256IMAGES_PREFIX = images-$(TAG_PREFIX)
257
258# Whether we are building a tool or not
259tool_or_package_fn = $(if $(is_build_tool),tool,package)
260
261# Directory where packages are built & installed
262BUILD_DIR = $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_$(call tool_or_package_fn))$(ARCH)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700263INSTALL_DIR = $(MU_BUILD_ROOT_DIR)/$(INSTALL_PREFIX)$(ARCH)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700264
265PLATFORM_IMAGE_DIR = $(MU_BUILD_ROOT_DIR)/$(IMAGES_PREFIX)$(PLATFORM)
266
267# $(call VAR,DEFAULT)
268override_var_with_default_fn = $(if $($(1)),$($(1)),$(2))
269
270# $(call if_directory_exists_fn,D1,D2) returns D1 if it exists else D2
271define if_directory_exists_fn
272$(shell if test -d $(1); then echo $(1); else echo $(2); fi)
273endef
274
275# $(call if_file_exists_fn,F1,F2) returns F1 if it exists else F2
276define if_file_exists_fn
277$(shell if test -f $(1); then echo $(1); else echo $(2); fi)
278endef
279
280# Default VAR, package specified override of default PACKAGE_VAR
281package_var_fn = $(call override_var_with_default_fn,$(1)_$(2),$(1))
282
283package_build_dir_fn = $(call package_var_fn,$(1),build_dir)
284
285package_install_dir_fn = \
286 $(if $(is_build_tool),$(TOOL_INSTALL_DIR),$(INSTALL_DIR)/$(call package_build_dir_fn,$(1)))
287
288PACKAGE_BUILD_DIR = \
289 $(BUILD_DIR)/$(call package_build_dir_fn,$(PACKAGE))
290PACKAGE_INSTALL_DIR = \
291 $(call package_install_dir_fn,$(PACKAGE))
292
293# Tools (gcc, binutils, glibc...) are installed here
294TOOL_INSTALL_DIR = $(MU_BUILD_ROOT_DIR)/tools
295
296# Target specific tools go here e.g. mu-build/tools/ppc-mu-linux
297TARGET_TOOL_INSTALL_DIR = $(TOOL_INSTALL_DIR)/$(TARGET)
298
299# Set BUILD_DEBUG to vx or x enable shell command tracing.
300BUILD_DEBUG =
301
302# Message from build system itself (as opposed to make or shell commands)
303build_msg_fn = echo "@@@@ $(1) @@@@"
304
Dave Barachc42508d2016-01-27 09:44:47 -0500305# Allow CCACHE_DIR to be overridden, e.g. in .../build-root/build-config.mk
306ifeq ($(CCACHE_DIR),)
307 CCACHE_DIR=$(MU_BUILD_ROOT_DIR)/.ccache
308endif
309
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310# Always prefer our own tools to those installed on system.
311# Note: ccache-bin must be before tool bin.
Dave Barach952ec0e2020-02-28 09:50:33 -0500312#
313# Removed LD_LIBRARY_PATH from BUILD_ENV (drb, 10/31/17):
Dave Barach0c0fe272017-10-31 16:28:11 -0400314# export LD_LIBRARY_PATH=$(TOOL_INSTALL_DIR)/lib64:$(TOOL_INSTALL_DIR)/lib
315# Reported to cause trouble. Only of historical interest, since we no longer
316# build a full tool chain from source.
317
Ed Warnickecb9cada2015-12-08 15:45:58 -0700318BUILD_ENV = \
Dave Barachc42508d2016-01-27 09:44:47 -0500319 export CCACHE_DIR=$(CCACHE_DIR) ; \
Damjan Marion92b44ea2018-03-14 22:09:22 +0100320 export PATH=$(wildcard /usr/lib*/ccache):$(TOOL_INSTALL_DIR)/bin:$${PATH} ; \
321 $(if $(call configure_var_fn,PATH), export PATH=$${PATH}:$(call configure_var_fn,PATH);,) \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322 export PATH="`echo $${PATH} | sed -e s/[.]://`" ; \
323 $(if $(not_native),export CONFIG_SITE=$(MU_BUILD_ROOT_DIR)/config.site ;,) \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324 set -eu$(BUILD_DEBUG) ; \
325 set -o pipefail
326
327######################################################################
328# Package build generic definitions
329######################################################################
330
331package_dir_fn = \
332 $(call find_build_data_dir_for_package_fn,$(1))/packages
333
334package_mk_fn = $(call package_dir_fn,$(1))/$(1).mk
335
Ed Warnickecb9cada2015-12-08 15:45:58 -0700336# Pick up built-root/pre-package-include.mk for all source directories
337$(foreach d,$(SOURCE_PATH_BUILD_ROOT_DIRS), \
338 $(eval -include $(d)/pre-package-include.mk))
339
340$(foreach d,$(addsuffix /packages,$(FIND_SOURCE_PATH)), \
341 $(eval -include $(d)/*.mk) \
342 $(eval ALL_PACKAGES += $(patsubst $(d)/%.mk,%,$(wildcard $(d)/*.mk))) \
343)
344
345# Pick up built-root/post-package-include.mk for all source directories
346$(foreach d,$(SOURCE_PATH_BUILD_ROOT_DIRS), \
347 $(eval -include $(d)/post-package-include.mk))
348
349# Linux specific native build tools
350NATIVE_TOOLS_LINUX = \
351 e2fsimage \
352 e2fsprogs \
353 fakeroot \
354 jffs2 \
355 mkimage \
356 zlib \
357 xz \
358 squashfs
359
360IS_LINUX = $(if $(findstring no,$($(PLATFORM)_uses_linux)),no,yes)
361
362NATIVE_TOOLS_$(IS_LINUX) += $(NATIVE_TOOLS_LINUX)
363
364# only build glibc for linux installs
365CROSS_TOOLS_$(IS_LINUX) += glibc gcc
366
367# must be first for bootstrapping
368NATIVE_TOOLS = findutils make
369
370# basic tools needed for build system
Ole Troan9d420872017-10-12 13:06:35 +0200371NATIVE_TOOLS += git automake autoconf libtool texinfo tar
Ed Warnickecb9cada2015-12-08 15:45:58 -0700372
373# needed to compile gcc
374NATIVE_TOOLS += mpfr gmp mpc
375
376# Tool to sign binaries
377NATIVE_TOOLS += sign
378
379# ccache
380NATIVE_TOOLS += ccache
381
382# Tools needed on native host to build for platform
383NATIVE_TOOLS += $(call ifdef_fn,$(PLATFORM)_native_tools,)
384
385# Tools for cross-compiling from native -> ARCH
386CROSS_TOOLS = binutils gcc-bootstrap gdb
387
388# Tools needed on native host to build for platform
389CROSS_TOOLS += $(call ifdef_fn,$(PLATFORM)_cross_tools,)
390
391NATIVE_TOOLS += $(NATIVE_TOOLS_yes)
392CROSS_TOOLS += $(CROSS_TOOLS_yes)
393
394timestamp_name_fn = .mu_build_$(1)_timestamp
395CONFIGURE_TIMESTAMP = $(call timestamp_name_fn,configure)
396BUILD_TIMESTAMP = $(call timestamp_name_fn,build)
397INSTALL_TIMESTAMP = $(call timestamp_name_fn,install)
398
399TIMESTAMP_DIR = $(PACKAGE_BUILD_DIR)
400
401find_newer_files_fn = \
402 "`for i in $(2) ; do \
403 [[ -f $$i && $$i -nt $(1) ]] && echo "$$i" && exit 0; \
404 done ; \
405 exit 0;`"
406
407find_filter = -not -name '*~'
408find_filter += -and -not -path '*/.git*'
409find_filter += -and -not -path '*/.svn*'
410find_filter += -and -not -path '*/.CVS*'
411find_filter += -and -not -path '*/manual/*'
412find_filter += -and -not -path '*/autom4te.cache/*'
413find_filter += -and -not -path '*/doc/all-cfg.texi'
414find_filter += -and -not -path '*/.mu_build_*'
415
416find_newer_filtered_fn = \
417 (! -f $(1) \
418 || -n $(call find_newer_files_fn,$(1),$(3)) \
Dave Barach1b576e02021-01-04 10:52:44 -0500419 || -n "`find -L $(2) \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420 -type f \
421 -and -newer $(1) \
422 -and \( $(4) \) \
423 -print -quit`")
424
425find_newer_fn = \
426 $(call find_newer_filtered_fn,$(1),$(2),$(3),$(find_filter))
427
428######################################################################
429# Package dependencies
430######################################################################
431
432# This must come before %-configure, %-build, %-install pattern rules
433# or else dependencies will not work.
434
435package_dependencies_fn = \
436 $(patsubst %-install, %, \
437 $(filter %-install,$($(1)_configure_depend)))
438
439PACKAGE_DEPENDENCIES = $(call package_dependencies_fn,$(PACKAGE))
440
441# package specific configure, build, install dependencies
442add_package_dependency_fn = \
443 $(if $($(1)_$(2)_depend), \
444 $(eval $(1)-$(2) : $($(1)_$(2)_depend)))
445
446$(foreach p,$(ALL_PACKAGES), \
447 $(call add_package_dependency_fn,$(p),configure) \
448 $(call add_package_dependency_fn,$(p),build) \
449 $(call add_package_dependency_fn,$(p),install))
450
451TARGETS_RESPECTING_DEPENDENCIES = image_install wipe diff push-all pull-all find-source
452
453# carry over packages dependencies to image install, wipe, pull-all, push-all
454$(foreach p,$(ALL_PACKAGES), \
455 $(if $($(p)_configure_depend), \
456 $(foreach s,$(TARGETS_RESPECTING_DEPENDENCIES), \
457 $(eval $(p)-$(s): \
458 $(addsuffix -$(s), $(call package_dependencies_fn,$(p)))))))
459
460# recursively resolve dependencies
461resolve_dependencies2_fn = $(strip \
462 $(eval __added = $(filter-out $(4), \
463 $(call uniq_fn, \
464 $(foreach l,$(3), \
465 $(call ifdef3_fn,$(l)$(1),,$(call $(2),$($(l)$(1)))) \
466 )))) \
467 $(eval __known = $(call uniq_fn,$(4) $(3) $(__added))) \
468 $(if $(__added), \
469 $(call resolve_dependencies2_fn,$(1),$(2),$(__added),$(__known)), \
470 $(__known)) \
471)
472
473resolve_dependencies_null_fn = $(1)
474
475resolve_dependencies_fn = $(call resolve_dependencies2_fn,$(1),resolve_dependencies_null_fn,$(2))
476
477######################################################################
478# Package configure
479######################################################################
480
481# x86_64 can be either 32/64. set BIACH=32 to get 32 bit libraries.
482BIARCH = 64
483
484x86_64_libdir = $(BIARCH)
485native_libdir = $($(NATIVE_ARCH)_libdir)
486
487# lib or lib64 depending
488arch_lib_dir = lib$($(BASIC_ARCH)_libdir)
489
490# find dynamic linker as absolute path
491TOOL_INSTALL_LIB_DIR=$(TOOL_INSTALL_DIR)/$(TARGET)/$(arch_lib_dir)
492DYNAMIC_LINKER=${shell cd $(TOOL_INSTALL_LIB_DIR); echo ld*.so.*}
493
494# Pad dynamic linker & rpath so elftool will never have to change ELF section sizes.
495# Yes, this is a kludge.
496lots_of_slashes_to_pad_names = "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"
497
498# When PLATFORM != native we *always* use our own versions of GLIBC and dynamic linker
Dave Barach61efa142016-01-22 08:23:09 -0500499# Allow per-platform overrides
500CROSS_LDFLAGS = $(strip $($(PLATFORM)_cross_ldflags))
501ifeq ($(CROSS_LDFLAGS),)
502 CROSS_LDFLAGS = \
503 -Wl,--dynamic-linker=$(lots_of_slashes_to_pad_names)$(TOOL_INSTALL_LIB_DIR)/$(DYNAMIC_LINKER) \
504 -Wl,-rpath -Wl,$(lots_of_slashes_to_pad_names)$(TOOL_INSTALL_LIB_DIR)
505endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700506
507cross_ldflags = $(if $(is_native)$(is_build_tool),,$(CROSS_LDFLAGS) )
508
509# $(call installed_libs_fn,PACKAGE)
510# Return install library directory for given package.
511# Some packages (e.g. openssl) don't install under lib64; instead they use lib
512define installed_lib_fn
513$(call if_directory_exists_fn,
514 $(call package_install_dir_fn,$(1))/$(arch_lib_dir),
515 $(call package_install_dir_fn,$(1))/lib)
516endef
517
518# Set -L and rpath to point to dependent libraries previously built by us.
519installed_libs_fn = \
520 $(foreach i,$(1), \
521 -L$(call installed_lib_fn,$(i)) \
522 -Wl,-rpath -Wl,$(call installed_lib_fn,$(i)))
523
524# As above for include files
525installed_include_fn = $(call package_install_dir_fn,$(1))/include
526
527installed_includes_fn = $(foreach i,$(1),-I$(call installed_include_fn,$(i)))
528
529# By default package CPPFLAGS (to set include path -I) and LDFLAGS (to set link path -L)
530# point at dependent install directories.
531DEFAULT_CPPFLAGS = $(call installed_includes_fn, $(PACKAGE_DEPENDENCIES))
532DEFAULT_LDFLAGS = $(call installed_libs_fn, $(PACKAGE_DEPENDENCIES))
533
534configure_var_fn = \
535 $(call tag_var_with_added_space_fn,$(1))$(call override_var_with_default_fn,$(PACKAGE)_$(1),$(DEFAULT_$(1)))
536configure_ldflags_fn = \
537 $(cross_ldflags)$(call configure_var_fn,LDFLAGS)
538
539# Allow packages to override CPPFLAGS, CFLAGS, and LDFLAGS
540CONFIGURE_ENV = \
541 $(if $(call configure_var_fn,CPPFLAGS), \
542 CPPFLAGS="$(CPPFLAGS) $(call configure_var_fn,CPPFLAGS)") \
Neale Ranns5ee623e2018-01-10 07:27:17 -0800543 $(if $(call configure_var_fn,CXXFLAGS), \
544 CXXFLAGS="$(CXXFLAGS) $(call configure_var_fn,CXXFLAGS)") \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700545 $(if $(call configure_var_fn,CFLAGS), \
546 CFLAGS="$(CFLAGS) $(call configure_var_fn,CFLAGS)") \
547 $(if $(call configure_var_fn,CCASFLAGS), \
548 CCASFLAGS="$(CCASFLAGS) $(call configure_var_fn,CCASFLAGS)") \
549 $(if $(call configure_ldflags_fn), \
550 LDFLAGS="$(LDFLAGS) $(call configure_ldflags_fn)") \
551 $(if $($(PACKAGE)_configure_env),$($(PACKAGE)_configure_env))
552
Ed Warnickecb9cada2015-12-08 15:45:58 -0700553# only partially used now (used in a few .mk files)
554ifeq ($(is_build_tool),yes)
555prefix = $(PACKAGE_INSTALL_DIR)
556libdir = $(PACKAGE_INSTALL_DIR)/$(arch_lib_dir)
557libexecdir = $(PACKAGE_INSTALL_DIR)/usr/libexec
558DESTDIR = /
559else
560# Eventually simplify this with no per package DESTDIR or prefix
561ppdMacro = $(if $(PER_PACKAGE_DESTDIR),$(call package_build_dir_fn,$(1)))
562pppMacro = $(if $(PER_PACKAGE_PREFIX),$(call package_build_dir_fn,$(1)))
563prefixMacro = $($(PLATFORM)_PREFIX_BASE)/$(pppMacro)
564prefix = $(call prefixMacro,$(PACKAGE))
565libdir = $($(PLATFORM)_LIBDIR)
566libexecdir = $($(PLATFORM)_LIBEXECDIR)
567destdirMacro = $($(PLATFORM)_DESTDIR_BASE)$(ppdMacro)
568DESTDIR = $(call destdirMacro,$(PACKAGE))
569endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700570
571configure_package_gnu = \
Damjan Marion686c1c82017-04-19 14:09:07 +0200572 s=$(call find_source_fn,$(PACKAGE_SOURCE))$(PACKAGE_SUBDIR) ; \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700573 if [ ! -f $$s/configure ] ; then \
574 autoreconf -i -f $$s ; \
575 fi ; \
576 cd $(PACKAGE_BUILD_DIR) ; \
577 env $(CONFIGURE_ENV) \
578 $$s/configure \
579 $(if $($(PACKAGE)_configure_host_and_target), \
580 $($(PACKAGE)_configure_host_and_target), \
581 $(if $(not_native),--host=$(TARGET),)) \
582 $(if $($(PACKAGE)_configure_prefix), \
583 $($(PACKAGE)_configure_prefix), \
584 --libdir=$(PACKAGE_INSTALL_DIR)/$(arch_lib_dir) \
585 --prefix=$(PACKAGE_INSTALL_DIR)) \
586 $($(PACKAGE)_configure_args) \
587 $($(PACKAGE)_configure_args_$(PLATFORM))
588
589configure_package = \
590 $(call build_msg_fn,Configuring $(PACKAGE) in $(PACKAGE_BUILD_DIR)) ; \
591 mkdir -p $(PACKAGE_BUILD_DIR) ; \
592 $(if $($(PACKAGE)_configure), \
593 $($(PACKAGE)_configure), \
594 $(configure_package_gnu))
595
596# Tools (e.g. gcc, binutils, gdb) required a platform to build for
597check_platform = \
598 is_tool="$(is_build_tool)" ; \
599 is_cross_package="$(findstring $(PACKAGE),$(CROSS_TOOLS))" ; \
600 is_arch_native="$(if $(subst native,,$(ARCH)),,yes)" ; \
601 if [ "$${is_tool}" == "yes" \
602 -a "$${is_cross_package}" != "" \
603 -a "$${is_arch_native}" != "" ]; then \
604 $(call build_msg_fn,You must specify PLATFORM for building tools) ; \
605 exit 1 ; \
606 fi ; \
607 : check that platform gcc can be found ; \
608 target_gcc=gcc ; \
609 if [ "$${is_arch_native}" != "yes" ] ; then \
610 target_gcc=$(TARGET)-gcc ; \
611 fi ; \
612 if [ "$${is_tool}" != "yes" \
613 -a "$${is_arch_native}" != "yes" \
614 -a ! -x "`which 2> /dev/null $${target_gcc}`" ] ; then \
615 $(call build_msg_fn, \
616 No cross-compiler found for platform $(PLATFORM) target $(TARGET); \
617 try make PLATFORM=$(PLATFORM) install-tools) ; \
618 exit 1 ; \
619 fi
Dave Barach952ec0e2020-02-28 09:50:33 -0500620
Ed Warnickecb9cada2015-12-08 15:45:58 -0700621configure_check_timestamp = \
622 @$(BUILD_ENV) ; \
623 $(check_platform) ; \
624 mkdir -p $(PACKAGE_BUILD_DIR) ; \
625 mkdir -p $(PACKAGE_INSTALL_DIR) ; \
626 conf="$(TIMESTAMP_DIR)/$(CONFIGURE_TIMESTAMP)" ; \
627 dirs="$(call package_mk_fn,$(PACKAGE)) \
Burt Silvermane5297322019-01-22 21:55:02 -0500628 $(SOURCE_PATH_BUILD_DATA_DIRS)/platforms/$(PLATFORM).mk \
629 $(wildcard $(call find_source_fn,$(PACKAGE_SOURCE))/cmake) \
630 $(shell find $(call find_source_fn,$(PACKAGE_SOURCE)) \
631 -name CMakeLists.txt) \
Damjan Marion686c1c82017-04-19 14:09:07 +0200632 $(wildcard $(call find_source_fn, \
633 $(PACKAGE_SOURCE))$(PACKAGE_SUBDIR)/configure) \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700634 $(MU_BUILD_ROOT_DIR)/config.site" ; \
635 if [[ $(call find_newer_fn, $${conf}, $${dirs}, $?) ]]; then \
636 $(configure_package) ; \
637 touch $${conf} ; \
638 else \
639 $(call build_msg_fn,Configuring $(PACKAGE): nothing to do) ; \
640 fi
641
642.PHONY: %-configure
643%-configure: %-find-source
644 $(configure_check_timestamp)
645
646######################################################################
647# Package build
648######################################################################
649
Chris Lukeb2861e82017-06-14 11:24:41 -0400650# /proc/cpuinfo does not exist on platforms without a /proc and on some
651# platforms, notably inside containers, it has no content. In those cases
652# we assume there's 1 processor; we use 2*ncpu for the -j option.
653# NB: GNU Make 4.2 will let us use '$(file </proc/cpuinfo)' to both test
654# for file presence and content; for now this will have to do.
Klement Sekera8432e6e2018-03-21 17:44:20 +0100655ifndef MAKE_PARALLEL_JOBS
Andrew Yourtchenko56ac7702020-02-07 12:58:00 +0100656MAKE_PARALLEL_JOBS = $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo), \
Damjan Marion93242842017-11-13 20:09:21 +0100657 $(shell grep -c ^processor /proc/cpuinfo), 2)
Klement Sekera8432e6e2018-03-21 17:44:20 +0100658endif
Andrew Yourtchenko56ac7702020-02-07 12:58:00 +0100659MAKE_PARALLEL_FLAGS ?= $(if $($(PACKAGE)_make_parallel_fails),,-j $(MAKE_PARALLEL_JOBS))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700660
661# Make command shorthand for packages & tools.
662PACKAGE_MAKE = \
663 $(MAKE) \
664 -C $(PACKAGE_BUILD_DIR) \
665 $($(PACKAGE)_make_args) \
666 $(MAKE_PARALLEL_FLAGS)
667
668build_package = \
669 $(call build_msg_fn,Building $* in $(PACKAGE_BUILD_DIR)) ; \
670 mkdir -p $(PACKAGE_BUILD_DIR) ; \
671 cd $(PACKAGE_BUILD_DIR) ; \
672 $(if $($(PACKAGE)_build), \
673 $($(PACKAGE)_build), \
674 $(PACKAGE_MAKE))
675
676build_check_timestamp = \
677 @$(BUILD_ENV) ; \
678 comp="$(TIMESTAMP_DIR)/$(BUILD_TIMESTAMP)" ; \
679 conf="$(TIMESTAMP_DIR)/$(CONFIGURE_TIMESTAMP)" ; \
680 dirs="$(call find_source_fn,$(PACKAGE_SOURCE)) \
681 $($(PACKAGE)_build_timestamp_depends) \
682 $(if $(is_build_tool),,$(addprefix $(INSTALL_DIR)/,$(PACKAGE_DEPENDENCIES)))" ; \
683 if [[ $${conf} -nt $${comp} \
684 || $(call find_newer_fn, $${comp}, $${dirs}, $?) ]]; then \
685 $(build_package) ; \
686 touch $${comp} ; \
687 else \
688 $(call build_msg_fn,Building $(PACKAGE): nothing to do) ; \
689 fi
690
691.PHONY: %-build
692%-build: %-configure
693 $(build_check_timestamp)
694
695.PHONY: %-rebuild
696%-rebuild: %-wipe %-build
697 @ :
698
699######################################################################
700# Package install
701######################################################################
702
703install_package = \
704 : by default, for non-tools, remove any previously installed bits ; \
705 $(if $(is_build_tool)$($(PACKAGE)_keep_instdir), \
706 true, \
707 rm -rf $(PACKAGE_INSTALL_DIR)); \
708 mkdir -p $(PACKAGE_INSTALL_DIR) ; \
709 $(if $($(PACKAGE)_pre_install),$($(PACKAGE)_pre_install),true); \
710 $(if $($(PACKAGE)_install), \
711 $($(PACKAGE)_install), \
712 $(PACKAGE_MAKE) \
713 $($(PACKAGE)_install_args) \
714 install) ; \
715 $(if $($(PACKAGE)_post_install),$($(PACKAGE)_post_install),true)
716
717install_check_timestamp = \
718 @$(BUILD_ENV) ; \
719 inst=$(TIMESTAMP_DIR)/$(INSTALL_TIMESTAMP) ; \
720 dirs="$(PACKAGE_BUILD_DIR) \
721 $($(PACKAGE)_install_dependencies)" ; \
722 if [[ $(call find_newer_fn, $${inst}, $${dirs}, $?) ]]; then \
723 $(call build_msg_fn,Installing $(PACKAGE)) ; \
724 $(install_package) ; \
725 touch $${inst} ; \
726 else \
727 $(call build_msg_fn,Installing $(PACKAGE): nothing to do) ; \
728 fi
729
730.PHONY: %-install
731%-install: %-build
732 $(install_check_timestamp)
733
734######################################################################
735# Source code managment
736######################################################################
737
738GIT = git
739
740# Maps package name to source directory root.
741# Multiple packages may use a single source tree.
742# For example, gcc-bootstrap package shares gcc source.
743PACKAGE_SOURCE = $(if $($(PACKAGE)_source),$($(PACKAGE)_source),$(PACKAGE))
Damjan Marion686c1c82017-04-19 14:09:07 +0200744PACKAGE_SUBDIR = $(if $($(PACKAGE)_configure_subdir),/$($(PACKAGE)_configure_subdir),)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700745
746# Use git to download source if directory is not found
747find_source_for_package = \
748 @$(BUILD_ENV) ; \
749 $(call build_msg_fn,Arch for platform '$(PLATFORM)' is $(ARCH)) ; \
750 $(call build_msg_fn,Finding source for $(PACKAGE)) ; \
751 s="$(call find_source_fn,$(PACKAGE_SOURCE))" ; \
752 [[ -z "$${s}" ]] \
753 && $(call build_msg_fn,Package $(PACKAGE) not found with path $(SOURCE_PATH)) \
754 && exit 1; \
755 mk="$(call find_build_data_dir_for_package_fn,$(PACKAGE_SOURCE))/packages/$(PACKAGE).mk"; \
756 $(call build_msg_fn,Makefile fragment found in $${mk}) ; \
757 if [ ! -d "$${s}" ] ; then \
758 d=`dirname $${mk}` ; \
759 i=`cd $${d}/.. && ($(GIT) config remote.origin.url || \
760 awk '/URL/ { print $$2; }' .git/remotes/origin)`; \
761 g=`dirname $${i}` ; \
762 $(call build_msg_fn,Fetching source: $(GIT) clone $${g}/$(PACKAGE_SOURCE) $$s) ; \
763 if ! $(GIT) clone $${g}/$(PACKAGE_SOURCE) $$s; then \
764 $(call build_msg_fn,No source for $(PACKAGE) in $${g}); \
765 exit 1; \
766 fi ; \
Dave Barach7210e942015-12-15 18:57:51 -0500767 $(call build_msg_fn,Fix file dates in $${g}/$(PACKAGE_SOURCE)) ; \
Simon Chatterjee810ad342020-06-15 17:17:18 +0000768 : the timestamp-adjustment script used to be invoked at this point ; \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700769 fi ; \
770 s=`cd $${s} && pwd` ; \
771 $(call build_msg_fn,Source found in $${s})
772
773.PHONY: %-find-source
774%-find-source:
775 $(find_source_for_package)
776
777.PHONY: %-push %-pull %-push-all %-pull-all
778%-push %-pull %-push-all %-pull-all:
779 @$(BUILD_ENV) ; \
780 push_or_pull=$(patsubst %-all,%,$(subst $(PACKAGE)-,,$@)) ; \
781 $(call build_msg_fn,Git $${push_or_pull} source for $(PACKAGE)) ; \
782 s=$(call find_source_fn,$(PACKAGE_SOURCE)) ; \
783 if [ "x$$s" = "x" ]; then \
784 $(call build_msg_fn,No source for $(PACKAGE)) ; \
785 exit 1; \
786 fi ; \
787 cd $$s && $(GIT) $${push_or_pull}
788
789# Pull all packages for platform
790.PHONY: pull-all
791pull-all:
792 @$(BUILD_ENV) ; \
793 $(call build_msg_fn,Git pull build system) ; \
794 for d in $(MU_BUILD_ROOT_DIR) \
795 $(SOURCE_PATH_BUILD_ROOT_DIRS) \
796 $(SOURCE_PATH_BUILD_DATA_DIRS); do \
797 $(call build_msg_fn,Git pull $${d}) ; \
798 pushd $${d} >& /dev/null && $(GIT) pull && popd >& /dev/null ; \
799 done ; \
800 $(call build_msg_fn,Git pull build tools) ; \
801 $(call tool_make_target_fn,pull-all) ; \
802 $(call build_msg_fn,Git pull packages for platform $(PLATFORM)) ; \
803 make PLATFORM=$(PLATFORM) $(patsubst %,%-pull-all,$(ROOT_PACKAGES))
804
805.PHONY: %-diff
Dave Barach952ec0e2020-02-28 09:50:33 -0500806%-diff:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700807 @$(BUILD_ENV) ; \
808 d=$(call find_source_fn,$(PACKAGE_SOURCE)) ; \
809 $(call build_msg_fn,Git diff $(PACKAGE)) ; \
810 if [ -d $${d}/.git ] ; then \
811 cd $${d} && $(GIT) --no-pager diff 2>/dev/null; \
812 else \
813 $(call build_msg_fn, $(PACKAGE) not a git directory) ; \
814 fi
Dave Barach952ec0e2020-02-28 09:50:33 -0500815
Ed Warnickecb9cada2015-12-08 15:45:58 -0700816
817
818# generate diffs for everything in source path
819.PHONY: diff-all
Dave Barach952ec0e2020-02-28 09:50:33 -0500820diff-all:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700821 @$(BUILD_ENV) ; \
822 $(call build_msg_fn,Generate diffs) ; \
823 for r in $(ABSOLUTE_SOURCE_PATH); do \
824 for d in $${r}/* ; do \
825 if [ -d $${d} ] ; then \
826 $(call build_msg_fn,Git diff $${d}) ; \
827 if [ -d $${d}/.git ] ; then \
828 cd $${d} && $(GIT) --no-pager diff 2>/dev/null; \
829 else \
830 $(call build_msg_fn, $${d} not a git directory) ; \
831 fi ; \
832 fi ; \
833 done ; \
834 done
835
836######################################################################
837# System images
838######################################################################
839
840IMAGE_DIR = $(MU_BUILD_ROOT_DIR)/image-$(PLATFORM)
841
842# Reports shared libraries in given directory
843find_shared_libs_fn = \
844 find $(1) \
845 -maxdepth 1 \
846 -regex '.*/lib[a-z0-9_]+\+?\+?.so' \
847 -o -regex '.*/lib[a-z0-9_]+-[0-9.]+\+?\+?.so' \
848 -o -regex '.*/lib[a-z0-9_]+\+?\+?.so.[0-9.]+'
849
850# By default pick up files from binary directories and /etc.
851# Also include shared libraries.
852DEFAULT_IMAGE_INCLUDE = \
853 for d in bin sbin libexec \
854 usr/bin usr/sbin usr/libexec \
855 etc; do \
856 [[ -d $$d ]] && echo $$d; \
857 done ; \
858 [[ -d $(arch_lib_dir) ]] \
859 && $(call find_shared_libs_fn,$(arch_lib_dir))
860
861# Define any shell functions needed by install scripts
862image_install_functions = \
863 $(foreach p,$(ALL_PACKAGES), \
864 $(if $($(p)_image_install_functions), \
865 $($(p)_image_install_functions)))
866
867# Should always be over-written by temp dir in %-root-image rule
868IMAGE_INSTALL_DIR = $(error you need to set IMAGE_INSTALL_DIR)
869
870image_install_fn = \
871 @$(BUILD_ENV) ; \
872 $(call build_msg_fn,Image-install $(1) for platform $(PLATFORM)) ; \
873 inst_dir=$(IMAGE_INSTALL_DIR) ; \
874 mkdir -p $${inst_dir} ; \
875 cd $(2) ; \
876 : select files to include in image ; \
877 image_include_files=" \
878 `$(call ifdef_fn,$(1)_image_include,$(DEFAULT_IMAGE_INCLUDE)) ; \
879 echo "" ; \
880 exit 0 ; `"; \
881 : select files regexps to exclude from image ; \
882 image_exclude_files="" ; \
883 if [ ! -z "$($(1)_image_exclude)" ] ; then \
884 image_exclude_files="${image_exclude_files} \
885 $(patsubst %,--exclude=%,$($(1)_image_exclude))" ; \
886 fi ; \
887 [[ -z "$${image_include_files}" || $${image_include_files} == " " ]] \
888 || tar cf - $${image_include_files} $${image_exclude_files} \
889 | tar xf - -C $${inst_dir} ; \
890 : copy files from copyimg directories on source path if present ; \
891 for build_data_dir in $(SOURCE_PATH_BUILD_DATA_DIRS) ; do \
892 d="$${build_data_dir}/packages/$(1).copyimg" ; \
893 if [ -d "$${d}" ] ; then \
894 env $($(PLATFORM)_copyimg_env) \
895 $(MU_BUILD_ROOT_DIR)/copyimg $${d} $${inst_dir} ; \
896 fi ; \
897 done ; \
898 : run package dependent install script ; \
899 $(if $($(1)_image_install), \
900 $(image_install_functions) \
901 cd $${inst_dir} ; \
902 $($(1)_image_install))
903
904.PHONY: %-image_install
905%-image_install: %-install
906 $(call image_install_fn,$(PACKAGE),$(PACKAGE_INSTALL_DIR))
907
908basic_system_image_include = \
909 $(call ifdef_fn,$(PLATFORM)_basic_system_image_include, \
910 echo bin/ldd ; \
911 echo $(arch_lib_dir)/ld*.so* ; \
912 $(call find_shared_libs_fn, $(arch_lib_dir)))
913
914basic_system_image_install = \
915 mkdir -p bin lib mnt proc root sbin sys tmp etc ; \
916 mkdir -p usr usr/{bin,sbin} usr/lib ; \
917 mkdir -p var var/{lib,lock,log,run,tmp} ; \
Dave Barach952ec0e2020-02-28 09:50:33 -0500918 mkdir -p var/lock/subsys var/lib/urandom
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919
920.PHONY: basic_system-image_install
921basic_system-image_install: # linuxrc-install
922 $(if $(not_native), \
923 $(call image_install_fn,basic_system,$(TARGET_TOOL_INSTALL_DIR)),)
924
925ROOT_PACKAGES = $(if $($(PLATFORM)_root_packages),$($(PLATFORM)_root_packages),$(default_root_packages))
926
927.PHONY: install-packages
Dave Barach952ec0e2020-02-28 09:50:33 -0500928install-packages: $(patsubst %,%-find-source,$(ROOT_PACKAGES))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700929 @$(BUILD_ENV) ; \
930 set -eu$(BUILD_DEBUG) ; \
931 d=$(MU_BUILD_ROOT_DIR)/packages-$(PLATFORM) ; \
932 rm -rf $${d} ; \
933 mkdir -p $${d}; \
934 $(MAKE) -C $(MU_BUILD_ROOT_DIR) IMAGE_INSTALL_DIR=$${d} \
935 $(patsubst %,%-image_install, \
936 basic_system \
937 $(ROOT_PACKAGES)) || exit 1; \
938 $(call build_msg_fn, Relocating ELF executables to run in $${d}) ; \
Dave Barach5a72e422018-03-13 12:54:43 -0400939 scripts/set-rpath $${d} $${d}/$(arch_lib_dir) ; \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700940 : strip symbols from files ; \
941 if [ $${strip_symbols:-no} = 'yes' ] ; then \
942 $(call build_msg_fn, Stripping symbols from files) ; \
943 find $${d} -type f \
944 -exec \
945 $(TARGET_PREFIX)strip \
946 --strip-unneeded '{}' ';' \
947 >& /dev/null ; \
948 else \
949 $(call build_msg_fn, NOT stripping symbols) ; \
Dave Barach952ec0e2020-02-28 09:50:33 -0500950 fi
Ed Warnickecb9cada2015-12-08 15:45:58 -0700951
952# readonly root squashfs image
953# Note: $(call build_msg_fn) does not seem to work inside of fakeroot so we use echo
954.PHONY: ro-image
955$(PLATFORM_IMAGE_DIR)/ro.img ro-image: $(patsubst %,%-find-source,$(ROOT_PACKAGES))
956 @$(BUILD_ENV) ; \
957 d=$(PLATFORM_IMAGE_DIR) ; \
958 mkdir -p $$d; \
959 ro_image=$$d/ro.img ; \
960 rm -f $${ro_image} ; \
961 tmp_dir="`mktemp -d $$d/ro-image-XXXXXX`" ; \
962 chmod 0755 $${tmp_dir} ; \
963 cd $${tmp_dir} ; \
964 trap "rm -rf $${tmp_dir}" err ; \
965 fakeroot /bin/bash -c "{ \
966 set -eu$(BUILD_DEBUG) ; \
967 $(MAKE) -C $(MU_BUILD_ROOT_DIR) IMAGE_INSTALL_DIR=$${tmp_dir} \
968 $(patsubst %,%-image_install, \
969 basic_system \
970 $(ROOT_PACKAGES)) ; \
971 : make dev directory ; \
972 $(linuxrc_makedev) ; \
973 echo @@@@ Relocating ELF executables to run in / @@@@ ; \
Dave Barach5a72e422018-03-13 12:54:43 -0400974 scripts/set-rpath /$(arch_lib_dir):/lib ; \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700975 : strip symbols from files ; \
976 if [ '$${strip_symbols:-yes}' = 'yes' ] ; then \
977 echo @@@@ Stripping symbols from files @@@@ ; \
978 find $${tmp_dir} -type f \
979 -exec \
980 $(TARGET_PREFIX)strip \
981 --strip-unneeded '{}' ';' \
982 >& /dev/null ; \
983 else \
984 echo @@@@ NOT stripping symbols @@@@ ; \
985 fi ; \
986 if [ $${sign_executables:-yes} = 'yes' \
987 -a -n "$($(PLATFORM)_public_key)" ] ; then \
988 echo @@@@ Signing executables @@@@ ; \
989 find $${tmp_dir} -type f \
990 | xargs sign $($(PLATFORM)_public_key) \
991 $($(PLATFORM)_private_key_passphrase) ; \
992 fi ; \
993 : make read-only file system ; \
994 mksquashfs \
995 $${tmp_dir} $${ro_image} \
996 -no-exports -no-progress -no-recovery ; \
997 }" ; \
998 : cleanup tmp directory ; \
999 rm -rf $${tmp_dir}
1000
1001MKFS_JFFS2_BYTE_ORDER_x86_64 = -l
1002MKFS_JFFS2_BYTE_ORDER_i686 = -l
1003MKFS_JFFS2_BYTE_ORDER_ppc = -b
1004MKFS_JFFS2_BYTE_ORDER_mips = -b
1005MKFS_JFFS2_BYTE_ORDER_native = $(MKFS_JFFS2_BYTE_ORDER_$(NATIVE_ARCH))
1006
1007MKFS_JFFS2_SECTOR_SIZE_IN_KBYTES = \
1008 $(call ifdef_fn,$(PLATFORM)_jffs2_sector_size_in_kbytes,256)
1009
1010mkfs_fn_jffs2 = mkfs.jffs2 \
1011 --eraseblock=$(MKFS_JFFS2_SECTOR_SIZE_IN_KBYTES)KiB \
1012 --root=$(1) --output=$(2) \
1013 $(MKFS_JFFS2_BYTE_ORDER_$(BASIC_ARCH))
1014
1015# As things stand the actual initrd size parameter
1016# is set in .../open-repo/build-data/packages/linuxrc.mk.
1017EXT2_RW_IMAGE_SIZE=notused
1018
1019mkfs_fn_ext2 = \
1020 e2fsimage -d $(1) -f $(2) -s $(EXT2_RW_IMAGE_SIZE)
1021
1022RW_IMAGE_TYPE=jffs2
1023
1024make_rw_image_fn = \
1025 $(call mkfs_fn_$(RW_IMAGE_TYPE),$(1),$(2))
1026
1027rw_image_embed_ro_image_fn = \
1028 mkdir -p proc initrd images ro rw union ; \
1029 cp $(PLATFORM_IMAGE_DIR)/$(1) images/$(1) ; \
1030 md5sum images/$(1) > images/$(1).md5 ; \
1031 echo Built by $(LOGNAME) at `date` > images/$(1).stamp ; \
1032 mkdir -p changes/$(1)
1033
1034# make sure RW_IMAGE_TYPE is a type we know how to build
1035.PHONY: rw-image-check-type
1036rw-image-check-type:
1037 @$(BUILD_ENV) ; \
1038 if [ -z "$(make_rw_image_fn)" ] ; then \
1039 $(call build_msg_fn,Unknown read/write fs image type; \
1040 try RW_IMAGE_TYPE=ext2 or RW_IMAGE_TYPE=jffs2) ; \
1041 exit 1; \
1042 fi
1043
1044# read write image
1045.PHONY: rw-image
1046rw-image: rw-image-check-type ro-image
1047 @$(BUILD_ENV) ; \
1048 d=$(PLATFORM_IMAGE_DIR) ; \
1049 mkdir -p $$d ; \
1050 rw_image="$$d/rw.$(RW_IMAGE_TYPE)" ; \
1051 ro_image="ro.img" ; \
1052 rm -f $$rw_image ; \
1053 tmp_dir="`mktemp -d $$d/rw-image-XXXXXX`" ; \
1054 chmod 0755 $${tmp_dir} ; \
1055 cd $${tmp_dir} ; \
1056 trap "rm -rf $${tmp_dir}" err ; \
1057 fakeroot /bin/bash -c "{ \
1058 set -eu$(BUILD_DEBUG) ; \
1059 $(linuxrc_makedev) ; \
1060 $(call rw_image_embed_ro_image_fn,$${ro_image}) ; \
1061 $(call make_rw_image_fn,$${tmp_dir},$${rw_image}) ; \
1062 }" ; \
1063 : cleanup tmp directory ; \
1064 rm -rf $${tmp_dir}
1065
1066images: linuxrc-install linux-install $(image_extra_dependencies) rw-image
1067 @$(BUILD_ENV) ; \
1068 d=$(PLATFORM_IMAGE_DIR) ; \
1069 cd $(BUILD_DIR)/linux-$(PLATFORM) ; \
1070 i="" ; \
1071 [[ -z $$i && -f bzImage ]] && i=bzImage ; \
1072 [[ -z $$i && -f zImage ]] && i=zImage ; \
1073 [[ -z $$i && -f linux ]] && i=linux ; \
1074 [[ -z $$i && -f vmlinux ]] && i=vmlinux ; \
1075 [[ -z $$i ]] \
1076 && $(call build_msg_fn,no linux image to install \
1077 in $(BUILD_DIR)/linux-$(PLATFORM)) \
1078 && exit 1 ; \
1079 cp $$i $$d
1080
1081######################################################################
1082# Tool chain build/install
1083######################################################################
1084
1085.PHONY: ccache-install
1086ccache-install:
1087 $(MAKE) -C $(MU_BUILD_ROOT_DIR) ccache-build
1088 mkdir -p $(TOOL_INSTALL_DIR)/ccache-bin
1089 ln -sf $(MU_BUILD_ROOT_DIR)/build-tool-native/ccache/ccache \
Dave Barach952ec0e2020-02-28 09:50:33 -05001090 $(TOOL_INSTALL_DIR)/ccache-bin/$(TARGET_PREFIX)gcc
Ed Warnickecb9cada2015-12-08 15:45:58 -07001091
1092TOOL_MAKE = $(MAKE) is_build_tool=yes
1093
1094tool_make_target_fn = \
1095 $(if $(strip $(NATIVE_TOOLS)), \
1096 $(TOOL_MAKE) $(patsubst %,%-$(1),$(NATIVE_TOOLS)) ARCH=native || exit 1 ;) \
1097 $(TOOL_MAKE) $(patsubst %,%-$(1),$(CROSS_TOOLS))
1098
1099.PHONY: install-tools
1100install-tools:
1101 $(call tool_make_target_fn,install)
1102
1103.PHONY: bootstrap-tools
1104bootstrap-tools:
1105 $(TOOL_MAKE) make-install findutils-install git-install \
1106 automake-install autoconf-install libtool-install fakeroot-install
1107
1108
1109######################################################################
1110# Clean
1111######################################################################
1112
1113package_clean_script = \
1114 @$(call build_msg_fn, Cleaning $* in $(PACKAGE_INSTALL_DIR)) ; \
1115 $(BUILD_ENV) ; \
1116 $(if $(is_build_tool),,rm -rf $(PACKAGE_INSTALL_DIR) ;) \
1117 rm -rf $(TIMESTAMP_DIR)/$(call timestamp_name_fn,*) ; \
1118 $(if $($(PACKAGE)_clean), \
1119 $($(PACKAGE)_clean), \
1120 $(PACKAGE_MAKE) clean)
1121
1122.PHONY: %-clean
1123%-clean:
1124 $(package_clean_script)
1125
1126# Wipe e.g. remove build and install directories for packages.
1127package_wipe_script = \
1128 @message=$(if $(is_build_tool),"Wiping build $(PACKAGE)","Wiping build/install $(PACKAGE)") ; \
1129 $(call build_msg_fn,$$message) ; \
1130 $(BUILD_ENV) ; \
Damjan Marion6bbf83a2017-01-10 10:39:21 +01001131 rm -rf $(if $(is_build_tool),$(PACKAGE_BUILD_DIR),$(PACKAGE_INSTALL_DIR) $(PACKAGE_BUILD_DIR))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001132
1133.PHONY: %-wipe
1134%-wipe:
1135 $(package_wipe_script)
1136
1137# Wipe entire build/install area for TAG and PLATFORM
1138.PHONY: wipe-all
1139wipe-all:
1140 @$(call build_msg_fn, Wiping $(BUILD_DIR) $(INSTALL_DIR)) ; \
1141 $(BUILD_ENV) ; \
1142 rm -rf $(BUILD_DIR) $(INSTALL_DIR)
1143
1144# Clean everything
1145distclean:
1146 rm -rf $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_package)*/
1147 rm -rf $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_tool)*
1148 rm -rf $(MU_BUILD_ROOT_DIR)/$(INSTALL_PREFIX)*
1149 rm -rf $(MU_BUILD_ROOT_DIR)/$(IMAGES_PREFIX)*
1150 rm -rf $(TOOL_INSTALL_DIR)
1151 rm -rf $(MU_BUILD_ROOT_DIR)/*.deb
Ed Warnicke46040a52016-03-22 12:52:22 -05001152 rm -rf $(MU_BUILD_ROOT_DIR)/*.rpm
Ed Warnickecb9cada2015-12-08 15:45:58 -07001153 rm -rf $(MU_BUILD_ROOT_DIR)/*.changes
Dave Barach952ec0e2020-02-28 09:50:33 -05001154 rm -rf $(MU_BUILD_ROOT_DIR)/*.buildinfo