diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | common.bottom.mk | 36 | ||||
-rw-r--r-- | common.once.mk | 7 | ||||
-rw-r--r-- | common.top.mk | 4 |
5 files changed, 36 insertions, 19 deletions
@@ -2,3 +2,4 @@ /config.sh *.o .*.mk +/*.tar.* @@ -23,5 +23,12 @@ subdirs = wrapper src_files = Makefile src_files += common.top.mk common.bottom.mk config.mk configure src_files += COPYING HACKING README +obj_files = config.sh config.h + +config_vars = $(shell $(SED) -n 's/^\s*\([a-z][^ !?:=]*\).*=.*/\1/p' $(topobjdir)/config.mk) PACKAGE VERSION DESTDIR +$(objdir)/config.sh: $(objdir)/config.mk + $(PRINTF) '%s=%s\n' $(foreach v,$(config_vars),$v $($v)) | LC_ALL=C $(SORT) > $@ +$(objdir)/config.h: $(objdir)/config.sh + . $(abspath $<) && $(PRINTF) '#define %s "%s"\n' $(foreach v,$(config_vars),$v '$($v)') PACKAGE_UPPER $${PACKAGE^^} | LC_ALL=C $(SORT) > $@ include $(topsrcdir)/common.bottom.mk diff --git a/common.bottom.mk b/common.bottom.mk index 0e2c039..016e093 100644 --- a/common.bottom.mk +++ b/common.bottom.mk @@ -39,9 +39,6 @@ $(parent)_clean_files := $($(parent)_clean_files) $($(module)_clean_files) $(parent)_slow_files := $($(parent)_slow_files) $($(module)_slow_files) $(parent)_conf_files := $($(parent)_conf_files) $($(module)_conf_files) $(parent)_dist_files := $($(parent)_dist_files) $($(module)_dist_files) -$(info added <$(module)> to <$(parent)>) -$(info $(parent)_clean_files => $($(parent)_clean_files)) -$(info $(parent)_obj_files => $($(parent)_obj_files)) endif modules := $(modules) $(module) @@ -53,19 +50,36 @@ define _nl endef +define _include_makefile +ifeq ($(filter $(abspath $1),$(included_makefiles)),) +include $(if $(call _is_subdir,.,$1),$(call _relto,.,$1),$(topobjdir)/$(call _relto,$(topobjdir),$1)) +endif +endef $(eval \ _COMMON_MK_NOONCE = n$(_nl)\ - $(foreach dir,$(subdirs),parent=$(module)$(_nl)include $(objdir)/$(dir)/Makefile$(_nl)) \ - $(foreach dir,$(depdirs),parent=dep $(_nl)include $(objdir)/$(dir)/Makefile$(_nl)) \ + $(foreach dir,$(subdirs),parent=$(module)$(_nl)$(call _include_makefile,$(objdir)/$(dir)/Makefile)$(_nl))\ + parent=dep$(_nl)\ + $(call _include_makefile,$(topobjdir)/$(dir)/Makefile)$(_nl)\ _COMMON_MK_NOONCE = $(_COMMON_MK_NOONCE)) -# This only gets evaluated once, after all of the other Makefiles a read +# This only gets evaluated once, after all of the other Makefiles are read ifeq ($(_COMMON_MK_NOONCE),) - -.phony = build install uninstall mostlyclean clean distclean maintainer-clean check +# Empty module-level variables +objdir = /bogus +srcdir = /bogus +subdirs = +depdirs = +src_files = +obj_files = +sys_files = +clean_files = +slow_files = +conf_files = +dist_files = # Declare phony targets +.phony = build install uninstall mostlyclean clean distclean maintainer-clean check define module_rules .PHONY: $(addsuffix -%(module),$(.phony)) # Constructive phony targets @@ -93,11 +107,11 @@ $(topobjdir)/$(PACKAGE)-$(VERSION).tar.gz: $(topobjdir)/$(PACKAGE)-$(VERSION) $(TAR) czf $@ -C $(<D) $(<F) _copyfile = $(MKDIRS) $(dir $2) && $(CP) $1 $2 _addfile = $(call _copyfile,$3,$2/$(call _relto,$1,$3)) -$(topobjdir)/$(PACKAGE)-$(VERSION): $(all_src_files) $(all_dist_files) +$(topobjdir)/$(PACKAGE)-$(VERSION): $(all_src_files) $(dep_src_files) $(all_dist_files) $(dep_dist_files) $(RM) -r $@ $(MKDIR) $(@D)/tmp.$(@F).$$$$ && \ - $(foreach f,$(all_src_files),$(call _addfile,$(topsrcdir),$(@D)/tmp.$(@F).$$$$,$f) &&) \ - $(foreach f,$(all_dist_files),$(call _addfile,$(topobjdir),$(@D)/tmp.$(@F).$$$$,$f) &&) \ + $(foreach f,$(all_src_files) $(dep_src_files) ,$(call _addfile,$(topsrcdir),$(@D)/tmp.$(@F).$$$$,$f) &&) \ + $(foreach f,$(all_dist_files) $(dep_dist_files),$(call _addfile,$(topobjdir),$(@D)/tmp.$(@F).$$$$,$f) &&) \ $(MV) $(@D)/tmp.$(@F).$$$$ $@ || $(RM) -r $(@D)/tmp.$(@F).$$$$ include $(topsrcdir)/common.once.mk diff --git a/common.once.mk b/common.once.mk index fc0aeb5..0603822 100644 --- a/common.once.mk +++ b/common.once.mk @@ -27,12 +27,5 @@ endif CPPFLAGS += -I$(topobjdir) M4FLAGS += -I$(topobjdir) -all_clean_files += $(topobjdir)/config.sh $(topobjdir)/config.h -config_vars = $(shell $(SED) -n 's/^\s*\([a-z][^ !?:=]*\).*=.*/\1/p' $(topobjdir)/config.mk) PACKAGE VERSION DESTDIR -$(topobjdir)/config.sh: $(topobjdir)/config.mk - $(PRINTF) '%s=%s\n' $(foreach v,$(config_vars),$v $($v)) | LC_ALL=C $(SORT) > $@ -$(topobjdir)/config.h: $(topobjdir)/config.sh - . $(abspath $<) && $(PRINTF) '#define %s "%s"\n' $(foreach v,$(config_vars),$v '$($v)') PACKAGE_UPPER $${PACKAGE^^} | LC_ALL=C $(SORT) > $@ - # Should be on by default .DELETE_ON_ERROR: diff --git a/common.top.mk b/common.top.mk index 931bc84..a83abb6 100644 --- a/common.top.mk +++ b/common.top.mk @@ -29,8 +29,10 @@ endif objdir := $(call _noslash,$(dir $(lastword $(filter-out %.mk,$(MAKEFILE_LIST))))) srcdir := $(firstword $(call _relto,., $(topsrcdir)/$(call _relto,$(topobjdir),$(objdir)) ) .) +included_makefiles := $(included_makefiles) $(abspath $(objdir)/Makefile) + ## Set module name -module := $(firstword $(subst /,_,$(if $(call _is_subdir,.,$(objdir)),$(call _relto,.,$(objdir)),dep-$(call _relto,$(topobjdir),$(objdir)))) all) +module := $(subst /,_,$(if $(call _is_subdir,.,$(objdir)),$(firstword $(call _relto,.,$(objdir)) all),dep-$(firstword $(call _relto,$(topobjdir),$(objdir)) top))) ## Empty variables for use by the module subdirs = |