blob: ed25a0cc06d00870beb01eecf6d50b50e3b04c48 [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
168x86_64_libdir = $(BIARCH)
169native_libdir = $($(NATIVE_ARCH)_libdir)
170
171# lib or lib64 depending
172arch_lib_dir = lib$($(BASIC_ARCH)_libdir)
173
174# OS to configure for. configure --host will be set to $(ARCH)-$(OS)
175OS = mu-linux
176
177spu_target = spu
178native_target =
179
180is_native = $(if $(ARCH:native=),,true)
181not_native = $(if $(ARCH:native=),true,)
182
183ARCH_TARGET_tmp = $(call ifdef_fn,$(ARCH)_target,$(ARCH)-$(OS))
184TARGET = $(call ifdef_fn,$(PLATFORM)_target,$(ARCH_TARGET_tmp))
185TARGET_PREFIX = $(if $(not_native),$(TARGET)-,)
186
187# CPU microarchitecture detection.
188# Either set <platform>_march in build-data/platforms/<platform>.mk,
189# or detect and use the build-host instruction set
190
191MARCH = $(strip $($(PLATFORM)_march))
192ifeq ($(MARCH),)
193 ifneq ($(wildcard $(TOOL_INSTALL_DIR)/bin/$(TARGET)-gcc),)
194 TARGET_GCC = $(TOOL_INSTALL_DIR)/bin/$(TARGET)-gcc
195 else ifneq ($(wildcard $(MU_BUILD_ROOT_DIR)/tools/bin/$(TARGET)-gcc),)
196 TARGET_GCC = $(MU_BUILD_ROOT_DIR)/tools/bin/$(TARGET)-gcc
197 endif
198 ifneq ($(TARGET_GCC),)
199 MARCH = $(shell $(TARGET_GCC) -Q --help=target -march=native | grep march | sed -e 's/.*march=[[:space:]]*//')
200 else
201 MARCH = native
202 endif
203else
204 ifeq ($(MARCH),nehalem)
205 override MARCH = corei7
206 else ifeq ($(MARCH),westmere)
207 override MARCH = corei7
208 else ifeq ($(MARCH),sandybridge)
209 override MARCH = corei7-avx
210 else ifeq ($(MARCH),ivybridge)
211 override MARCH = core-avx-i
212 else ifeq ($(MARCH),haswell)
213 override MARCH = core-avx2
214 endif
215endif
216export MARCH
217
218######################################################################
219# Generic build stuff
220######################################################################
221
222# The package we are currently working on
223PACKAGE = $*
224
225# Build/install tags. This lets you have different CFLAGS/CPPFLAGS/LDFLAGS
226# for e.g. debug versus optimized compiles. Each tag has its own set of build/install
227# areas.
228TAG =
229TAG_PREFIX = $(if $(TAG),$(TAG)-)
230
231# yes you need the space
232tag_var_with_added_space_fn = $(if $($(TAG)_TAG_$(1)),$($(TAG)_TAG_$(1)) )
233
234# TAG=debug for debugging
235debug_TAG_CFLAGS = -g -O0 -DCLIB_DEBUG -march=$(MARCH)
236debug_TAG_LDFLAGS = -g -O0 -DCLIB_DEBUG -march=$(MARCH)
237
238# TAG=prof for profiling
239prof_TAG_CFLAGS = -g -pg -O2
240prof_TAG_LDFLAGS = -g -pg -O2
241
242# TAG=o0
243o0_TAG_CFLAGS = -g -O0
244o1_TAG_LDFLAGS = -g -O0
245
246# TAG=o1
247o1_TAG_CFLAGS = -g -O1
248o1_TAG_LDFLAGS = -g -O1
249
250# TAG=o2
251o2_TAG_CFLAGS = -g -O2
252o2_TAG_LDFLAGS = -g -O2
253
254# TAG=o3
255o3_TAG_CFLAGS = -g -O3
256o3_TAG_LDFLAGS = -g -O3
257
258BUILD_PREFIX_package = build-$(TAG_PREFIX)
259BUILD_PREFIX_tool = build-tool-$(TAG_PREFIX)
260INSTALL_PREFIX = install-$(TAG_PREFIX)
261IMAGES_PREFIX = images-$(TAG_PREFIX)
262
263# Whether we are building a tool or not
264tool_or_package_fn = $(if $(is_build_tool),tool,package)
265
266# Directory where packages are built & installed
267BUILD_DIR = $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_$(call tool_or_package_fn))$(ARCH)
268
269## BURT
270# we will deprecate INSTALL_DIR shortly for DFLT_INSTALL_DIR
271INSTALL_DIR = $(MU_BUILD_ROOT_DIR)/$(INSTALL_PREFIX)$(ARCH)
272# DFLT_INSTALL_DIR used in platforms.mk for $(PLATFORM)_DESTDIR_BASE
273DFLT_INSTALL_DIR := $(MU_BUILD_ROOT_DIR)/$(INSTALL_PREFIX)$(ARCH)
274## BURT
275
276PLATFORM_IMAGE_DIR = $(MU_BUILD_ROOT_DIR)/$(IMAGES_PREFIX)$(PLATFORM)
277
278# $(call VAR,DEFAULT)
279override_var_with_default_fn = $(if $($(1)),$($(1)),$(2))
280
281# $(call if_directory_exists_fn,D1,D2) returns D1 if it exists else D2
282define if_directory_exists_fn
283$(shell if test -d $(1); then echo $(1); else echo $(2); fi)
284endef
285
286# $(call if_file_exists_fn,F1,F2) returns F1 if it exists else F2
287define if_file_exists_fn
288$(shell if test -f $(1); then echo $(1); else echo $(2); fi)
289endef
290
291# Default VAR, package specified override of default PACKAGE_VAR
292package_var_fn = $(call override_var_with_default_fn,$(1)_$(2),$(1))
293
294package_build_dir_fn = $(call package_var_fn,$(1),build_dir)
295
296package_install_dir_fn = \
297 $(if $(is_build_tool),$(TOOL_INSTALL_DIR),$(INSTALL_DIR)/$(call package_build_dir_fn,$(1)))
298
299PACKAGE_BUILD_DIR = \
300 $(BUILD_DIR)/$(call package_build_dir_fn,$(PACKAGE))
301PACKAGE_INSTALL_DIR = \
302 $(call package_install_dir_fn,$(PACKAGE))
303
304# Tools (gcc, binutils, glibc...) are installed here
305TOOL_INSTALL_DIR = $(MU_BUILD_ROOT_DIR)/tools
306
307# Target specific tools go here e.g. mu-build/tools/ppc-mu-linux
308TARGET_TOOL_INSTALL_DIR = $(TOOL_INSTALL_DIR)/$(TARGET)
309
310# Set BUILD_DEBUG to vx or x enable shell command tracing.
311BUILD_DEBUG =
312
313# Message from build system itself (as opposed to make or shell commands)
314build_msg_fn = echo "@@@@ $(1) @@@@"
315
316# Always prefer our own tools to those installed on system.
317# Note: ccache-bin must be before tool bin.
318BUILD_ENV = \
319 export CCACHE_DIR=$(MU_BUILD_ROOT_DIR)/.ccache ; \
320 export PATH=$(TOOL_INSTALL_DIR)/ccache-bin:$(TOOL_INSTALL_DIR)/bin:$${PATH} ; \
321 export PATH="`echo $${PATH} | sed -e s/[.]://`" ; \
322 $(if $(not_native),export CONFIG_SITE=$(MU_BUILD_ROOT_DIR)/config.site ;,) \
323 export LD_LIBRARY_PATH=$(TOOL_INSTALL_DIR)/lib64:$(TOOL_INSTALL_DIR)/lib ; \
324 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
336### BURT
337
338#next version
339#pkgPhaseDependMacro = $(foreach x,configure build install, \
340 $(eval $(1)_$(x)_depend := $($(1)_depend:%=%-$(x))))
341#version equivalent to original code
342pkgPhaseDependMacro = $(eval $(1)_configure_depend := $($(1)_depend:%=%-install))
343
344### BURT
345
346# Pick up built-root/pre-package-include.mk for all source directories
347$(foreach d,$(SOURCE_PATH_BUILD_ROOT_DIRS), \
348 $(eval -include $(d)/pre-package-include.mk))
349
350$(foreach d,$(addsuffix /packages,$(FIND_SOURCE_PATH)), \
351 $(eval -include $(d)/*.mk) \
352 $(eval ALL_PACKAGES += $(patsubst $(d)/%.mk,%,$(wildcard $(d)/*.mk))) \
353)
354
355# Pick up built-root/post-package-include.mk for all source directories
356$(foreach d,$(SOURCE_PATH_BUILD_ROOT_DIRS), \
357 $(eval -include $(d)/post-package-include.mk))
358
359# Linux specific native build tools
360NATIVE_TOOLS_LINUX = \
361 e2fsimage \
362 e2fsprogs \
363 fakeroot \
364 jffs2 \
365 mkimage \
366 zlib \
367 xz \
368 squashfs
369
370IS_LINUX = $(if $(findstring no,$($(PLATFORM)_uses_linux)),no,yes)
371
372NATIVE_TOOLS_$(IS_LINUX) += $(NATIVE_TOOLS_LINUX)
373
374# only build glibc for linux installs
375CROSS_TOOLS_$(IS_LINUX) += glibc gcc
376
377# must be first for bootstrapping
378NATIVE_TOOLS = findutils make
379
380# basic tools needed for build system
381NATIVE_TOOLS += git automake autoconf libtool texinfo bison flex tar
382
383# needed to compile gcc
384NATIVE_TOOLS += mpfr gmp mpc
385
386# Tool to sign binaries
387NATIVE_TOOLS += sign
388
389# ccache
390NATIVE_TOOLS += ccache
391
392# Tools needed on native host to build for platform
393NATIVE_TOOLS += $(call ifdef_fn,$(PLATFORM)_native_tools,)
394
395# Tools for cross-compiling from native -> ARCH
396CROSS_TOOLS = binutils gcc-bootstrap gdb
397
398# Tools needed on native host to build for platform
399CROSS_TOOLS += $(call ifdef_fn,$(PLATFORM)_cross_tools,)
400
401NATIVE_TOOLS += $(NATIVE_TOOLS_yes)
402CROSS_TOOLS += $(CROSS_TOOLS_yes)
403
404timestamp_name_fn = .mu_build_$(1)_timestamp
405CONFIGURE_TIMESTAMP = $(call timestamp_name_fn,configure)
406BUILD_TIMESTAMP = $(call timestamp_name_fn,build)
407INSTALL_TIMESTAMP = $(call timestamp_name_fn,install)
408
409TIMESTAMP_DIR = $(PACKAGE_BUILD_DIR)
410
411find_newer_files_fn = \
412 "`for i in $(2) ; do \
413 [[ -f $$i && $$i -nt $(1) ]] && echo "$$i" && exit 0; \
414 done ; \
415 exit 0;`"
416
417find_filter = -not -name '*~'
418find_filter += -and -not -path '*/.git*'
419find_filter += -and -not -path '*/.svn*'
420find_filter += -and -not -path '*/.CVS*'
421find_filter += -and -not -path '*/manual/*'
422find_filter += -and -not -path '*/autom4te.cache/*'
423find_filter += -and -not -path '*/doc/all-cfg.texi'
424find_filter += -and -not -path '*/.mu_build_*'
425
426find_newer_filtered_fn = \
427 (! -f $(1) \
428 || -n $(call find_newer_files_fn,$(1),$(3)) \
429 || -n "`find -H $(2) \
430 -type f \
431 -and -newer $(1) \
432 -and \( $(4) \) \
433 -print -quit`")
434
435find_newer_fn = \
436 $(call find_newer_filtered_fn,$(1),$(2),$(3),$(find_filter))
437
438######################################################################
439# Package dependencies
440######################################################################
441
442# This must come before %-configure, %-build, %-install pattern rules
443# or else dependencies will not work.
444
445package_dependencies_fn = \
446 $(patsubst %-install, %, \
447 $(filter %-install,$($(1)_configure_depend)))
448
449PACKAGE_DEPENDENCIES = $(call package_dependencies_fn,$(PACKAGE))
450
451# package specific configure, build, install dependencies
452add_package_dependency_fn = \
453 $(if $($(1)_$(2)_depend), \
454 $(eval $(1)-$(2) : $($(1)_$(2)_depend)))
455
456$(foreach p,$(ALL_PACKAGES), \
457 $(call add_package_dependency_fn,$(p),configure) \
458 $(call add_package_dependency_fn,$(p),build) \
459 $(call add_package_dependency_fn,$(p),install))
460
461TARGETS_RESPECTING_DEPENDENCIES = image_install wipe diff push-all pull-all find-source
462
463# carry over packages dependencies to image install, wipe, pull-all, push-all
464$(foreach p,$(ALL_PACKAGES), \
465 $(if $($(p)_configure_depend), \
466 $(foreach s,$(TARGETS_RESPECTING_DEPENDENCIES), \
467 $(eval $(p)-$(s): \
468 $(addsuffix -$(s), $(call package_dependencies_fn,$(p)))))))
469
470# recursively resolve dependencies
471resolve_dependencies2_fn = $(strip \
472 $(eval __added = $(filter-out $(4), \
473 $(call uniq_fn, \
474 $(foreach l,$(3), \
475 $(call ifdef3_fn,$(l)$(1),,$(call $(2),$($(l)$(1)))) \
476 )))) \
477 $(eval __known = $(call uniq_fn,$(4) $(3) $(__added))) \
478 $(if $(__added), \
479 $(call resolve_dependencies2_fn,$(1),$(2),$(__added),$(__known)), \
480 $(__known)) \
481)
482
483resolve_dependencies_null_fn = $(1)
484
485resolve_dependencies_fn = $(call resolve_dependencies2_fn,$(1),resolve_dependencies_null_fn,$(2))
486
487######################################################################
488# Package configure
489######################################################################
490
491# x86_64 can be either 32/64. set BIACH=32 to get 32 bit libraries.
492BIARCH = 64
493
494x86_64_libdir = $(BIARCH)
495native_libdir = $($(NATIVE_ARCH)_libdir)
496
497# lib or lib64 depending
498arch_lib_dir = lib$($(BASIC_ARCH)_libdir)
499
500# find dynamic linker as absolute path
501TOOL_INSTALL_LIB_DIR=$(TOOL_INSTALL_DIR)/$(TARGET)/$(arch_lib_dir)
502DYNAMIC_LINKER=${shell cd $(TOOL_INSTALL_LIB_DIR); echo ld*.so.*}
503
504# Pad dynamic linker & rpath so elftool will never have to change ELF section sizes.
505# Yes, this is a kludge.
506lots_of_slashes_to_pad_names = "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"
507
508# When PLATFORM != native we *always* use our own versions of GLIBC and dynamic linker
509CROSS_LDFLAGS = \
510 -Wl,--dynamic-linker=$(lots_of_slashes_to_pad_names)$(TOOL_INSTALL_LIB_DIR)/$(DYNAMIC_LINKER) \
511 -Wl,-rpath -Wl,$(lots_of_slashes_to_pad_names)$(TOOL_INSTALL_LIB_DIR)
512
513cross_ldflags = $(if $(is_native)$(is_build_tool),,$(CROSS_LDFLAGS) )
514
515# $(call installed_libs_fn,PACKAGE)
516# Return install library directory for given package.
517# Some packages (e.g. openssl) don't install under lib64; instead they use lib
518define installed_lib_fn
519$(call if_directory_exists_fn,
520 $(call package_install_dir_fn,$(1))/$(arch_lib_dir),
521 $(call package_install_dir_fn,$(1))/lib)
522endef
523
524# Set -L and rpath to point to dependent libraries previously built by us.
525installed_libs_fn = \
526 $(foreach i,$(1), \
527 -L$(call installed_lib_fn,$(i)) \
528 -Wl,-rpath -Wl,$(call installed_lib_fn,$(i)))
529
530# As above for include files
531installed_include_fn = $(call package_install_dir_fn,$(1))/include
532
533installed_includes_fn = $(foreach i,$(1),-I$(call installed_include_fn,$(i)))
534
535# By default package CPPFLAGS (to set include path -I) and LDFLAGS (to set link path -L)
536# point at dependent install directories.
537DEFAULT_CPPFLAGS = $(call installed_includes_fn, $(PACKAGE_DEPENDENCIES))
538DEFAULT_LDFLAGS = $(call installed_libs_fn, $(PACKAGE_DEPENDENCIES))
539
540configure_var_fn = \
541 $(call tag_var_with_added_space_fn,$(1))$(call override_var_with_default_fn,$(PACKAGE)_$(1),$(DEFAULT_$(1)))
542configure_ldflags_fn = \
543 $(cross_ldflags)$(call configure_var_fn,LDFLAGS)
544
545# Allow packages to override CPPFLAGS, CFLAGS, and LDFLAGS
546CONFIGURE_ENV = \
547 $(if $(call configure_var_fn,CPPFLAGS), \
548 CPPFLAGS="$(CPPFLAGS) $(call configure_var_fn,CPPFLAGS)") \
549 $(if $(call configure_var_fn,CFLAGS), \
550 CFLAGS="$(CFLAGS) $(call configure_var_fn,CFLAGS)") \
551 $(if $(call configure_var_fn,CCASFLAGS), \
552 CCASFLAGS="$(CCASFLAGS) $(call configure_var_fn,CCASFLAGS)") \
553 $(if $(call configure_ldflags_fn), \
554 LDFLAGS="$(LDFLAGS) $(call configure_ldflags_fn)") \
555 $(if $($(PACKAGE)_configure_env),$($(PACKAGE)_configure_env))
556
557### BURT
558# only partially used now (used in a few .mk files)
559ifeq ($(is_build_tool),yes)
560prefix = $(PACKAGE_INSTALL_DIR)
561libdir = $(PACKAGE_INSTALL_DIR)/$(arch_lib_dir)
562libexecdir = $(PACKAGE_INSTALL_DIR)/usr/libexec
563DESTDIR = /
564else
565# Eventually simplify this with no per package DESTDIR or prefix
566ppdMacro = $(if $(PER_PACKAGE_DESTDIR),$(call package_build_dir_fn,$(1)))
567pppMacro = $(if $(PER_PACKAGE_PREFIX),$(call package_build_dir_fn,$(1)))
568prefixMacro = $($(PLATFORM)_PREFIX_BASE)/$(pppMacro)
569prefix = $(call prefixMacro,$(PACKAGE))
570libdir = $($(PLATFORM)_LIBDIR)
571libexecdir = $($(PLATFORM)_LIBEXECDIR)
572destdirMacro = $($(PLATFORM)_DESTDIR_BASE)$(ppdMacro)
573DESTDIR = $(call destdirMacro,$(PACKAGE))
574endif
575### BURT
576### dbarach
577image_extra_dependencies = $($(PLATFORM)_image_extra_dependencies)
578### dbarach
579
580configure_package_gnu = \
581 s=$(call find_source_fn,$(PACKAGE_SOURCE)) ; \
582 if [ ! -f $$s/configure ] ; then \
583 autoreconf -i -f $$s ; \
584 fi ; \
585 cd $(PACKAGE_BUILD_DIR) ; \
586 env $(CONFIGURE_ENV) \
587 $$s/configure \
588 $(if $($(PACKAGE)_configure_host_and_target), \
589 $($(PACKAGE)_configure_host_and_target), \
590 $(if $(not_native),--host=$(TARGET),)) \
591 $(if $($(PACKAGE)_configure_prefix), \
592 $($(PACKAGE)_configure_prefix), \
593 --libdir=$(PACKAGE_INSTALL_DIR)/$(arch_lib_dir) \
594 --prefix=$(PACKAGE_INSTALL_DIR)) \
595 $($(PACKAGE)_configure_args) \
596 $($(PACKAGE)_configure_args_$(PLATFORM))
597
598configure_package = \
599 $(call build_msg_fn,Configuring $(PACKAGE) in $(PACKAGE_BUILD_DIR)) ; \
600 mkdir -p $(PACKAGE_BUILD_DIR) ; \
601 $(if $($(PACKAGE)_configure), \
602 $($(PACKAGE)_configure), \
603 $(configure_package_gnu))
604
605# Tools (e.g. gcc, binutils, gdb) required a platform to build for
606check_platform = \
607 is_tool="$(is_build_tool)" ; \
608 is_cross_package="$(findstring $(PACKAGE),$(CROSS_TOOLS))" ; \
609 is_arch_native="$(if $(subst native,,$(ARCH)),,yes)" ; \
610 if [ "$${is_tool}" == "yes" \
611 -a "$${is_cross_package}" != "" \
612 -a "$${is_arch_native}" != "" ]; then \
613 $(call build_msg_fn,You must specify PLATFORM for building tools) ; \
614 exit 1 ; \
615 fi ; \
616 : check that platform gcc can be found ; \
617 target_gcc=gcc ; \
618 if [ "$${is_arch_native}" != "yes" ] ; then \
619 target_gcc=$(TARGET)-gcc ; \
620 fi ; \
621 if [ "$${is_tool}" != "yes" \
622 -a "$${is_arch_native}" != "yes" \
623 -a ! -x "`which 2> /dev/null $${target_gcc}`" ] ; then \
624 $(call build_msg_fn, \
625 No cross-compiler found for platform $(PLATFORM) target $(TARGET); \
626 try make PLATFORM=$(PLATFORM) install-tools) ; \
627 exit 1 ; \
628 fi
629
630configure_check_timestamp = \
631 @$(BUILD_ENV) ; \
632 $(check_platform) ; \
633 mkdir -p $(PACKAGE_BUILD_DIR) ; \
634 mkdir -p $(PACKAGE_INSTALL_DIR) ; \
635 conf="$(TIMESTAMP_DIR)/$(CONFIGURE_TIMESTAMP)" ; \
636 dirs="$(call package_mk_fn,$(PACKAGE)) \
637 $(wildcard $(call find_source_fn,$(PACKAGE_SOURCE))/configure) \
638 $(MU_BUILD_ROOT_DIR)/config.site" ; \
639 if [[ $(call find_newer_fn, $${conf}, $${dirs}, $?) ]]; then \
640 $(configure_package) ; \
641 touch $${conf} ; \
642 else \
643 $(call build_msg_fn,Configuring $(PACKAGE): nothing to do) ; \
644 fi
645
646.PHONY: %-configure
647%-configure: %-find-source
648 $(configure_check_timestamp)
649
650######################################################################
651# Package build
652######################################################################
653
654linux_n_cpus = `grep '^processor' /proc/cpuinfo | wc -l`
655
656MAKE_PARALLEL_JOBS = \
657 -j $(shell \
658 if [ -f /proc/cpuinfo ] ; then \
659 expr 4 '*' $(linux_n_cpus) ; \
660 else \
661 echo 1 ; \
662 fi)
663
664MAKE_PARALLEL_FLAGS = $(if $($(PACKAGE)_make_parallel_fails),,$(MAKE_PARALLEL_JOBS))
665
666# Make command shorthand for packages & tools.
667PACKAGE_MAKE = \
668 $(MAKE) \
669 -C $(PACKAGE_BUILD_DIR) \
670 $($(PACKAGE)_make_args) \
671 $(MAKE_PARALLEL_FLAGS)
672
673build_package = \
674 $(call build_msg_fn,Building $* in $(PACKAGE_BUILD_DIR)) ; \
675 mkdir -p $(PACKAGE_BUILD_DIR) ; \
676 cd $(PACKAGE_BUILD_DIR) ; \
677 $(if $($(PACKAGE)_build), \
678 $($(PACKAGE)_build), \
679 $(PACKAGE_MAKE))
680
681build_check_timestamp = \
682 @$(BUILD_ENV) ; \
683 comp="$(TIMESTAMP_DIR)/$(BUILD_TIMESTAMP)" ; \
684 conf="$(TIMESTAMP_DIR)/$(CONFIGURE_TIMESTAMP)" ; \
685 dirs="$(call find_source_fn,$(PACKAGE_SOURCE)) \
686 $($(PACKAGE)_build_timestamp_depends) \
687 $(if $(is_build_tool),,$(addprefix $(INSTALL_DIR)/,$(PACKAGE_DEPENDENCIES)))" ; \
688 if [[ $${conf} -nt $${comp} \
689 || $(call find_newer_fn, $${comp}, $${dirs}, $?) ]]; then \
690 $(build_package) ; \
691 touch $${comp} ; \
692 else \
693 $(call build_msg_fn,Building $(PACKAGE): nothing to do) ; \
694 fi
695
696.PHONY: %-build
697%-build: %-configure
698 $(build_check_timestamp)
699
700.PHONY: %-rebuild
701%-rebuild: %-wipe %-build
702 @ :
703
704######################################################################
705# Package install
706######################################################################
707
708install_package = \
709 : by default, for non-tools, remove any previously installed bits ; \
710 $(if $(is_build_tool)$($(PACKAGE)_keep_instdir), \
711 true, \
712 rm -rf $(PACKAGE_INSTALL_DIR)); \
713 mkdir -p $(PACKAGE_INSTALL_DIR) ; \
714 $(if $($(PACKAGE)_pre_install),$($(PACKAGE)_pre_install),true); \
715 $(if $($(PACKAGE)_install), \
716 $($(PACKAGE)_install), \
717 $(PACKAGE_MAKE) \
718 $($(PACKAGE)_install_args) \
719 install) ; \
720 $(if $($(PACKAGE)_post_install),$($(PACKAGE)_post_install),true)
721
722install_check_timestamp = \
723 @$(BUILD_ENV) ; \
724 inst=$(TIMESTAMP_DIR)/$(INSTALL_TIMESTAMP) ; \
725 dirs="$(PACKAGE_BUILD_DIR) \
726 $($(PACKAGE)_install_dependencies)" ; \
727 if [[ $(call find_newer_fn, $${inst}, $${dirs}, $?) ]]; then \
728 $(call build_msg_fn,Installing $(PACKAGE)) ; \
729 $(install_package) ; \
730 touch $${inst} ; \
731 else \
732 $(call build_msg_fn,Installing $(PACKAGE): nothing to do) ; \
733 fi
734
735.PHONY: %-install
736%-install: %-build
737 $(install_check_timestamp)
738
739######################################################################
740# Source code managment
741######################################################################
742
743GIT = git
744
745# Maps package name to source directory root.
746# Multiple packages may use a single source tree.
747# For example, gcc-bootstrap package shares gcc source.
748PACKAGE_SOURCE = $(if $($(PACKAGE)_source),$($(PACKAGE)_source),$(PACKAGE))
749
750# Use git to download source if directory is not found
751find_source_for_package = \
752 @$(BUILD_ENV) ; \
753 $(call build_msg_fn,Arch for platform '$(PLATFORM)' is $(ARCH)) ; \
754 $(call build_msg_fn,Finding source for $(PACKAGE)) ; \
755 s="$(call find_source_fn,$(PACKAGE_SOURCE))" ; \
756 [[ -z "$${s}" ]] \
757 && $(call build_msg_fn,Package $(PACKAGE) not found with path $(SOURCE_PATH)) \
758 && exit 1; \
759 mk="$(call find_build_data_dir_for_package_fn,$(PACKAGE_SOURCE))/packages/$(PACKAGE).mk"; \
760 $(call build_msg_fn,Makefile fragment found in $${mk}) ; \
761 if [ ! -d "$${s}" ] ; then \
762 d=`dirname $${mk}` ; \
763 i=`cd $${d}/.. && ($(GIT) config remote.origin.url || \
764 awk '/URL/ { print $$2; }' .git/remotes/origin)`; \
765 g=`dirname $${i}` ; \
766 $(call build_msg_fn,Fetching source: $(GIT) clone $${g}/$(PACKAGE_SOURCE) $$s) ; \
767 if ! $(GIT) clone $${g}/$(PACKAGE_SOURCE) $$s; then \
768 $(call build_msg_fn,No source for $(PACKAGE) in $${g}); \
769 exit 1; \
770 fi ; \
Dave Barach7210e942015-12-15 18:57:51 -0500771 $(call build_msg_fn,Fix file dates in $${g}/$(PACKAGE_SOURCE)) ; \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700772 (cd $${s} ; $(MU_BUILD_ROOT_DIR)/autowank --touch) ; \
773 fi ; \
774 s=`cd $${s} && pwd` ; \
775 $(call build_msg_fn,Source found in $${s})
776
777.PHONY: %-find-source
778%-find-source:
779 $(find_source_for_package)
780
781.PHONY: %-push %-pull %-push-all %-pull-all
782%-push %-pull %-push-all %-pull-all:
783 @$(BUILD_ENV) ; \
784 push_or_pull=$(patsubst %-all,%,$(subst $(PACKAGE)-,,$@)) ; \
785 $(call build_msg_fn,Git $${push_or_pull} source for $(PACKAGE)) ; \
786 s=$(call find_source_fn,$(PACKAGE_SOURCE)) ; \
787 if [ "x$$s" = "x" ]; then \
788 $(call build_msg_fn,No source for $(PACKAGE)) ; \
789 exit 1; \
790 fi ; \
791 cd $$s && $(GIT) $${push_or_pull}
792
793# Pull all packages for platform
794.PHONY: pull-all
795pull-all:
796 @$(BUILD_ENV) ; \
797 $(call build_msg_fn,Git pull build system) ; \
798 for d in $(MU_BUILD_ROOT_DIR) \
799 $(SOURCE_PATH_BUILD_ROOT_DIRS) \
800 $(SOURCE_PATH_BUILD_DATA_DIRS); do \
801 $(call build_msg_fn,Git pull $${d}) ; \
802 pushd $${d} >& /dev/null && $(GIT) pull && popd >& /dev/null ; \
803 done ; \
804 $(call build_msg_fn,Git pull build tools) ; \
805 $(call tool_make_target_fn,pull-all) ; \
806 $(call build_msg_fn,Git pull packages for platform $(PLATFORM)) ; \
807 make PLATFORM=$(PLATFORM) $(patsubst %,%-pull-all,$(ROOT_PACKAGES))
808
809.PHONY: %-diff
810%-diff:
811 @$(BUILD_ENV) ; \
812 d=$(call find_source_fn,$(PACKAGE_SOURCE)) ; \
813 $(call build_msg_fn,Git diff $(PACKAGE)) ; \
814 if [ -d $${d}/.git ] ; then \
815 cd $${d} && $(GIT) --no-pager diff 2>/dev/null; \
816 else \
817 $(call build_msg_fn, $(PACKAGE) not a git directory) ; \
818 fi
819
820
821
822# generate diffs for everything in source path
823.PHONY: diff-all
824diff-all:
825 @$(BUILD_ENV) ; \
826 $(call build_msg_fn,Generate diffs) ; \
827 for r in $(ABSOLUTE_SOURCE_PATH); do \
828 for d in $${r}/* ; do \
829 if [ -d $${d} ] ; then \
830 $(call build_msg_fn,Git diff $${d}) ; \
831 if [ -d $${d}/.git ] ; then \
832 cd $${d} && $(GIT) --no-pager diff 2>/dev/null; \
833 else \
834 $(call build_msg_fn, $${d} not a git directory) ; \
835 fi ; \
836 fi ; \
837 done ; \
838 done
839
840######################################################################
841# System images
842######################################################################
843
844IMAGE_DIR = $(MU_BUILD_ROOT_DIR)/image-$(PLATFORM)
845
846# Reports shared libraries in given directory
847find_shared_libs_fn = \
848 find $(1) \
849 -maxdepth 1 \
850 -regex '.*/lib[a-z0-9_]+\+?\+?.so' \
851 -o -regex '.*/lib[a-z0-9_]+-[0-9.]+\+?\+?.so' \
852 -o -regex '.*/lib[a-z0-9_]+\+?\+?.so.[0-9.]+'
853
854# By default pick up files from binary directories and /etc.
855# Also include shared libraries.
856DEFAULT_IMAGE_INCLUDE = \
857 for d in bin sbin libexec \
858 usr/bin usr/sbin usr/libexec \
859 etc; do \
860 [[ -d $$d ]] && echo $$d; \
861 done ; \
862 [[ -d $(arch_lib_dir) ]] \
863 && $(call find_shared_libs_fn,$(arch_lib_dir))
864
865# Define any shell functions needed by install scripts
866image_install_functions = \
867 $(foreach p,$(ALL_PACKAGES), \
868 $(if $($(p)_image_install_functions), \
869 $($(p)_image_install_functions)))
870
871# Should always be over-written by temp dir in %-root-image rule
872IMAGE_INSTALL_DIR = $(error you need to set IMAGE_INSTALL_DIR)
873
874image_install_fn = \
875 @$(BUILD_ENV) ; \
876 $(call build_msg_fn,Image-install $(1) for platform $(PLATFORM)) ; \
877 inst_dir=$(IMAGE_INSTALL_DIR) ; \
878 mkdir -p $${inst_dir} ; \
879 cd $(2) ; \
880 : select files to include in image ; \
881 image_include_files=" \
882 `$(call ifdef_fn,$(1)_image_include,$(DEFAULT_IMAGE_INCLUDE)) ; \
883 echo "" ; \
884 exit 0 ; `"; \
885 : select files regexps to exclude from image ; \
886 image_exclude_files="" ; \
887 if [ ! -z "$($(1)_image_exclude)" ] ; then \
888 image_exclude_files="${image_exclude_files} \
889 $(patsubst %,--exclude=%,$($(1)_image_exclude))" ; \
890 fi ; \
891 [[ -z "$${image_include_files}" || $${image_include_files} == " " ]] \
892 || tar cf - $${image_include_files} $${image_exclude_files} \
893 | tar xf - -C $${inst_dir} ; \
894 : copy files from copyimg directories on source path if present ; \
895 for build_data_dir in $(SOURCE_PATH_BUILD_DATA_DIRS) ; do \
896 d="$${build_data_dir}/packages/$(1).copyimg" ; \
897 if [ -d "$${d}" ] ; then \
898 env $($(PLATFORM)_copyimg_env) \
899 $(MU_BUILD_ROOT_DIR)/copyimg $${d} $${inst_dir} ; \
900 fi ; \
901 done ; \
902 : run package dependent install script ; \
903 $(if $($(1)_image_install), \
904 $(image_install_functions) \
905 cd $${inst_dir} ; \
906 $($(1)_image_install))
907
908.PHONY: %-image_install
909%-image_install: %-install
910 $(call image_install_fn,$(PACKAGE),$(PACKAGE_INSTALL_DIR))
911
912basic_system_image_include = \
913 $(call ifdef_fn,$(PLATFORM)_basic_system_image_include, \
914 echo bin/ldd ; \
915 echo $(arch_lib_dir)/ld*.so* ; \
916 $(call find_shared_libs_fn, $(arch_lib_dir)))
917
918basic_system_image_install = \
919 mkdir -p bin lib mnt proc root sbin sys tmp etc ; \
920 mkdir -p usr usr/{bin,sbin} usr/lib ; \
921 mkdir -p var var/{lib,lock,log,run,tmp} ; \
922 mkdir -p var/lock/subsys var/lib/urandom
923
924.PHONY: basic_system-image_install
925basic_system-image_install: # linuxrc-install
926 $(if $(not_native), \
927 $(call image_install_fn,basic_system,$(TARGET_TOOL_INSTALL_DIR)),)
928
929ROOT_PACKAGES = $(if $($(PLATFORM)_root_packages),$($(PLATFORM)_root_packages),$(default_root_packages))
930
931.PHONY: install-packages
932install-packages: $(patsubst %,%-find-source,$(ROOT_PACKAGES))
933 @$(BUILD_ENV) ; \
934 set -eu$(BUILD_DEBUG) ; \
935 d=$(MU_BUILD_ROOT_DIR)/packages-$(PLATFORM) ; \
936 rm -rf $${d} ; \
937 mkdir -p $${d}; \
938 $(MAKE) -C $(MU_BUILD_ROOT_DIR) IMAGE_INSTALL_DIR=$${d} \
939 $(patsubst %,%-image_install, \
940 basic_system \
941 $(ROOT_PACKAGES)) || exit 1; \
942 $(call build_msg_fn, Relocating ELF executables to run in $${d}) ; \
943 find $${d} -type f \
944 -exec elftool quiet in '{}' out '{}' \
945 set-interpreter \
946 $${d}/$(arch_lib_dir)/$(DYNAMIC_LINKER) \
947 set-rpath $${d}/$(arch_lib_dir):$${d}/lib ';' ; \
948 : strip symbols from files ; \
949 if [ $${strip_symbols:-no} = 'yes' ] ; then \
950 $(call build_msg_fn, Stripping symbols from files) ; \
951 find $${d} -type f \
952 -exec \
953 $(TARGET_PREFIX)strip \
954 --strip-unneeded '{}' ';' \
955 >& /dev/null ; \
956 else \
957 $(call build_msg_fn, NOT stripping symbols) ; \
958 fi
959
960# readonly root squashfs image
961# Note: $(call build_msg_fn) does not seem to work inside of fakeroot so we use echo
962.PHONY: ro-image
963$(PLATFORM_IMAGE_DIR)/ro.img ro-image: $(patsubst %,%-find-source,$(ROOT_PACKAGES))
964 @$(BUILD_ENV) ; \
965 d=$(PLATFORM_IMAGE_DIR) ; \
966 mkdir -p $$d; \
967 ro_image=$$d/ro.img ; \
968 rm -f $${ro_image} ; \
969 tmp_dir="`mktemp -d $$d/ro-image-XXXXXX`" ; \
970 chmod 0755 $${tmp_dir} ; \
971 cd $${tmp_dir} ; \
972 trap "rm -rf $${tmp_dir}" err ; \
973 fakeroot /bin/bash -c "{ \
974 set -eu$(BUILD_DEBUG) ; \
975 $(MAKE) -C $(MU_BUILD_ROOT_DIR) IMAGE_INSTALL_DIR=$${tmp_dir} \
976 $(patsubst %,%-image_install, \
977 basic_system \
978 $(ROOT_PACKAGES)) ; \
979 : make dev directory ; \
980 $(linuxrc_makedev) ; \
981 echo @@@@ Relocating ELF executables to run in / @@@@ ; \
982 find $${d} -type f \
983 -exec elftool quiet in '{}' out '{}' \
984 set-interpreter \
985 /$(arch_lib_dir)/$(DYNAMIC_LINKER) \
986 set-rpath /$(arch_lib_dir):/lib ';' ; \
987 : strip symbols from files ; \
988 if [ '$${strip_symbols:-yes}' = 'yes' ] ; then \
989 echo @@@@ Stripping symbols from files @@@@ ; \
990 find $${tmp_dir} -type f \
991 -exec \
992 $(TARGET_PREFIX)strip \
993 --strip-unneeded '{}' ';' \
994 >& /dev/null ; \
995 else \
996 echo @@@@ NOT stripping symbols @@@@ ; \
997 fi ; \
998 if [ $${sign_executables:-yes} = 'yes' \
999 -a -n "$($(PLATFORM)_public_key)" ] ; then \
1000 echo @@@@ Signing executables @@@@ ; \
1001 find $${tmp_dir} -type f \
1002 | xargs sign $($(PLATFORM)_public_key) \
1003 $($(PLATFORM)_private_key_passphrase) ; \
1004 fi ; \
1005 : make read-only file system ; \
1006 mksquashfs \
1007 $${tmp_dir} $${ro_image} \
1008 -no-exports -no-progress -no-recovery ; \
1009 }" ; \
1010 : cleanup tmp directory ; \
1011 rm -rf $${tmp_dir}
1012
1013MKFS_JFFS2_BYTE_ORDER_x86_64 = -l
1014MKFS_JFFS2_BYTE_ORDER_i686 = -l
1015MKFS_JFFS2_BYTE_ORDER_ppc = -b
1016MKFS_JFFS2_BYTE_ORDER_mips = -b
1017MKFS_JFFS2_BYTE_ORDER_native = $(MKFS_JFFS2_BYTE_ORDER_$(NATIVE_ARCH))
1018
1019MKFS_JFFS2_SECTOR_SIZE_IN_KBYTES = \
1020 $(call ifdef_fn,$(PLATFORM)_jffs2_sector_size_in_kbytes,256)
1021
1022mkfs_fn_jffs2 = mkfs.jffs2 \
1023 --eraseblock=$(MKFS_JFFS2_SECTOR_SIZE_IN_KBYTES)KiB \
1024 --root=$(1) --output=$(2) \
1025 $(MKFS_JFFS2_BYTE_ORDER_$(BASIC_ARCH))
1026
1027# As things stand the actual initrd size parameter
1028# is set in .../open-repo/build-data/packages/linuxrc.mk.
1029EXT2_RW_IMAGE_SIZE=notused
1030
1031mkfs_fn_ext2 = \
1032 e2fsimage -d $(1) -f $(2) -s $(EXT2_RW_IMAGE_SIZE)
1033
1034RW_IMAGE_TYPE=jffs2
1035
1036make_rw_image_fn = \
1037 $(call mkfs_fn_$(RW_IMAGE_TYPE),$(1),$(2))
1038
1039rw_image_embed_ro_image_fn = \
1040 mkdir -p proc initrd images ro rw union ; \
1041 cp $(PLATFORM_IMAGE_DIR)/$(1) images/$(1) ; \
1042 md5sum images/$(1) > images/$(1).md5 ; \
1043 echo Built by $(LOGNAME) at `date` > images/$(1).stamp ; \
1044 mkdir -p changes/$(1)
1045
1046# make sure RW_IMAGE_TYPE is a type we know how to build
1047.PHONY: rw-image-check-type
1048rw-image-check-type:
1049 @$(BUILD_ENV) ; \
1050 if [ -z "$(make_rw_image_fn)" ] ; then \
1051 $(call build_msg_fn,Unknown read/write fs image type; \
1052 try RW_IMAGE_TYPE=ext2 or RW_IMAGE_TYPE=jffs2) ; \
1053 exit 1; \
1054 fi
1055
1056# read write image
1057.PHONY: rw-image
1058rw-image: rw-image-check-type ro-image
1059 @$(BUILD_ENV) ; \
1060 d=$(PLATFORM_IMAGE_DIR) ; \
1061 mkdir -p $$d ; \
1062 rw_image="$$d/rw.$(RW_IMAGE_TYPE)" ; \
1063 ro_image="ro.img" ; \
1064 rm -f $$rw_image ; \
1065 tmp_dir="`mktemp -d $$d/rw-image-XXXXXX`" ; \
1066 chmod 0755 $${tmp_dir} ; \
1067 cd $${tmp_dir} ; \
1068 trap "rm -rf $${tmp_dir}" err ; \
1069 fakeroot /bin/bash -c "{ \
1070 set -eu$(BUILD_DEBUG) ; \
1071 $(linuxrc_makedev) ; \
1072 $(call rw_image_embed_ro_image_fn,$${ro_image}) ; \
1073 $(call make_rw_image_fn,$${tmp_dir},$${rw_image}) ; \
1074 }" ; \
1075 : cleanup tmp directory ; \
1076 rm -rf $${tmp_dir}
1077
1078images: linuxrc-install linux-install $(image_extra_dependencies) rw-image
1079 @$(BUILD_ENV) ; \
1080 d=$(PLATFORM_IMAGE_DIR) ; \
1081 cd $(BUILD_DIR)/linux-$(PLATFORM) ; \
1082 i="" ; \
1083 [[ -z $$i && -f bzImage ]] && i=bzImage ; \
1084 [[ -z $$i && -f zImage ]] && i=zImage ; \
1085 [[ -z $$i && -f linux ]] && i=linux ; \
1086 [[ -z $$i && -f vmlinux ]] && i=vmlinux ; \
1087 [[ -z $$i ]] \
1088 && $(call build_msg_fn,no linux image to install \
1089 in $(BUILD_DIR)/linux-$(PLATFORM)) \
1090 && exit 1 ; \
1091 cp $$i $$d
1092
1093######################################################################
1094# Tool chain build/install
1095######################################################################
1096
1097.PHONY: ccache-install
1098ccache-install:
1099 $(MAKE) -C $(MU_BUILD_ROOT_DIR) ccache-build
1100 mkdir -p $(TOOL_INSTALL_DIR)/ccache-bin
1101 ln -sf $(MU_BUILD_ROOT_DIR)/build-tool-native/ccache/ccache \
1102 $(TOOL_INSTALL_DIR)/ccache-bin/$(TARGET_PREFIX)gcc
1103
1104TOOL_MAKE = $(MAKE) is_build_tool=yes
1105
1106tool_make_target_fn = \
1107 $(if $(strip $(NATIVE_TOOLS)), \
1108 $(TOOL_MAKE) $(patsubst %,%-$(1),$(NATIVE_TOOLS)) ARCH=native || exit 1 ;) \
1109 $(TOOL_MAKE) $(patsubst %,%-$(1),$(CROSS_TOOLS))
1110
1111.PHONY: install-tools
1112install-tools:
1113 $(call tool_make_target_fn,install)
1114
1115.PHONY: bootstrap-tools
1116bootstrap-tools:
1117 $(TOOL_MAKE) make-install findutils-install git-install \
1118 automake-install autoconf-install libtool-install fakeroot-install
1119
1120
1121######################################################################
1122# Clean
1123######################################################################
1124
1125package_clean_script = \
1126 @$(call build_msg_fn, Cleaning $* in $(PACKAGE_INSTALL_DIR)) ; \
1127 $(BUILD_ENV) ; \
1128 $(if $(is_build_tool),,rm -rf $(PACKAGE_INSTALL_DIR) ;) \
1129 rm -rf $(TIMESTAMP_DIR)/$(call timestamp_name_fn,*) ; \
1130 $(if $($(PACKAGE)_clean), \
1131 $($(PACKAGE)_clean), \
1132 $(PACKAGE_MAKE) clean)
1133
1134.PHONY: %-clean
1135%-clean:
1136 $(package_clean_script)
1137
1138# Wipe e.g. remove build and install directories for packages.
1139package_wipe_script = \
1140 @message=$(if $(is_build_tool),"Wiping build $(PACKAGE)","Wiping build/install $(PACKAGE)") ; \
1141 $(call build_msg_fn,$$message) ; \
1142 $(BUILD_ENV) ; \
1143 rm -rf $(if $(is_build_tool),$(PACKAGE_BUILD_DIR),$(PACKAGE_INSTALL_DIR) $(PACKAGE_BUILD_DIR))
1144
1145.PHONY: %-wipe
1146%-wipe:
1147 $(package_wipe_script)
1148
1149# Wipe entire build/install area for TAG and PLATFORM
1150.PHONY: wipe-all
1151wipe-all:
1152 @$(call build_msg_fn, Wiping $(BUILD_DIR) $(INSTALL_DIR)) ; \
1153 $(BUILD_ENV) ; \
1154 rm -rf $(BUILD_DIR) $(INSTALL_DIR)
1155
1156# Clean everything
1157distclean:
1158 rm -rf $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_package)*/
1159 rm -rf $(MU_BUILD_ROOT_DIR)/$(BUILD_PREFIX_tool)*
1160 rm -rf $(MU_BUILD_ROOT_DIR)/$(INSTALL_PREFIX)*
1161 rm -rf $(MU_BUILD_ROOT_DIR)/$(IMAGES_PREFIX)*
1162 rm -rf $(TOOL_INSTALL_DIR)
1163 rm -rf $(MU_BUILD_ROOT_DIR)/*.deb
1164 rm -rf $(MU_BUILD_ROOT_DIR)/*.changes
1165 (cd $(MU_BUILD_ROOT_DIR)/deb/;debian/rules clean)
1166 rm -f $(MU_BUILD_ROOT_DIR)/deb/debian/*.install
1167 rm -f $(MU_BUILD_ROOT_DIR)/deb/debian/*.dkms
1168 rm -f $(MU_BUILD_ROOT_DIR)/deb/debian/changelog