blob: 04c9f8b49fa8605f945a844de720bafe0eec370e [file] [log] [blame]
#
# Copyright (c) 2010-2012 Nest Labs, Inc.
# All rights reserved.
#
# This document is the property of Nest. It is considered
# confidential and proprietary information.
#
# This document may not be reproduced or transmitted in any form,
# in whole or in part, without the express written permission of
# Nest.
#
# Description:
# This file is the makefile for the Linux kernel.
#
include pre.mak
PackageRoot := .
PackageName := linux
PackageSeparator :=
PackageSourceDir := $(PackageRoot)/$(PackageName)
PackageBuildConfig := $(call GenerateBuildPaths,.config)
PackageBuildMakefile := $(call GenerateBuildPaths,Makefile)
CleanPaths += $(PackageLicenseFile)
#
# Configuration
#
# Kernel default configuration is handled from most-specific to
# least-specific, as follows:
#
# Out-of-tree:
#
# 1) If configs/$(BuildProduct)/$(BuildConfig)_defconfig exists,
# it is used.
# 2) If configs/$(BuildProduct)/defconfig exists, it is used.
# 3) If configs/$(BuildConfig)_defconfig exists, it is used.
# 4) If configs/defconfig exists, it is used.
#
# In-tree:
#
# 5) If none of those exist, $(LinuxDefaultConfig) is used, which
# refers to an architecture- and/or board-specific default
# configuration.
#
# We go through this elaborate scheme because, once created, the
# kernel loses all association with it configuration file and the
# source it was created from. As a consequence, if the default
# configuration is edited, the kernel doesn't know about the
# change. This is especially problematic when changing branches or
# receiving updates to the default configuration and the kernel
# doesn't rebuild to reflect those changes.
#
# With this scheme, the user can edit .config as before. However, now
# if the default configuration is changed, out-of-tree only, .config
# is updated and the kernel will rebuild to reflect those changes.
#
PackageConfigDir := configs
PackageDefaultConfig := $(LinuxDefaultConfig)
PackageProjectConfig := $(PackageConfigDir)/defconfig
PackageConfigConfig := $(PackageConfigDir)/$(BuildConfig)_defconfig
PackageProductConfig := $(PackageConfigDir)/$(BuildProduct)/defconfig
PackageProductConfigConfig := $(PackageConfigDir)/$(BuildProduct)/$(BuildConfig)_defconfig
PackageMaybeProjectConfig := $(wildcard $(PackageProjectConfig))
PackageMaybeConfigConfig := $(wildcard $(PackageConfigConfig))
PackageMaybeProductConfig := $(wildcard $(PackageProductConfig))
PackageMaybeProductConfigConfig := $(wildcard $(PackageProductConfigConfig))
PackageMaybeConfig := $(if $(PackageMaybeProductConfigConfig),$(PackageProductConfigConfig),$(if $(PackageMaybeProductConfig),$(PackageProductConfig),$(if $(PackageMaybeConfigConfig),$(PackageConfigConfig),$(if $(PackageMaybeProjectConfig),$(PackageProjectConfig),))))
PackageSourceConfig := $(if $(PackageMaybeConfig),$(PackageMaybeConfig),)
#
# Specific products may want additional build targets beyond those
# produced by the linux build's 'all' target. Process and establish
# those.
#
LinuxAllTarget := all
LinuxBuildTargets := $(filter-out $(LinuxAllTarget),$(LinuxProductTargets)) $(LinuxAllTarget)
#
# For some architectures, the linux build requires u-boot's host
# 'mkimage' tool. Establish some paths and directories that will be
# used, if present, to help the linux build find it.
#
MkimagePath := $(wildcard $(call GenerateResultPaths,fw/u-boot/bin,mkimage))
MkimageDir := $(call Deslashify,$(dir $(MkimagePath)))
#
# Architecture-specific boot images that may need to be copied from
# the build to the result directory.
#
LinuxBootFolder = arch/$(LinuxProductArch)/boot
LinuxBootDir = $(call GenerateBuildPaths,$(LinuxBootFolder))
LinuxBootBuildPaths = $(call GenerateBuildPaths,$(addprefix $(LinuxBootFolder)/,$(LinuxProductBootFiles)))
LinuxBootResultPaths = $(call GenerateResultPaths,,$(notdir $(LinuxBootBuildPaths)))
LinuxKernelFiles = vmlinux
LinuxKernelFolder = .
LinuxKernelDir = $(call GenerateBuildPaths,$(LinuxKernelFolder))
LinuxKernelBuildPaths = $(call GenerateBuildPaths,$(addprefix $(call Slashify,$(LinuxKernelFolder)),$(LinuxKernelFiles)))
LinuxKernelResultPaths = $(call GenerateResultPaths,,$(notdir $(LinuxKernelBuildPaths)))
#
# Common make arguments shared by all Linux target commands
#
LinuxCommonMakeArgs = -C $(PackageSourceDir) O=$(CURDIR)/$(BuildDirectory) ARCH=$(LinuxProductArch)
define echo-defconfig
$(Echo) "The default Linux build configuration is \"$(if $(PackageSourceConfig),$(PackageSourceConfig),$(PackageDefaultConfig))\"."
endef
all: $(PackageDefaultGoal)
# Generate the package license contents.
$(PackageSourceDir)/COPYING: source
$(PackageLicenseFile): $(PackageSourceDir)/COPYING
$(copy-result)
# We are building this package from version-controller source, so
# there is nothing to do for this target goal.
$(PackageSourceDir):
# Prepare the sources.
.PHONY: source
source: | $(PackageSourceDir)
# Patch the sources, if necessary.
.PHONY: patch
patch: source
# The Linux kernel build has no way of explicitly setting CC, LD,
# OBJCOPY, et al and instead relies on the value of
# CROSS_COMPILE. Consequently, we have to ensure that 'ToolBinDir' is
# in 'PATH' so that the kernel build infrastructure can find
# $(CROSS_COMPILE)gcc, $(CROSS_COMPILE)ld, et al.
#
# Additionally, per the above, add the path to U-Boot's 'mkimage' if
# the variable is defined.
configure build images stage stage-modules: PATH := $(PATH):$(ToolBinDir)$(if $(MkimageDir),:$(MkimageDir),)
# Generate the Linux build configuration and make file
#
# We are either copying and out-of-tree configuration or using an
# in-tree default (see above).
# $(PackageBuildConfig): help-defconfig
$(PackageBuildConfig): $(PackageSourceConfig) | $(PackageSourceDir) $(BuildDirectory)
$(echo-defconfig)
$(if $(PackageSourceConfig),$(copy-result),$(Verbose)$(MAKE) $(LinuxCommonMakeArgs) $(LinuxDefaultConfig))
# Configure the source for building.
.PHONY: configure
configure: source $(PackageBuildConfig)
# Build the source.
.PHONY: build
build: configure images
# Build the linux kernel images, including vmlinux (ELF).
.PHONY: images
images: configure | $(BuildDirectory)
$(Verbose)$(MAKE) $(LinuxCommonMakeArgs) $(LinuxBuildTargets)
# Stage the build to a temporary installation area.
.PHONY: stage stage-boot stage-modules stage-headers
stage: stage-boot stage-modules stage-headers
stage-boot stage-modules stage-headers: build | $(ResultDirectory)
stage-modules:
$(Verbose)$(MAKE) $(LinuxCommonMakeArgs) INSTALL_MOD_PATH=$(ResultDirectory) DEPMOD=$(DEPMOD) modules_install
stage-headers:
$(Verbose)$(MAKE) $(LinuxCommonMakeArgs) INSTALL_HDR_PATH=$(ResultDirectory) headers_install
$(LinuxBootResultPaths): $(ResultDirectory)/%: $(LinuxBootDir)/%
$(copy-result)
$(LinuxKernelResultPaths): $(ResultDirectory)/%: $(LinuxKernelDir)/%
$(copy-result)
stage-boot: $(LinuxBootResultPaths) $(LinuxKernelResultPaths)
clean:
$(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
$(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
.PHONY: help help-defconfig
help-defconfig:
$(echo-defconfig)
help: help-defconfig
include post.mak