The BSP Makefile

Every BSP has a Makefile in its base directory and can have other Makefiles in subdirectories.

The BSP Makefile defines the following targets:

all

Invokes the install, links, and images targets, if more than one target image is defined in the BSP Makefile.

If you don't specify a target, make defaults to this target.

prebuilt

Recursively copies the prebuilt directory's contents to the install directory.

install

Invokes the prebuilt target, then performs the following in the src directory:

  • make hinstall to copy all public headers from src into the install directory.

  • make install to build all binaries in src and copy the results into the install directory.

This target also adds a buildfile to the BSP's images directory using one of the following methods:

  • Copying the default buildfile from src/hardware/startup/boards/board/build to install/${CPU_VARIANT}/boot/build/ and renaming it board.build. A symlink that points to board.build is added to the BSP's images directory.
  • The buildfile is derived from the BSP packaging and manifest information. It is placed in the images directory, but is not a copy or symlink.
links

Creates a symbolic link (a “copy” on Windows) from install/cpu/boot/build/board.build to images/board.build.

images

Changes to the images directory, then runs the Makefile in that directory. This Makefile creates an IFS file based on the buildfile linked in during the make links target.

Any extra work required (e.g., IPL padding, conversion to an alternate format) is also handled from within this Makefile.

Note: If you don't specify a target, make defaults to the all option.

For more information about makefiles in general, see the GNU website at www.gnu.org/.

Sample Makefile

Below is a sample BSP Makefile for an ARM board. Note that the image building process uses additional Makefiles, such as the /images/Makefile (see Product-specific targets), to build the final target image:

# This is the top-level Makefile for all source packages.
# It makes all the code in the "src" directory, then installs it
# in the "install" directory, then makes the images in
# the images directory (if present).

ROOT_DIR := $(notdir $(CURDIR))
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
unexport ROOT_DIR

.PHONY: all install clean links make_links dummy images prebuilt binaries

# Expands to a single newline character
define NEWLINE


endef

SUFFIXES := .mk

all: install links $(if $(wildcard images/*),images)
	@echo done

subdirs:=$(subst /Makefile,,$(wildcard */[Mm]akefile))

clean:
	$(foreach dir,$(subdirs), $(MAKE) -C$(dir) clean $(NEWLINE))
	-$(RM_HOST) -r install/*

install: $(if $(wildcard prebuilt/*),prebuilt)
	$(MAKE) -Csrc hinstall
	$(MAKE) -Csrc

#
# Have to invoke "make_links" target because the first make expands
# the $(wildcard ...) too soon - we might not have copied things into
# the "install" tree yet.
#
links:
	$(MAKE) make_links

make_links:
	$(foreach file,$(wildcard install/*/boot/build/*),cd images;$(LN_HOST) ../$(file) $(notdir $(file));cd ..; )

images:
	$(MAKE) -Cimages

prebuilt:
	cp -rf prebuilt/* install

For information about the make utility, see make in the Utilities Reference; for information about the qconfig utility, see qconfig in the Utilities Reference.

Product-specific targets

Some BSPs may be delivered with more than one possible target image already configured. For example, a BSP for the NEXCOM VTC 1010, includes a Makefile that defines a target image for the BSP with Screen Graphics Subsystem support, and a target image without Screen support. The Makefile in the BSP's /images directory defines two targets. You can generate either image, or both:

all
Invokes both targets.
ifs-target.format
Invokes the build without Screen support, where target is the name of your platform (e.g., imx6-sabresmart).
ifs-target-graphics
Invokes the build with Screen support, where target is the name of your platform (e.g., imx6-sabresmart-graphics).

Below is the source for the Makefile. You can use it as a model if you need to modify a BSP to produce more than one target image:

ROOT_DIR := $(notdir $(CURDIR))
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)

HOST_MKIFS := mkifs

SUFFIXES := .build .ifs .raw

.PHONY: all clean

all: ifs-nexcom-vtc1010.bin  ifs-nexcom-vtc1010-graphics.bin

clean:
	$(RM_HOST) ifs-nexcom-vtc1010.bin
	$(RM_HOST) ifs-nexcom-vtc1010-graphics.bin

ifs-nexcom-vtc1010.bin: nexcom-vtc1010.build
	$(HOST_MKIFS) -r../install -v $(MKIFSFLAGS) $^ $@

ifs-nexcom-vtc1010-graphics.bin: nexcom-vtc1010-graphics.build
	$(HOST_MKIFS) -r../install -v $(MKIFSFLAGS) $^ $@