From d93989a3ffd5143a53b8a084d0513cfbc2b1670e Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Wed, 11 May 2011 23:40:47 +0400 Subject: [PATCH] initial logging subsystem Now we don't dump all the gory details onto thee but rather log them handsomely and present only the most important details by default; use DEBUG=1 and/or BUILDLOG=/path/to/file to tweak. Also introduced IMAGEDIR and IMAGENAME. The rest: - ovz-smp is no more - base-l10n pkglist (suggested by Alexander Kuprin) - clean.mk: + fixed an oversight: the test result erroneously applied only to the first command of several ones that should be run iff build/ is a symlink + drop implicit rules (it's no C code) - Makefile: more reasonable iso names - image.in/Makefile: .disk/date too --- Makefile | 34 ++++++++++++++------- README | 7 +++++ clean.mk | 28 +++++++++++------ distro.mk | 15 ++++++--- features.in/hdt/config.mk | 3 +- features.in/syslinux/cfg.in/10localboot.cfg | 2 +- features.in/syslinux/cfg.in/20install2.cfg | 6 ++-- features.in/syslinux/cfg.in/80rescue.cfg | 2 +- functions.mk | 2 +- image.in/Makefile | 14 +++++++-- iso.mk | 26 ++++++++++++++-- log.mk | 23 ++++++++++++++ pkg.in/lists/tagged/base+l10n | 2 ++ profile.mk | 16 +++++++--- 14 files changed, 138 insertions(+), 42 deletions(-) create mode 100644 log.mk create mode 100644 pkg.in/lists/tagged/base+l10n diff --git a/Makefile b/Makefile index a9f3b7f9..37027c22 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,7 @@ all help: @echo '** available distribution targets:' - @echo $(DISTROS) | fmt -sw65 | column -t - -include clean.mk -include distro.mk -include profile.mk -include iso.mk + @echo $(DISTROS) | fmt -sw"$$((COLUMNS>>1))" | column -t # this could have come from environment; # if not, can be symlinked if r/w, or made anew (NB: immediate assignment) @@ -23,16 +18,33 @@ PREFIX := mkimage-profiles.build BUILDDIR := $(shell [ -s build ] && realpath build || bin/mktmpdir $(PREFIX)) endif -ifdef DEBUG -GLOBAL_VERBOSE ?= 1 -SHELL += -x -endif +# most of the actual work done elsewhere +include clean.mk +include distro.mk +include profile.mk +include log.mk +include iso.mk # we can't use implicit rules for top-level targets, only for prereqs CONFIGS := $(shell sed -n 's,^distro/\([^:.]\+\):.*$$,\1,p' distro.mk) DISTROS := $(addsuffix .iso,$(CONFIGS)) ARCH ?= $(shell arch | sed 's/i686/i586/') +DATE = $(shell date +%Y%m%d) -export ARCH BUILDDIR DEBUG GLOBAL_VERBOSE SHELL +export ARCH BUILDDIR DATE SHELL + +# to be passed into .config.mk +IMAGEDIR ?= $(shell [ -d "$$HOME/out" -a -w "$$HOME/out" ] \ + && echo "$$HOME/out" \ + || echo "$(BUILDDIR)/out" ) +IMAGENAME ?= mkimage-profiles-$(ARCH).iso $(DISTROS): %.iso: | profile/init distro/% boot/isolinux profile/populate iso + @# TODO: run automated tests (e.g. iso size) + @OUTNAME="$(@:.iso=)-$(DATE)-$(ARCH).iso"; \ + test -s "$(IMAGEDIR)/$(IMAGENAME)" && \ + mv "$(IMAGEDIR)/"{$(IMAGENAME),$$OUTNAME} && \ + echo "** image: $(IMAGEDIR)/$$OUTNAME" && \ + ln -sf "$$OUTNAME" "$(IMAGEDIR)/$@" && \ + ln -sf "$@" "$(IMAGEDIR)/mkimage-profiles.iso" +### TODO: copy build.log as well for successful builds? diff --git a/README b/README index aae74e5a..00edc294 100644 --- a/README +++ b/README @@ -50,3 +50,10 @@ configurables: ~/.mkimage/metaconf.mk, see distro.mk NB: следует крайне осторожно пользоваться COMMON_PACKAGES, т.к. указанные пакеты попадут во все стадии (в т.ч. stage1 и install2, чувствительные к объёму). + +Результат: +- при успешном завершении сборки образ называется сообразно + дистрибутиву и укладывается в $(IMAGEDIR): + + указанный явно, + + либо ~/out/ (если возможно), + + или $(BUILDDIR)/out/ иначе diff --git a/clean.mk b/clean.mk index 4efbea13..42b28018 100644 --- a/clean.mk +++ b/clean.mk @@ -1,14 +1,22 @@ -clean: - @echo '** cleaning up...' - @find -name '*~' -delete >&/dev/null - @[ -d build/ ] && \ - $(MAKE) -C build/ $@ GLOBAL_BUILDDIR=$(shell readlink build) \ - ||: +# this makefile can be used standalone +# drop stock predefined rules +.DEFAULT: + +clean: + @echo '** cleaning up' + @find -name '*~' -delete >&/dev/null + @if test -L build; then \ + $(MAKE) -C build $@ GLOBAL_BUILDDIR=$(shell readlink build) $(LOG); \ + fi + +# there can be some sense in writing log here even if normally +# $(BUILDDIR)/ gets purged: make might have failed, +# and BUILDLOG can be specified by hand either distclean: clean - @[ -d build/ ] && \ + @if test -L build; then \ rm -rf build/.git; \ - $(MAKE) -C build/ $@ GLOBAL_BUILDDIR=$(shell readlink build) && \ + $(MAKE) -C build $@ GLOBAL_BUILDDIR=$(shell readlink build) $(LOG) && \ rm -r $(shell readlink build) && \ - rm build \ - ||: + rm build; \ + fi diff --git a/distro.mk b/distro.mk index 40c95860..8d334be0 100644 --- a/distro.mk +++ b/distro.mk @@ -1,5 +1,8 @@ +# this makefile is designed to be included in toplevel one +ifdef BUILDDIR + # step 2: build up distribution's configuration -# + # NB: distro/ targets should be defined here, # see toplevel Makefile's $(DISTRO) assignment CONFIG = $(BUILDDIR)/.config.mk @@ -7,7 +10,7 @@ CONFIG = $(BUILDDIR)/.config.mk # source initial feature snippets -include features.in/*/config.mk -# put(), add(), set(), tags() +# put(), add(), set(), try(), tags(): see functions.mk # # package list names are considered relative to pkg/lists/ # @@ -26,9 +29,11 @@ sub/%: # initalize config from scratch, put some sane defaults in distro/.init: - @echo "** starting distro configuration build process" + @echo "** preparing distro configuration$${DEBUG:+: see $(CONFIG)}" @$(call try,MKIMAGE_PREFIX,/usr/share/mkimage) @$(call try,GLOBAL_VERBOSE,) + @$(call try,IMAGEDIR,$(IMAGEDIR)) + @$(call try,IMAGENAME,$(IMAGENAME)) # NB: the last flavour in KFLAVOURS gets to be the default one; # the kernel packages regexp evaluation has to take place at build stage @@ -49,7 +54,7 @@ distro/server-base: distro/installer sub/main use/syslinux/ui-menu use/memtest distro/server-light: distro/server-base use/hdt @$(call set,BRANDING,sisyphus-server-light) - @$(call set,KFLAVOURS,ovz-smp el-smp) # override default + @$(call set,KFLAVOURS,ovz-el el-smp) # override default @$(call add,KMODULES,igb ipset kvm ndiswrapper pf_ring rtl8192 xtables-addons) @$(call add,DISK_LISTS,kernel-wifi) @$(call add,BASE_LISTS,$(call tags,base server)) @@ -72,3 +77,5 @@ distro/.metaconf: boot/%: distro/.init @$(call set,BOOTLOADER,$*) + +endif diff --git a/features.in/hdt/config.mk b/features.in/hdt/config.mk index eeedcc6a..1e5e1540 100644 --- a/features.in/hdt/config.mk +++ b/features.in/hdt/config.mk @@ -1,5 +1,4 @@ use/hdt: use/syslinux + @$(call add,STAGE1_PACKAGES,pciids) @$(call add,SYSLINUX_MODULES,hdt) -# might be /usr/share/pci.ids if usig hwdatabase @$(call add,SYSLINUX_FILES,/usr/share/misc/pci.ids) - diff --git a/features.in/syslinux/cfg.in/10localboot.cfg b/features.in/syslinux/cfg.in/10localboot.cfg index ad3d44ec..348e6e91 100644 --- a/features.in/syslinux/cfg.in/10localboot.cfg +++ b/features.in/syslinux/cfg.in/10localboot.cfg @@ -1,3 +1,3 @@ label harddisk - menu label ^Continue as usual + menu label ^Boot from HDD (as usual) localboot 0x80 diff --git a/features.in/syslinux/cfg.in/20install2.cfg b/features.in/syslinux/cfg.in/20install2.cfg index ae0bd209..06187ddb 100644 --- a/features.in/syslinux/cfg.in/20install2.cfg +++ b/features.in/syslinux/cfg.in/20install2.cfg @@ -1,8 +1,8 @@ label linux - menu label ^Normal install + menu label ^Install ALT Linux kernel alt0/vmlinuz append initrd=alt0/full.cz changedisk vga=0x314 quiet=1 showopts automatic=method:cdrom label noapic - menu label ^FailSafe(TM) install + menu label ^Install ALT Linux (failsafe) kernel alt0/vmlinuz - append initrd=alt0/full.cz changedisk vga=0x314 showopts nolapic noapic acpi=off + append initrd=alt0/full.cz changedisk showopts nolapic noapic diff --git a/features.in/syslinux/cfg.in/80rescue.cfg b/features.in/syslinux/cfg.in/80rescue.cfg index ab539c59..115c754c 100644 --- a/features.in/syslinux/cfg.in/80rescue.cfg +++ b/features.in/syslinux/cfg.in/80rescue.cfg @@ -1,4 +1,4 @@ label rescue - menu label ^Rescue + menu label ^Rescue LiveCD kernel alt0/vmlinuz append initrd=alt0/full.cz live fastboot stagename=rescue diff --git a/functions.mk b/functions.mk index 7bb47efe..2f83e019 100644 --- a/functions.mk +++ b/functions.mk @@ -1,7 +1,7 @@ # NB: don"t use ANY quotes ('/") for put()/add()/set() arguments! # shell will get confused by ' or args get spammed with " -# pay attention to the context in which functions get called: +# pay attention to the context functions get called in: # e.g. features.in/syslinux/config.mk introduces conditionals # this one adds whatever is given as an argument diff --git a/image.in/Makefile b/image.in/Makefile index e3de5df7..c212bc57 100644 --- a/image.in/Makefile +++ b/image.in/Makefile @@ -12,10 +12,13 @@ SUBDIRS = $(SUBPROFILES) # "main" subprofile needs genbasedir CHROOT_PACKAGES = apt-utils ### -MKI_PACK_RESULTS = isoboot:mkimage-profiles.iso +MKI_PACK_RESULTS = isoboot:$(IMAGENAME) COPY_TREE = ./files BOOT_TYPE = isolinux +# outdir shouldn't be wiped clean before use +CLEANUP_OUTDIR = + ifeq "$(wildcard $(APTCONF))" "" GLOBAL_HSH_APT_CONFIG = /etc/apt/apt.conf else @@ -27,7 +30,13 @@ include $(MKIMAGE_PREFIX)/targets.mk all: prep copy-subdirs copy-tree run-scripts pack-image # FIXME: scripts.d/? -prep: debug dot-disk metadata +prep: debug dot-disk metadata $(IMAGEDIR) + +$(IMAGEDIR): + mkdir -p "$(IMAGEDIR)" + +# specified only for the final image, not for the subparts +pack-image: OUTDIR = $(IMAGEDIR) debug: ifdef DEBUG @@ -40,6 +49,7 @@ dot-disk: @mkdir -p files/.disk @echo "ALT Linux based" >files/.disk/info @echo "$(ARCH)" >files/.disk/arch + @echo "$(DATE)" >files/.disk/date @type -t git >&/dev/null && ( \ cd $(TOPDIR) && \ git show-ref --head --dereference -s -- HEAD 2>/dev/null; \ diff --git a/iso.mk b/iso.mk index a7e84d50..f406fe8f 100644 --- a/iso.mk +++ b/iso.mk @@ -1,3 +1,6 @@ +# this makefile is designed to be included in toplevel one +ifdef BUILDDIR + # step 4 is kicked off here but actually done by image.in/Makefile # # adding boot/isolinux to prereqs is too late here, @@ -6,5 +9,24 @@ # NB: /usr/bin/{i586,x86_64} are setarch(8) symlinks iso: - @echo "** starting image build process" - $(ARCH) $(MAKE) -C $(BUILDDIR)/ GLOBAL_BUILDDIR=$(BUILDDIR) + @echo -n "** starting image build" + @if test -n "$(DEBUG)"; then \ + echo ": see $(BUILDLOG)"; \ + else \ + echo " (coffee time)"; \ + fi + @if time $(ARCH) \ + $(MAKE) -C $(BUILDDIR)/ GLOBAL_BUILDDIR=$(BUILDDIR) $(LOG); \ + then \ + echo "** build done (`tail -2 $(BUILDLOG) \ + | sed -n 's,^.* \([0-9:]\+\)\...elapsed.*$$,\1,p' \ + || echo "no log"`)"; \ + else \ + echo "** build failed, see log: $(BUILDLOG)"; \ + if test -z "$(DEBUG)"; then \ + echo " (you might want to re-run with DEBUG=1)"; \ + fi; \ + tail -100 "$(BUILDLOG)" | grep "^E:"; \ + fi + +endif diff --git a/log.mk b/log.mk new file mode 100644 index 00000000..ec4f93ae --- /dev/null +++ b/log.mk @@ -0,0 +1,23 @@ +# this makefile is designed to be included in toplevel one +ifdef BUILDDIR + +# simple logging switch inspired by netch@'s advice: +# you can add plain $(LOG) to a rule recipe line to moderate it +# (logfile is automatically truncated during profile/init) + +BUILDLOG ?= $(BUILDDIR)/build.log + +ifdef DEBUG +GLOBAL_VERBOSE ?= $(DEBUG) +ifeq (2,$(DEBUG)) +SHELL += -x +endif +LOG = >>$(BUILDLOG) 2>&1 +else +MAKE += -s +LOG = 2>>$(BUILDLOG) >/dev/null +endif + +export BUILDLOG DEBUG GLOBAL_VERBOSE LOG MAKE SHELL + +endif diff --git a/pkg.in/lists/tagged/base+l10n b/pkg.in/lists/tagged/base+l10n new file mode 100644 index 00000000..52f0d359 --- /dev/null +++ b/pkg.in/lists/tagged/base+l10n @@ -0,0 +1,2 @@ +glibc-locales +glibc-gconv-modules diff --git a/profile.mk b/profile.mk index 91a99c5d..2f8337a7 100644 --- a/profile.mk +++ b/profile.mk @@ -1,8 +1,12 @@ +# this makefile is designed to be included in toplevel one +ifdef BUILDDIR + # step 1: initialize the off-tree mkimage profile -profile/init: - @echo "** BUILDDIR: $(BUILDDIR)" +profile/init: distclean + @echo -n "** initializing BUILDDIR: " @rsync -qaH --delete image.in/ "$(BUILDDIR)"/ @:> "$(BUILDDIR)"/.config.mk + @:> "$(BUILDLOG)" @mkdir "$(BUILDDIR)"/.mki # mkimage toplevel marker @type -t git >&/dev/null && \ cd $(BUILDDIR) && \ @@ -11,14 +15,16 @@ profile/init: git commit -qam 'init' @rm -f build @if [ -w . ]; then \ - ln -sf "$(BUILDDIR)" build; \ + ln -sf "$(BUILDDIR)" build && \ + echo "build/"; \ else \ - echo "** profile directory readonly: skipping symlinks, env only"; \ + echo "$(BUILDDIR)/"; \ fi # this is done after step 2, see toplevel Makefile profile/populate: profile/init distro/.metaconf @for dir in sub.in features.in pkg.in; do \ - $(MAKE) -C $$dir; \ + $(MAKE) -C $$dir $(LOG); \ done +endif