Loading...
#!/usr/bin/make -f

# Use the system dtc if python3-libfdt is available, otherwise let
# U-Boot build its own dtc and pylibfdt (needed for Jammy)
ifneq (,$(shell python3 -c "import libfdt" 2>/dev/null && echo y))
export DTC=/usr/bin/dtc
endif

# Disable branch hardening to fix build failure of arch:all build
# https://bugs.debian.org/1052724
export DEB_BUILD_MAINT_OPTIONS=hardening=-branch

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

DEBIAN_REVISION ?= $(shell echo $(DEB_VERSION) | sed -e 's,.*-,-,')

include debian/targets.mk

# Enable verbose build by default, disable when terse is specified.
ifneq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
VERBOSE=0
else
VERBOSE=1
endif
common_make_args += V=$(VERBOSE)
common_make_args += BINMAN_DEBUG=1
common_make_args += BINMAN_VERBOSE=3

# the upstream build passes LDFLAGS directly to ld instead of calling gcc for
# linking; so instead of passing -Wl,foo in LDFLAGS as in automake builds, one
# should set LDFLAGS to foo directly
comma := ,
LDFLAGS := $(patsubst -Wl$(comma)%,%,$(LDFLAGS))

HOSTCFLAGS := $(CFLAGS)
export HOSTCFLAGS

# Exclude package notes to avoid FTBFS on oracular
unexport ELF_PACKAGE_METADATA

%:
	dh $@

override_dh_auto_build-indep: u-boot-concept-qemu u-boot-concept-efi
override_dh_auto_build-arch:

.PHONY: u-boot-concept-qemu u-boot-concept-efi

define build_template

  # Tell Make to build the platform as part of the package.
  $(package): $(platform)

  $(platform):
	# debian/rules: building platform: $(platform)
	mkdir -p debian/build/$(platform)

	dh_auto_build -- $(common_make_args) \
	  O=debian/build/$(platform) \
	  CROSS_COMPILE=$(or $($(platform)_CROSS_COMPILE),$(CROSS_COMPILE)) \
	  $($(platform)_assigns) \
	  $(platform)_defconfig

	sed -i -e 's,^CONFIG_LOCALVERSION=.*,CONFIG_LOCALVERSION="$(DEBIAN_REVISION)",' \
	  -e 's,^CONFIG_RUST_EXAMPLES=y,# CONFIG_RUST_EXAMPLES is not set,' \
	  debian/build/$(platform)/.config

	dh_auto_build -- $(common_make_args) \
	  O=debian/build/$(platform) \
	  CROSS_COMPILE=$(or $($(platform)_CROSS_COMPILE),$(CROSS_COMPILE)) \
	  $($(platform)_assigns)

	# Upstream generates executable targets (last checked with 2020-10).
	chmod -x $(addprefix debian/build/$(platform)/,$($(platform)_targets))

  install-$(platform):
	dh_install -p$(package) $(addprefix debian/build/$(platform)/,$($(platform)_targets)) usr/lib/u-boot-concept/$(platform)

endef
$(foreach package, u-boot-concept-qemu u-boot-concept-efi,\
  $(foreach platform, $($(package)_platforms),\
    $(eval $(build_template))))

override_dh_auto_test-indep:
override_dh_auto_test-arch:

# Do not spend time searching for an install target in Makefile.
override_dh_auto_install:

execute_after_dh_install-indep: \
  $(addprefix install-,$(u-boot-concept-qemu_platforms)) installdocs-u-boot-concept-qemu \
  $(addprefix install-,$(u-boot-concept-efi_platforms)) installdocs-u-boot-concept-efi

installdocs-u-boot-concept-qemu:
	mkdir -p debian/build/u-boot-concept-qemu/configs
	for platform in $(u-boot-concept-qemu_platforms); do \
	  cp -u debian/build/$$platform/.config debian/build/u-boot-concept-qemu/configs/config.$$platform; \
	done
	dh_installdocs -pu-boot-concept-qemu debian/build/u-boot-concept-qemu/configs

installdocs-u-boot-concept-efi:
	mkdir -p debian/build/u-boot-concept-efi/configs
	for platform in $(u-boot-concept-efi_platforms); do \
	  cp -u debian/build/$$platform/.config debian/build/u-boot-concept-efi/configs/config.$$platform; \
	done
	dh_installdocs -pu-boot-concept-efi debian/build/u-boot-concept-efi/configs

override_dh_clean:
	rm -rf debian/build/
	dh_clean
	find . -type d -name __pycache__ -delete

override_dh_gencontrol:
	dh_gencontrol -- \
	  '-Vu-boot-concept-qemu:platforms=$(subst $() ,$${Newline},$(u-boot-concept-qemu_platforms))' \
	  '-Vu-boot-concept-efi:platforms=$(subst $() ,$${Newline},$(u-boot-concept-efi_platforms))'