[Lunar-commits] <lunar-iso> Started on rewrite using less scripts and split makefile
Peter de Ridder
peter at lunar-linux.org
Thu Apr 11 00:32:14 CEST 2013
commit 8d710f290667e5e7e81de8c8c285c7f3b8f7372a
Author: Peter de Ridder <peter at lunar-linux.org>
Date: Sun, 19 Aug 2012 15:55:08 -0700
URL: https://github.com/lunar-linux/lunar-iso/commit/8d710f290667e5e7e81de8c8c285c7f3b8f7372a
Started on rewrite using less scripts and split makefile
---
Makefile | +14/-133
mkfiles/bootstrap.mk | +33/-0
mkfiles/build.mk | +19/-0
mkfiles/download.mk | +42/-0
scripts/bootstrap-lunar-cache | +81/-0
scripts/chroot-build | +26/-0
scripts/download-lunar-spool | +37/-0
7 files changed, 252 insertions(+), 133 deletions(-)
--- a/Makefile
+++ b/Makefile
@@ -10,152 +10,33 @@
ISO_SOURCE = $(shell bash -c "pwd -P")
# define the kernel arch name
-ISO_KARCH=$(shell arch | grep -qw i.86 && echo i386 || arch)
+###ISO_KARCH=$(shell arch | grep -qw i.86 && echo i386 || arch)
# and the general arch (i386/i686)
ISO_ARCH=$(shell arch)
include conf/config
-ISO_KSUFFIX = $(shell if echo $(ISO_KVER) | grep -q "^2\.6\." ; then echo 2.6 ; else echo 2.4 ; fi ;)
+###ISO_KSUFFIX = $(shell if echo $(ISO_KVER) | grep -q "^2\.6\." ; then echo 2.6 ; else echo 2.4 ; fi ;)
# define the location where the ISO will be generated
ISO_TARGET = $(ISO_SOURCE)/BUILD
-export ISO_SOURCE ISO_TARGET ISO_MAJOR ISO_MINOR ISO_VERSION ISO_CODENAME \
- ISO_DATE ISO_CNAME ISO_KVER ISO_PVER ISO_GRSVER ISO_LUNAR_MODULE \
- ISO_KSUFFIX ISO_MAKES ISO_REDUCE ISO_BUILD ISO_KARCH ISO_GCCARCH
+###export ISO_SOURCE ISO_TARGET ISO_MAJOR ISO_MINOR ISO_VERSION ISO_CODENAME \
+### ISO_DATE ISO_CNAME ISO_KVER ISO_PVER ISO_GRSVER ISO_LUNAR_MODULE \
+### ISO_KSUFFIX ISO_MAKES ISO_REDUCE ISO_BUILD ISO_KARCH ISO_GCCARCH
-all: iso
+export ISO_SOURCE ISO_TARGET ISO_BUILD
-iso: initrd proper $(ISO_TARGET)/.iso
-$(ISO_TARGET)/.iso:
- @echo "Generating ISO"
- @scripts/isofs
+all: build
-proper: locale aaa_dev aaa_base $(ISO_TARGET)/.proper
-$(ISO_TARGET)/.proper:
- @echo "Cleaning BUILD"
- @scripts/proper
-
-locale: $(ISO_TARGET)/.locale_list
-$(ISO_TARGET)/.locale_list:
- @echo "Generating locale list"
- @scripts/gen_locale_list
-
-aaa_dev: $(ISO_SOURCE)/aaa_dev/aaa_dev.tar.bz2
-$(ISO_SOURCE)/aaa_dev/aaa_dev.tar.bz2: initrd
-
-initrd: memtest kernels $(ISO_SOURCE)/initrd/initrd
-$(ISO_SOURCE)/initrd/initrd:
- @echo "Generating initrd image"
- @scripts/initrd
-
-kernels: rebuild $(ISO_SOURCE)/kernels/.kernels
-$(ISO_SOURCE)/kernels/.kernels:
- @echo "Building precompiled kernels"
- @scripts/kernels
-
-memtest: rebuild $(ISO_SOURCE)/memtest/memtest
-$(ISO_SOURCE)/memtest/memtest:
- @echo "Generating memtest boot image"
- @scripts/memtest
-
-aaa_base: rebuild $(ISO_SOURCE)/aaa_base/aaa_base.tar.bz2
-$(ISO_SOURCE)/aaa_base/aaa_base.tar.bz2:
- @echo "Creating aaa_base.tar.bz2"
- @scripts/aaa_base
-
-prebuild: prepare $(ISO_TARGET)/.prebuild
-$(ISO_TARGET)/.prebuild:
- @echo "Running prebuild process"
- @scripts/prebuild
-
-rebuild: etc $(ISO_TARGET)/.rebuild
-$(ISO_TARGET)/.rebuild:
- @echo "Starting rebuild process"
- @scripts/rebuild
-
-etc: toolset unpack $(ISO_TARGET)/.etcf
-$(ISO_TARGET)/.etcf:
- @echo "Copying miscfiles"
- @scripts/etc
-
-toolset: prebuild $(ISO_SOURCE)/template/moonbase.tar.bz2 $(ISO_SOURCE)/template/$(ISO_LUNAR_MODULE).tar.bz2
-$(ISO_SOURCE)/template/moonbase.tar.bz2 $(ISO_SOURCE)/template/$(ISO_LUNAR_MODULE).tar.bz2:
- @echo "Getting a proper moonbase"
- @scripts/toolset
-
-unpack: cachefill dirs $(ISO_TARGET)/.unpack
-$(ISO_TARGET)/.unpack:
- @echo "Unpacking binaries and copying sources"
- @scripts/unpack
-
-cachefill: dirs $(ISO_TARGET)/.cachefill
-$(ISO_TARGET)/.cachefill:
- @echo "Resolving and testing dependencies"
- @scripts/precheck
- @echo "Fetching cache tarballs and sources"
- @scripts/cachefill
-
-dirs: init $(ISO_TARGET)/.dirs
-$(ISO_TARGET)/.dirs:
- @echo "Creating LSB directory structure"
- @scripts/dirs
-
-init: $(ISO_TARGET)/.init
-$(ISO_TARGET)/.init:
- @if [ -d BUILD ] ; then \
- echo "BUILD directory already exists!"; \
- false; \
- fi
- @echo "Creating BUILD root"
- @scripts/init
-
-prepare:
- @echo "preparing sources and packages"
- @scripts/prepare
+include mkfiles/bootstrap.mk
+include mkfiles/download.mk
+include mkfiles/build.mk
clean:
- umount BUILD/dev &> /dev/null || true
- umount BUILD/proc &> /dev/null || true
- umount BUILD/sys &> /dev/null || true
- rm -rf BUILD
- rm -rf initrd/BUILD initrd/initrd
- rm -rf spool cache
- rm -rf aaa_base aaa_dev
- rm -rf memtest
- rm -rf kernels/TAR kernels/*.tar.bz2 kernels/.kernels kernels/.initrd_kernels
- rm -f template/moonbase.tar.bz2
- rm -f kernels/linux kernels/linux.map
- rm -f kernels/safe kernels/safe.map
- rm -rf locale
-
-dist: lunar-$(ISO_VERSION).iso
- rm -f lunar-$(ISO_VERSION).iso.{bz2,sha1,bz2.sha1}
- bzip2 -k lunar-$(ISO_VERSION).iso
- sha1sum lunar-$(ISO_VERSION).iso > lunar-$(ISO_VERSION).iso.sha1
- sha1sum lunar-$(ISO_VERSION).iso.bz2 > lunar-$(ISO_VERSION).iso.bz2.sha1
-
-blank:
- @scripts/blank
-
-burn:
- @scripts/burn
-
-# these are for hacking around and doing manual adjustments
-tar:
- tar cf BUILD.tar BUILD
-
-moonbase-extract:
- tar xf $(ISO_TARGET)/var/lib/lunar/moonbase.tar.bz2 -C $(ISO_TARGET)/var/lib/lunar
- rm $(ISO_TARGET)/var/lib/lunar/moonbase.tar.bz2
- @echo "Don't forget to do a 'make moonbase-pack!'"
+ rm -r $(ISO_TARGET) $(ISO_SOURCE)/{spool,cache}
-moonbase-pack:
- tar cjf $(ISO_TARGET)/var/lib/lunar/moonbase.tar.bz2 -C $(ISO_TARGET)/var/lib/lunar moonbase/
- rm -rf $(ISO_TARGET)/var/lib/lunar/moonbase
- @echo "Packed up moonbase."
+# Convenient target for development
+chroot:
+ $(ISO_SOURCE)/scripts/chroot-build su -
-test:
- @echo "running tests"
- @scripts/test
--- /dev/null
+++ b/mkfiles/bootstrap.mk
@@ -0,0 +1,33 @@
+bootstrap: bootstrap-base bootstrap-lunar
+
+# file the target with the base file required
+$(ISO_TARGET)/.base: $(ISO_TARGET)/.stamp
+ @mkdir -p $(ISO_TARGET)/{bin,dev,etc,lib,mnt,proc,root,run,sbin,sys,tmp,usr,var} $(ISO_TARGET)/run/lock $(ISO_TARGET)/usr/{bin,include,lib,libexec,sbin,src,share} $(ISO_TARGET)/var/{cache,empty,lib,log,spool,state,tmp}
+ @ln -sf lib $(ISO_TARGET)/lib32
+ @ln -sf lib $(ISO_TARGET)/lib64
+ @ln -sf lib $(ISO_TARGET)/usr/lib32
+ @ln -sf lib $(ISO_TARGET)/usr/lib64
+ @ln -sf ../run/lock $(ISO_TARGET)/var/lock
+ @ln -sf ../run $(ISO_TARGET)/var/run
+ @cp -r $(ISO_SOURCE)/template/etc $(ISO_TARGET)
+ @touch $@
+
+bootstrap-base: $(ISO_TARGET)/.base
+
+# bootstrap on a lunar host
+$(ISO_SOURCE)/cache/.copied:
+ @$(ISO_SOURCE)/scripts/bootstrap-lunar-cache
+ @touch $@
+
+$(ISO_TARGET)/.modules: $(ISO_SOURCE)/cache/.copied $(ISO_TARGET)/.stamp
+ for archive in $(ISO_SOURCE)/cache/*-$(ISO_BUILD).tar.bz2 ; do \
+ tar -xjf "$$archive" -C $(ISO_TARGET) || exit 1 ; \
+ done
+ @touch $@
+
+bootstrap-lunar: $(ISO_TARGET)/.modules
+
+
+$(ISO_TARGET)/.stamp:
+ @mkdir -p $(ISO_TARGET)
+ @touch $@
--- /dev/null
+++ b/mkfiles/build.mk
@@ -0,0 +1,19 @@
+build: build-toolchain
+
+$(ISO_TARGET)/.moonbase-build: $(ISO_TARGET)/.base $(ISO_TARGET)/.modules $(ISO_TARGET)/.moonbase-download
+ @$(ISO_SOURCE)/scripts/chroot-build lsh create_module_index
+ @$(ISO_SOURCE)/scripts/chroot-build lsh create_depends_cache
+ @$(ISO_SOURCE)/scripts/chroot-build lsh update_plugins
+ @touch $@
+
+build-moonbase: $(ISO_TARGET)/.moonbase-build
+
+$(ISO_TARGET)/.toolchain: $(ISO_TARGET)/.moonbase-build
+ yes n | lin -rc kernel-headers glibc binutils gcc binutils glibc
+ @touch $@
+
+build-toolchain: $(ISO_TARGET)/.toolchain
+
+$(ISO_TARGET)/.stage1: $(iso_target)/.toolchain
+
+build-stage1: $(ISO_TARGET)/.stage1
--- /dev/null
+++ b/mkfiles/download.mk
@@ -0,0 +1,42 @@
+download-sources: install-moonbase download-lunar
+
+install-sources: install-spool
+
+
+# download the moonbase
+$(ISO_SOURCE)/spool/moonbase.tar.bz2: $(ISO_SOURCE)/spool/.stamp
+ @wget -O $@ "`lsh eval echo '$$MOONBASE_URL'`/moonbase.tar.bz2" \
+ || { rm $@ ; exit 1 ; }
+ @touch $@
+
+$(ISO_TARGET)/.moonbase-download: $(ISO_TARGET)/.stamp $(ISO_SOURCE)/spool/moonbase.tar.bz2
+ @mkdir -p $(ISO_TARGET)/var/lib/lunar/moonbase
+ @rm -r $(ISO_TARGET)/var/lib/lunar/moonbase
+ @tar -xjf $(ISO_SOURCE)/spool/moonbase.tar.bz2 -C $(ISO_TARGET)/var/lib/lunar moonbase/core moonbase/aliases
+ @mkdir -p $(ISO_TARGET)/var/lib/lunar/moonbase/zlocal
+ @mkdir -p $(ISO_TARGET)/var/state/lunar/moonbase
+ @touch $(ISO_TARGET)/var/state/lunar/packages{,.backup}
+ @touch $@
+
+install-moonbase: $(ISO_TARGET)/.moonbase-download
+
+#download on a lunar host
+$(ISO_SOURCE)/spool/.copied: $(ISO_TARGET)/.moonbase-download
+ @$(ISO_SOURCE)/scripts/download-lunar-spool
+ @touch $@
+
+download-lunar: $(ISO_SOURCE)/spool/.copied
+
+
+# install the sources
+$(ISO_TARGET)/.spool: $(ISO_SOURCE)/spool/.copied
+ @mkdir -p $(ISO_TARGET)/var/spool/lunar
+ @cp $(ISO_SOURCE)/spool/* $(ISO_TARGET)/var/spool/lunar/
+ @touch $@
+
+install-spool: $(ISO_TARGET)/.spool
+
+
+$(ISO_SOURCE)/spool/.stamp:
+ @mkdir $(ISO_SOURCE)/spool
+ @touch $@
--- /dev/null
+++ b/scripts/bootstrap-lunar-cache
@@ -0,0 +1,81 @@
+#!/bin/bash
+
+BOOTSTRAP_MODULES="bash binutils bzip2 coreutils dialog diffutils file findutils gawk gcc glib-2 glibc grep gzip installwatch less lunar make patch procps readline sed util-linux xz zlib"
+
+mkdir -p "$ISO_SOURCE/cache"
+
+NEED_MODULES=
+LUNAR_CACHE=`lsh eval echo '$INSTALL_CACHE'`
+NEED_CACHE=
+NO_CACHE=
+
+# make a list of all the required caches
+for mod in $BOOTSTRAP_MODULES ; do
+ # if this module isn't installed it probebly isn't required
+ if lsh module_installed $mod ; then
+ NEED_MODULES="$NEED_MODULES $mod"
+ for dep in `lvu links $mod` ; do
+ MODULE_NAME="$dep"
+ # find the correct name of this module
+ while echo "$MODULE_NAME" | grep -q - ; do
+ MODULE_NAME=${MODULE_NAME%-*}
+ lsh module_installed $MODULE_NAME && break
+ done || continue
+ NEED_MODULES="$NEED_MODULES $MODULE_NAME"
+ done
+ fi
+done
+
+# make a unique list of module
+NEED_MODULES=`for mod in $NEED_MODULES ; do echo $mod ; done | sort -u`
+
+echo Required modules:
+for mod in $NEED_MODULES ; do
+ echo " $mod"
+done
+
+for mod in $NEED_MODULES ; do
+ # check for cache file presence
+ CACHE="$mod-$(lsh installed_version $mod)-$ISO_BUILD.tar.bz2"
+ if [ ! -f "$ISO_SOURCE/cache/$CACHE" ] ; then
+ cp "$LUNAR_CACHE/$CACHE" "$ISO_SOURCE/cache/$CACHE" || NEED_CACHE="$NEED_CACHE $mod"
+ fi
+done
+
+if [ ! -f "$ISO_SOURCE/cache/fixup-$ISO_BUILD.tar.bz2" ] ; then
+ tar -cjf "$ISO_SOURCE/cache/fixup-$ISO_BUILD.tar.bz2" /lib/ld-linux-x86-64.so.2 /lib/libc.so.6 /lib/libdl.so.2 /lib/libm.so.6 /lib/librt.so.1 /lib/libpthread.so.0 /lib/libnss_files.so.2 /lib/libutil.so.1 /lib/libnsl.so.1 /lib/libcrypt.so.1
+fi
+
+if [ -z "$NEED_CACHE" ] ; then
+ exit 0
+fi
+
+echo Rebuild modules to create cache:
+for mod in $NEED_CACHE ; do
+ echo " $mod"
+done
+
+if [ -n "$REBUILD_MANUAL" ] ; then
+ exit 1
+fi
+
+lin -c $NEED_CACHE
+
+for mod in $NEED_CACHE ; do
+ # check for cache file presence
+ CACHE="$mod-$(lsh installed_version $mod)-$ISO_BUILD.tar.bz2"
+ if [ ! -f "$ISO_SOURCE/cache/$CACHE" ] ; then
+ cp "$LUNAR_CACHE/$CACHE" "$ISO_SOURCE/cache/$CACHE" || NO_CACHE="$NO_CACHE $mod"
+ fi
+done
+
+if [ -z "$NO_CACHE" ] ; then
+ exit 0
+fi
+
+echo No module cache files:
+for mod in $NO_CACHE ; do
+ echo " $mod"
+done
+
+exit 1
--- /dev/null
+++ b/scripts/chroot-build
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+function mount_system_fs ()
+{
+ for mpoint in proc sys dev ; do
+ mount --bind /${mpoint} $ISO_TARGET/${mpoint} || return 1
+ done
+}
+
+function umount_system_fs ()
+{
+ for mpoint in proc sys dev ; do
+ if ! umount $ISO_TARGET/${mpoint} &> /dev/null ; then
+ umount -l -f $ISO_TARGET/${mpoint} &> /dev/null
+ fi
+ done
+}
+
+mount_system_fs &&
+
+chroot "$ISO_TARGET" "$@"
+RESULT=$?
+
+umount_system_fs
+
+exit $RESULT
--- /dev/null
+++ b/scripts/download-lunar-spool
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+CORE_MODULES=`find "$ISO_TARGET/var/lib/lunar/moonbase/core" -name DETAILS -printf "%h\n" | sed 's at .*/@@'`
+
+mkdir -p "$ISO_SOURCE/spool"
+
+LUNAR_CACHE=`lsh eval echo '$SOURCE_CACHE'`
+NO_CACHE=
+
+echo Required modules:
+for mod in $CORE_MODULES ; do
+ echo " $mod"
+done
+
+for mod in $CORE_MODULES ; do
+ lsh eval MOONBASE="$ISO_TARGET/var/lib/lunar/moonbase" download_module "$mod"
+ # check for cache file presence
+ for src in `lsh eval MOONBASE="$ISO_TARGET/var/lib/lunar/moonbase" sources "$mod"` ; do
+ if [ ! -f "$ISO_SOURCE/spool/$src" ] ; then
+ cp "$LUNAR_CACHE/$src" "$ISO_SOURCE/spool/$src" || NO_CACHE="$NO_CACHE $mod"
+ fi
+ done
+done
+
+if [ -z "$NO_CACHE" ] ; then
+ exit 0
+fi
+
+# make a unique list of module
+NO_CACHE=`for mod in $NO_CACHE ; do echo $mod ; done | sort -u`
+
+echo No module source files:
+for mod in $NO_CACHE ; do
+ echo " $mod"
+done
+
+exit 1
More information about the Lunar-commits
mailing list