Add iso compression support.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-07-28 01:46:01 +02:00
parent e9e033212a
commit 5ee7ff4e67
4 changed files with 155 additions and 55 deletions

View File

@ -41,10 +41,11 @@ SORTIX_BUILDS_DIR?=builds
SORTIX_PORTS_DIR?=ports
SORTIX_RELEASE_DIR?=release
SORTIX_REPOSITORY_DIR?=repository
SORTIX_ISO_COMPRESSION?=xz
include build-aux/dirs.mak
BUILD_NAME:=sortix_$(VERSION)_$(MACHINE)
BUILD_NAME:=sortix-$(VERSION)-$(MACHINE)
INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).initrd
@ -179,7 +180,6 @@ sysroot-source: sysroot-fsh
cp Makefile -t "$(SYSROOT)/src"
cp README -t "$(SYSROOT)/src"
cp -RT build-aux "$(SYSROOT)/src/build-aux"
cp -RT isosrc "$(SYSROOT)/src/isosrc"
(for D in $(MODULES); do (cp -R $$D -t "$(SYSROOT)/src" && $(MAKE) -C "$(SYSROOT)/src/$$D" clean) || exit $$?; done)
(cd "$(SYSROOT)" && find .) | sed 's/\.//' | \
grep -E '^/src(/.*)?$$' | \
@ -227,7 +227,6 @@ clean-builds:
rm -f sortix.bin
rm -f sortix.initrd
rm -f sortix.iso
rm -f sortix.iso.xz
.PHONY: clean-release
clean-release:
@ -252,10 +251,10 @@ mostlyclean: clean-core clean-ports clean-builds clean-release clean-sysroot
distclean: clean-core clean-ports clean-builds clean-release clean-repository clean-sysroot
.PHONY: most-things
most-things: sysroot initrd tar iso
most-things: sysroot initrd iso
.PHONY: everything
everything: most-things iso.xz
everything: most-things
# Targets that build multiple architectures.
@ -321,7 +320,6 @@ $(INITRD): sysroot
echo "exclude /dev" >> $(INITRD).filter
echo "exclude /src/sysroot" >> $(INITRD).filter
echo "exclude /tmp" >> $(INITRD).filter
if ! which mkinitrd; then echo You need to install mkinitrd; fi
mkinitrd --format=sortix-initrd-2 --filter=$(INITRD).filter "$(SYSROOT)" "$(INITRD).live" -o $(INITRD)
rm -f $(INITRD).filter
rm -rf $(INITRD).live
@ -337,44 +335,36 @@ sortix.initrd: $(INITRD)
$(SORTIX_BUILDS_DIR):
mkdir -p $(SORTIX_BUILDS_DIR)
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz: sysroot $(INITRD) $(SORTIX_BUILDS_DIR)
rm -rf $(SORTIX_BUILDS_DIR)/tardir
mkdir -p $(SORTIX_BUILDS_DIR)/tardir
mkdir -p $(SORTIX_BUILDS_DIR)/tardir/boot
cp "$(SYSROOT)/boot/sortix.bin" $(SORTIX_BUILDS_DIR)/tardir/boot/sortix.bin
cp $(INITRD) $(SORTIX_BUILDS_DIR)/tardir/boot/sortix.initrd
tar --create --xz --file $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz -C $(SORTIX_BUILDS_DIR)/tardir `ls $(SORTIX_BUILDS_DIR)/tardir`
rm -rf $(SORTIX_BUILDS_DIR)/tardir
.PHONY: tar
tar: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz
# Bootable images
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso: sysroot $(INITRD) $(SORTIX_BUILDS_DIR)
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
cp -RT isosrc $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot
ifeq ($(SORTIX_ISO_COMPRESSION),xz)
xz -c "$(SYSROOT)/boot/sortix.bin" > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.bin.xz
xz -c $(INITRD) > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.initrd.xz
build-aux/iso-grub-cfg.sh --platform $(HOST) --version $(VERSION) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
grub-mkrescue --compress=xz -o $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
else ifeq ($(SORTIX_ISO_COMPRESSION),gzip)
gzip -c "$(SYSROOT)/boot/sortix.bin" > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.bin.gz
gzip -c $(INITRD) > $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.initrd.gz
build-aux/iso-grub-cfg.sh --platform $(HOST) --version $(VERSION) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
grub-mkrescue --compress=gz -o $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
else # none
cp "$(SYSROOT)/boot/sortix.bin" $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.bin
cp $(INITRD) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.initrd
build-aux/iso-grub-cfg.sh --platform $(HOST) --version $(VERSION) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
grub-mkrescue -o $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
endif
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_BUILDS_DIR)
xz -c $< > $@
.PHONY: iso
iso: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso
.PHONY: iso.xz
iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz
sortix.iso: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso
cp $< $@
sortix.iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz
cp $< $@
# Release
$(SORTIX_RELEASE_DIR)/$(VERSION):
@ -383,20 +373,14 @@ $(SORTIX_RELEASE_DIR)/$(VERSION):
$(SORTIX_RELEASE_DIR)/$(VERSION)/builds: $(SORTIX_RELEASE_DIR)/$(VERSION)
mkdir -p $@
$(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz $(SORTIX_RELEASE_DIR)/$(VERSION)/builds
$(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).iso: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_RELEASE_DIR)/$(VERSION)/builds
cp $< $@
.PHONY: release-iso.xz
release-iso.xz: $(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).iso.xz
$(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).tar.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz $(SORTIX_RELEASE_DIR)/$(VERSION)/builds
cp $< $@
.PHONY: release-tar
release-tar: $(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).tar.xz
.PHONY: release-iso
release-iso: $(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).iso
.PHONY: release-builds
release-builds: release-iso.xz release-tar
release-builds: release-iso
$(SORTIX_RELEASE_DIR)/$(VERSION)/README: README $(SORTIX_RELEASE_DIR)/$(VERSION)
cp $< $@

