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