From 9a8f8ef7cd8b5b6242572e2f38e31e506ee25c9f Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Mon, 13 Sep 2010 17:22:05 +0300 Subject: [PATCH] distro.mk: functionalization - set(), add(), log() + special thanks to rider@ for log format feedback - simple debug facility - builds, installs and runs... again --- Makefile | 9 ++++-- clean.mk | 1 + distro.mk | 45 +++++++++++++--------------- functions.mk | 33 ++++++++++++++++++++ image.in/Makefile | 2 +- image.in/files/syslinux/isolinux.cfg | 2 +- iso.mk | 4 +-- sub.in/stage1/Makefile | 4 +-- sub.in/stage1/initfs | 1 + 9 files changed, 68 insertions(+), 33 deletions(-) create mode 100644 functions.mk create mode 100644 sub.in/stage1/initfs diff --git a/Makefile b/Makefile index 2442860d..36a28e1a 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,14 @@ BUILDDIR := $(shell realpath build || bin/mktmpdir mkimage-profiles.build) endif export BUILDDIR +ifdef DEBUG +GLOBAL_VERBOSE ?= 1 +SHELL += -x +endif + # 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)) +CONFIGS := $(shell sed -n 's,^distro/\([^:]\+\):.*$$,\1,p' distro.mk) +DISTROS := $(addsuffix .iso,$(CONFIGS)) all: @echo '** available distribution targets:' diff --git a/clean.mk b/clean.mk index 49bfec4d..4e7f5605 100644 --- a/clean.mk +++ b/clean.mk @@ -6,6 +6,7 @@ clean: distclean: clean @[ -d build/ ] && \ + rm -rf build/.git; \ make -C build/ $@ GLOBAL_BUILDDIR=$(shell readlink build) && \ rm -r $(shell readlink build) && \ rm build \ diff --git a/distro.mk b/distro.mk index 30bb7c91..c38a14be 100644 --- a/distro.mk +++ b/distro.mk @@ -4,14 +4,8 @@ CONFIG = $(BUILDDIR)/.config.mk # source initial feature snippets -include features.in/*/config.mk -# NB: don"t use ANY quotes ('/") for put() arguments! -# shell will get confused by ' or args get spammed with " -put = $(and $(1),$(put_body)) -define put_body -@printf '%s\n' '$(1)#=- $@' >> "$(CONFIG)" -endef - -tags = $(shell echo "$(1)" | bin/tags2lists) +# put(), add(), set(), tags() +include functions.mk # request particular image subprofile inclusion sub/%: @@ -27,31 +21,32 @@ sub/%: # # tags do boolean expressions: (tag1 && !(tag2 || tag3)) -init: +distro/init: @echo "** starting distro configuration build process" - :> $(CONFIG) - $(call put,KFLAVOUR=std-def) ### - $(call put,IMAGE_INIT_LIST=+branding-$$(BRANDING)-release) - $(call put,BRANDING=altlinux-desktop) ### - @#$(call put,STAGE1_PACKAGES=kernel-image-$$(KFLAVOUR)) - $(call put,KERNEL_PACKAGES=kernel-image-$$(KFLAVOUR)) + @:> $(CONFIG) -distro/syslinux: init +distro/base: distro/init sub/stage1 + $(call set,KFLAVOUR,std-def) ### + $(call set,IMAGE_INIT_LIST,+branding-$$(BRANDING)-release) + $(call set,BRANDING,altlinux-desktop) ### + $(call set,KERNEL_PACKAGES,kernel-image-$$(KFLAVOUR)) + +distro/syslinux: distro/base # NB: our */* are phony targets really, just for namespace -distro/installer: init sub/install2 +distro/installer: distro/base sub/install2 @#$(call put,BRANDING=altlinux-sisyphus) ### - $(call put,BASE_LISTS=base kernel) - $(call put,INSTALL2_PACKAGES=installer-distro-server-light-stage2) ### + $(call set,BASE_LISTS,base kernel) + $(call set,INSTALL2_PACKAGES,installer-distro-server-light-stage2) ### distro/server-base: distro/installer sub/main use/memtest86 - $(call put,BASE_LISTS+=server-base kernel-server) + $(call add,BASE_LISTS,server-base kernel-server) distro/server-light: distro/server-base use/bootsplash - $(call put,KFLAVOUR=ovz-smp) # override default - $(call put,BRANDING=sisyphus-server-light) - $(call put,DISK_LISTS+=kernel-wifi) - $(call put,BASE_LISTS+=$(call tags,base server)) + $(call set,KFLAVOUR,ovz-smp) # override default + $(call set,BRANDING,sisyphus-server-light) + $(call add,DISK_LISTS,kernel-wifi) + $(call add,BASE_LISTS,$(call tags,base server)) use/bootsplash: - $(call put,COMMON_TAGS+=bootsplash) + $(call add,COMMON_TAGS,bootsplash) diff --git a/functions.mk b/functions.mk new file mode 100644 index 00000000..79f9adf3 --- /dev/null +++ b/functions.mk @@ -0,0 +1,33 @@ +# NB: don"t use ANY quotes ('/") for put()/add()/set() arguments! +# shell will get confused by ' or args get spammed with " + +# this one adds whatever is given as an argument +put = $(and $(1),$(put_body)) +define put_body +$(log_body) +@printf '%s\n' '$(1)' >> "$(CONFIG)" +endef + +# these two take two args +# add() just appends an additive rule... +add = $(and $(1),$(2),$(add_body)) +define add_body +$(log_body) +@printf '%s += %s\n' '$(1)' '$(2)' >> "$(CONFIG)" +endef + +# ...set() comments out any previous definition +# and then appends an assigning rule +set = $(and $(1),$(2),$(set_body)) +define set_body +$(log_body) +@subst 's|^$(1)[ ]*+*=.*$$|#& # overridden by $@|' "$(CONFIG)" +@printf '%s = %s\n' '$(1)' '$(2)' >> "$(CONFIG)" +endef + +# is there a way to set a global make var from a recipe?.. +define log_body +@grep -q '^# $@$$' "$(CONFIG)" || printf '# %s\n' '$@' >> "$(CONFIG)" +endef + +tags = $(shell echo "$(1)" | bin/tags2lists) diff --git a/image.in/Makefile b/image.in/Makefile index b3a19107..44f47d31 100644 --- a/image.in/Makefile +++ b/image.in/Makefile @@ -22,7 +22,7 @@ prep: disk-info metadata disk-info: mkdir -p files/.disk - echo "$(PROPAGATOR_VERSION)" >files/.disk/info ### +$(ARCH) + echo "FIXME" >files/.disk/info ### +$(ARCH) (cd $(TOPDIR); git show-ref --head --dereference -s -- HEAD 2>/dev/null) >files/.disk/commit [ -s files/.disk/commit ] || rm files/.disk/commit diff --git a/image.in/files/syslinux/isolinux.cfg b/image.in/files/syslinux/isolinux.cfg index 558e5be7..9e1ccf5c 100644 --- a/image.in/files/syslinux/isolinux.cfg +++ b/image.in/files/syslinux/isolinux.cfg @@ -5,7 +5,7 @@ timeout 200 # f1 help.txt # f2 version.txt # ... -default rescue +default linux label harddisk menu label Continue as usual diff --git a/iso.mk b/iso.mk index b2f386b0..e0212f3a 100644 --- a/iso.mk +++ b/iso.mk @@ -1,6 +1,6 @@ iso: @echo "** starting image build process" @### setup GLOBAL_BOOT_TYPE, etc - @#echo (cd $(BUILDDIR)/; autoconf; ./configure --with-aptconf=$(HOME)/apt/apt.conf) ### - @echo $(MAKE) -C $(BUILDDIR)/ GLOBAL_BUILDDIR=$(BUILDDIR) + (cd $(BUILDDIR)/; autoconf; ./configure --with-aptconf=$(HOME)/apt/apt.conf) ### + $(MAKE) -C $(BUILDDIR)/ GLOBAL_BUILDDIR=$(BUILDDIR) @# check iso size diff --git a/sub.in/stage1/Makefile b/sub.in/stage1/Makefile index 5314d6a3..50013b02 100644 --- a/sub.in/stage1/Makefile +++ b/sub.in/stage1/Makefile @@ -1,5 +1,5 @@ -include globals.mk -include functions.mk +include ../globals.mk +include ../functions.mk include $(MKIMAGE_PREFIX)/config.mk include $(GLOBAL_BUILDDIR)/.config.mk diff --git a/sub.in/stage1/initfs b/sub.in/stage1/initfs new file mode 100644 index 00000000..59905b86 --- /dev/null +++ b/sub.in/stage1/initfs @@ -0,0 +1 @@ +file /.VERSION @TMPDIR@/.VERSION 0644 0 0