126
build-aux/iso-grub-cfg.sh Executable file
View File

@ -0,0 +1,126 @@
#!/bin/sh -e
platform=
directory=
version=
dashdash=
previous_option=
for argument do
if test -n "$previous_option"; then
eval $previous_option=\$argument
previous_option=
continue
fi
case $argument in
*=?*) parameter=$(expr "X$argument" : '[^=]*=\(.*\)') ;;
*=) parameter= ;;
*) parameter=yes ;;
esac
case $dashdash$argument in
--) dashdash=yes ;;
--platform=*) platform=$parameter ;;
--platform) previous_option=platform ;;
--version=*) version=$parameter ;;
--version) previous_option=version ;;
-*) echo "$0: unrecognized option $argument" >&2
exit 1 ;;
*) directory="$argument" ;;
esac
done
if test -n "$previous_option"; then
echo "$0: option '$argument' requires an argument" >&2
exit 1
fi
if test -z "$platform"; then
echo "$0: platform wasn't set with --platform" >&2
exit 1
fi
if test -z "$version"; then
echo "$0: platform wasn't set with --version" >&2
exit 1
fi
if test -z "$directory"; then
echo "$0: no directory operand supplied" >&2
exit 1
fi
machine=$(expr x"$platform" : 'x\([^-]*\).*')
cd "$directory"
mkdir -p boot/grub
exec > boot/grub/grub.cfg
cat << EOF
insmod part_msdos
insmod ext2
EOF
find . | grep -Eq '\.gz$' && echo "insmod gzio"
find . | grep -Eq '\.xz$' && echo "insmod xzio"
echo
cat << EOF
if loadfont unicode ; then
insmod vbe
insmod vga
insmod gfxterm
fi
terminal_output gfxterm
set menu_title="Sortix $version for $machine"
set timeout=10
set default="0"
EOF
maybe_compressed() {
if [ -e "$1.xz" ]; then
echo "$1.xz"
elif [ -e "$1.gz" ]; then
echo "$1.gz"
else
echo "$1"
fi
}
human_size() {
du -bh "$1" | grep -Eo '^[^[:space:]]+'
}
menuentry() {
echo
args=""
[ -n "$2" ] && args=" $2"
kernel=$(maybe_compressed boot/sortix.bin)
initrd=$(maybe_compressed boot/sortix.initrd)
printf "menuentry \"Sortix (%s)\" {\n" "$1"
case $platform in
x86_64-*)
cat << EOF
if ! cpuid -l; then
echo "Error: You cannot run this 64-bit operating system because" \
"this computer has no 64-bit mode."
read
exit
fi
EOF
;;
esac
cat << EOF
echo -n "Loading /$kernel ($(human_size $kernel)) ... "
multiboot /$kernel$args
echo done
echo -n "Loading /$initrd ($(human_size $initrd)) ... "
module /$initrd
echo done
EOF
printf "}\n"
}
menuentry "live environment" ''

View File

@ -1,17 +0,0 @@
insmod part_msdos
insmod ext2
if loadfont /boot/grub/fonts/unicode.pf2 ; then
insmod vbe
insmod vga
insmod gfxterm
fi
terminal_output gfxterm
set timeout=10
set default="0"
menuentry "Sortix" {
multiboot /boot/sortix.bin
module /boot/sortix.initrd
}

View File

@ -138,6 +138,13 @@ Specifies compiler optimization options that gets added to
.Ev CFLAGS
and
.Ev CXXFLAGS .
.It Ev SORTIX_ISO_COMPRESSION
Specifies the compression algorithm used in iso files. This must be one of
.Sy none , gzip
or
.Sy xz
and defaults to
.Sy xz .
.El
.Ss Components
The operating systems components, such as libc and the kernel, each have their