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