default: all

SQUASHFS_VERSION=4

# Include mkimage config file with default definitions
include /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=/home/builder/mkimage-profiles-plc-LP8x81
include functions.mk

PROFILE=1
VERBOSE=1
GLOBAL_VERBOSE=1
GLOBAL_HSH_APT_CONFIG=/etc/apt/apt.conf

IMAGE_INIT_LIST = +branding-altlinux-desktop-release
CHROOT_PACKAGES = apt-utils rsync \
		  kernel-image-rt-up \
		  memtest86+ \
		  branding-altlinux-desktop-bootloader \
		  branding-altlinux-desktop-bootsplash \
		  findutils \
		  bootsplash \
		  branding-altlinux-desktop-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_PUBL=$(INFO_ORIGIN)


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) $(shell ls .work/chroot/.image/ALTLinux/ | grep RPMS | sed 's/RPMS.//' | xargs echo) 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 /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 = /home/builder/out/desktop

disk-info:
	mkdir -p isofiles/.disk
	echo "$(PROPAGATOR_VERSION)" >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,$(GLOBAL_PKG_GROUPS)) \
	$(call group,$(GLOBAL_PKG_GROUPS)) \
	| isofiles/Metadata
	tar -cf $@ -C $(GLOBAL_PKGDIR) $(^:$(GLOBAL_PKGDIR)/%=%)

isofiles/Metadata:
	mkdir -p $@

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

make-outdir:
	mkdir -p /home/builder/out/desktop