Petr Šabata f5bf49
TEST_CASE ?=
Petr Šabata f5bf49
BASE_IMAGE ?=
Petr Šabata f5bf49
Petr Šabata f5bf49
TEST_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
Petr Šabata f5bf49
BUILD_ROOT := $(TEST_ROOT)/build
Petr Šabata f5bf49
REPO = $(shell realpath $(TEST_ROOT)/../)
Petr Šabata f5bf49
ARCH ?= $(shell arch)
Petr Šabata f5bf49
SPEC = kexec-tools.spec
Petr Šabata f5bf49
Petr Šabata f5bf49
DIST ?= fedora
Petr Šabata f5bf49
DIST_ABR ?= f
Petr Šabata f5bf49
DIST_ABRL ?= fc
Petr Šabata f5bf49
DIST_UNSET ?= rhel
DistroBaker 17a515
RELEASE ?= 33
Petr Šabata f5bf49
DistroBaker 17a515
DEFAULT_BASE_IMAGE_VER ?= 1.2
Petr Šabata f5bf49
DEFAULT_BASE_IMAGE ?= Fedora-Cloud-Base-$(RELEASE)-$(DEFAULT_BASE_IMAGE_VER).$(ARCH).raw.xz
Petr Šabata f5bf49
DEFAULT_BASE_IMAGE_URL ?= https://dl.fedoraproject.org/pub/fedora/linux/releases/$(RELEASE)/Cloud/$(ARCH)/images/$(DEFAULT_BASE_IMAGE)
Petr Šabata f5bf49
Petr Šabata f5bf49
BUILD_ROOT = $(TEST_ROOT)/build
Petr Šabata f5bf49
RPMDEFINE = --define '_sourcedir $(REPO)'\
Petr Šabata f5bf49
	    --define '_specdir $(REPO)'\
Petr Šabata f5bf49
	    --define '_builddir $(BUILD_ROOT)'\
Petr Šabata f5bf49
	    --define '_srcrpmdir $(BUILD_ROOT)'\
Petr Šabata f5bf49
	    --define '_rpmdir $(BUILD_ROOT)'\
Petr Šabata f5bf49
	    --define 'dist %{?distprefix}.$(DIST_ABRL)$(RELEASE)'\
Petr Šabata f5bf49
	    --define '$(DIST) $(RELEASE)'\
Petr Šabata f5bf49
	    --eval '%undefine $(DIST_UNSET)'\
Petr Šabata f5bf49
	    --define '$(DIST_ABRL)$(RELEASE) 1'\
Petr Šabata f5bf49
Petr Šabata f5bf49
KEXEC_TOOLS_SRC = $(filter-out $(REPO)/tests,$(wildcard $(REPO)/*))
Petr Šabata f5bf49
KEXEC_TOOLS_TEST_SRC = $(wildcard $(REPO)/tests/scripts/**/*)
Petr Šabata f5bf49
KEXEC_TOOLS_NVR = $(shell rpm $(RPMDEFINE) -q --specfile $(REPO)/$(SPEC) 2>/dev/null | grep -m 1 .)
Petr Šabata f5bf49
KEXEC_TOOLS_RPM = $(BUILD_ROOT)/$(ARCH)/$(KEXEC_TOOLS_NVR).rpm
Petr Šabata f5bf49
Petr Šabata f5bf49
all: $(TEST_ROOT)/output/test-base-image
Petr Šabata f5bf49
Petr Šabata f5bf49
# Use either:
Petr Šabata f5bf49
# fedpkg --release $(DIST_ABR)$(RELEASE) --path ../../ local
Petr Šabata f5bf49
# or
Petr Šabata f5bf49
# rpmbuild $(RPMDEFINE) -ba $(REPO)/$(SPEC)
Petr Šabata f5bf49
# to rebuild the rpm, currently use rpmbuild to have better control over the rpm building process
Petr Šabata f5bf49
#
Petr Šabata f5bf49
$(KEXEC_TOOLS_RPM): $(KEXEC_TOOLS_SRC)
Petr Šabata f5bf49
	sh -c "cd .. && fedpkg sources"
Petr Šabata f5bf49
	@echo Rebuilding RPM due to modification of sources: $?
Petr Šabata f5bf49
	rpmbuild $(RPMDEFINE) -ba $(REPO)/$(SPEC)
Petr Šabata f5bf49
Petr Šabata f5bf49
$(BUILD_ROOT)/base-image:
Petr Šabata f5bf49
	mkdir -p $(BUILD_ROOT)
Petr Šabata f5bf49
ifeq ($(strip $(BASE_IMAGE)),)
Petr Šabata f5bf49
	wget $(DEFAULT_BASE_IMAGE_URL) -O $(BUILD_ROOT)/$(DEFAULT_BASE_IMAGE)
Petr Šabata f5bf49
	$(TEST_ROOT)/scripts/build-image.sh \
Petr Šabata f5bf49
		$(BUILD_ROOT)/$(DEFAULT_BASE_IMAGE)\
Petr Šabata f5bf49
		$(BUILD_ROOT)/base-image
Petr Šabata f5bf49
else
Petr Šabata f5bf49
	$(TEST_ROOT)/scripts/build-image.sh \
Petr Šabata f5bf49
		$(BASE_IMAGE)\
Petr Šabata f5bf49
		$(BUILD_ROOT)/base-image
Petr Šabata f5bf49
endif
Petr Šabata f5bf49
Petr Šabata f5bf49
$(BUILD_ROOT)/inst-base-image: $(BUILD_ROOT)/base-image
Petr Šabata f5bf49
	@echo "Building installation base image"
Petr Šabata f5bf49
	echo $(KEXEC_TOOLS_NVR)
Petr Šabata f5bf49
	$(TEST_ROOT)/scripts/build-image.sh \
Petr Šabata f5bf49
		$(BUILD_ROOT)/base-image \
Petr Šabata f5bf49
		$(BUILD_ROOT)/inst-base-image \
Petr Šabata f5bf49
		$(TEST_ROOT)/scripts/build-scripts/base-image.sh
Petr Šabata f5bf49
Petr Šabata f5bf49
$(TEST_ROOT)/output/test-base-image: $(BUILD_ROOT)/inst-base-image $(KEXEC_TOOLS_RPM) $(KEXEC_TOOLS_TEST_SRC)
Petr Šabata f5bf49
	@echo "Building test base image"
Petr Šabata f5bf49
	mkdir -p $(TEST_ROOT)/output
Petr Šabata f5bf49
	$(TEST_ROOT)/scripts/build-image.sh \
Petr Šabata f5bf49
		$(BUILD_ROOT)/inst-base-image \
Petr Šabata f5bf49
		$(TEST_ROOT)/output/test-base-image \
Petr Šabata f5bf49
		$(TEST_ROOT)/scripts/build-scripts/test-base-image.sh \
Petr Šabata f5bf49
		$(KEXEC_TOOLS_RPM)
Petr Šabata f5bf49
Petr Šabata f5bf49
test-run: $(TEST_ROOT)/output/test-base-image
Petr Šabata f5bf49
ifeq ($(strip $(TEST_CASE)),)
Petr Šabata f5bf49
	$(TEST_ROOT)/scripts/run-test.sh
Petr Šabata f5bf49
else
Petr Šabata f5bf49
	$(TEST_ROOT)/scripts/run-test.sh --console $(TEST_CASE)
Petr Šabata f5bf49
endif
Petr Šabata f5bf49
Petr Šabata f5bf49
clean:
Petr Šabata f5bf49
	rm -rf $(TEST_ROOT)/build
Petr Šabata f5bf49
	rm -rf $(TEST_ROOT)/output