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