default: all

SQUASHFS_VERSION=@SQUASHFS_VERSION@

# Include mkimage config file with default definitions
include @MKI_PREFIX@/usr/share/mkimage/config.mk

# Include autogenerated config file with necessary
# stages (components) for specific product.
# Not neccessary for clean family targets.
-include autocfg.mk

GLOBAL_PKGDIR = $(CURDIR)/pkg

# packagelist stuff
TOPDIR=@TOPDIR@
include functions.mk

PROFILE=1
VERBOSE=1
GLOBAL_VERBOSE=1
GLOBAL_HSH_APT_CONFIG=@APTCONF@

IMAGE_INIT_LIST = +branding-@BRANDING@-release
CHROOT_PACKAGES = apt-utils rsync \
		  kernel-image-@KERNEL@ \
		  kernel-modules-drm-@KERNEL@ \
		  kernel-modules-drm-radeon-@KERNEL@ \
		  memtest86+ \
		  branding-@BRANDING@-bootloader \
		  branding-@BRANDING@-bootsplash \
		  syslinux \
		  findutils \
		  file \
		  make-initrd make-initrd-nfs make-initrd-plymouth make-initrd-propagator \
		  firmware-linux firmware-aic94xx-seq \
		  propagator \
		  branding-@BRANDING@-notes \
		  pkg/lists/docs

CLEANUP_OUTDIR=

COPY_TREE=./isofiles

GLOBAL_BOOT_TYPE ?= isolinux
BOOT_TYPE = $(GLOBAL_BOOT_TYPE)
INFO_BOOT_TYPE = $(BOOT_TYPE)

ifeq "$(BOOT_TYPE)" "syslinux"
		MKI_PACK_RESULTS = boot:$(OUTNAME)
else
		MKI_PACK_RESULTS = $(shell [ -f .work/chroot/.image/syslinux/isolinux.cfg ] && echo boot || echo isodata):$(OUTNAME)
endif

BOOT_VOLS = $(INFO_VOLSETID)
BOOT_PUBL = $(INFO_PUBLISHER)
BOOT_APPI = $(INFO_APPI)
BOOT_PREP = $(INFO_PREP)


GLOBAL_PROPAGATOR_MAR_MODULES ?= ./modules
PROPAGATOR_MAR_MODULES = $(GLOBAL_PROPAGATOR_MAR_MODULES)

PROPAGATOR_INITFS = ./initfs
PROPAGATOR_VERSION = $(shell ls */.work/chroot/.image/etc/altlinux-release | head -1 | xargs -r cat) @ARCH@ build $(shell date +%F)

BOOT_VOLI = $(shell ls */.work/chroot/.image/etc/altlinux-release| head -1 | xargs -r cat)

INFO_PKG_GROUPS = $(GLOBAL_PKG_GROUPS)

# Include mkimage targets definitions
include @MKI_PREFIX@/usr/share/mkimage/targets.mk

update-tags:
	make -C pkg all

test-tags: update-tags
	make -C main test-tags

all: debug rm-pkg-groups update-tags \
	isofiles/Metadata/pkg-groups.tar copy-subdirs disk-info \
	copy-tree loader-cfg chmod-hook run-scripts \
	make-outdir pack-image rm-loader

debug:
	@echo CHROOT_PACKAGES=$(CHROOT_PACKAGES)

pack-image: OUTDIR = @OUTDIR@

disk-info:
	mkdir -p isofiles/.disk
	echo "$(PROPAGATOR_VERSION)" > isofiles/.disk/info
#	echo "$(BOOT_VOLI)" > isofiles/.disk/info;

rm-loader:
	rm -f isofiles/syslinux/{isolinux,syslinux}.cfg

rm-pkg-groups:
	rm -f isofiles/Metadata/pkg-groups.tar

loader-cfg: rm-loader
	cp -a isolinux .work/chroot/.in/
#	cp isolinux/$(BOOT_TYPE).cfg-$(MKI_OUTNAME) isofiles/syslinux/$(BOOT_TYPE).cfg

# see also alterator-pkg
isofiles/Metadata/pkg-groups.tar: \
	$(call list,.base) \
	$(call list,$(shell  grep X-Alterator-PackageList /dev/null $(call group,$(GLOBAL_PKG_GROUPS)) | cut -d= -f2)) \
	$(call group,$(GLOBAL_PKG_GROUPS)) \
	| isofiles/Metadata
	tar -cf $@ -C $(GLOBAL_PKGDIR) $(^:$(GLOBAL_PKGDIR)/%=%)

isofiles/Metadata:
	mkdir $@

chmod-hook:
	  chmod +x scripts.d/02-gfxboot
	  chmod +x scripts.d/05-copydocs

make-outdir:
	mkdir -p @OUTDIR@

