From bce7ec06c4234cb5713bb20350b3aff9010e3703 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 8 Feb 2016 16:36:45 -0500 Subject: (libretools) Refactor the build system. Avoid recursive make. This looks like a lot, but more things should "just work". We have `make dist` now! --- automake.head.mk | 58 +++++++++++++++++++++++ automake.tail.mk | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ automake.txt | 88 ++++++++++++++++++++++++++++++++++ common.bottom.mk | 136 ----------------------------------------------------- common.top.mk | 49 ------------------- config.mk | 46 ------------------ 6 files changed, 286 insertions(+), 231 deletions(-) create mode 100644 automake.head.mk create mode 100644 automake.tail.mk create mode 100644 automake.txt delete mode 100644 common.bottom.mk delete mode 100644 common.top.mk delete mode 100644 config.mk diff --git a/automake.head.mk b/automake.head.mk new file mode 100644 index 0000000..a3c90fd --- /dev/null +++ b/automake.head.mk @@ -0,0 +1,58 @@ +# Copyright (C) 2015-2016 Luke Shumaker +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +_am = am_ + +_am_noslash = $(patsubst %/.,%,$(patsubst %/,%,$1)) +# These are all $(call _am_func,parent,child) +#_am_relto = $(if $2,$(shell realpath -s --relative-to='$1' $2)) +_am_is_subdir = $(filter $(abspath $1)/%,$(abspath $2)/.) +_am_relto_helper = $(if $(call _am_is_subdir,$1,$2),$(patsubst $1/%,%,$(addsuffix /.,$2)),$(addprefix ../,$(call _am_relto_helper,$(patsubst %/,%,$(dir $1)),$2))) +_am_relto = $(call _am_noslash,$(call _am_relto_helper,$(call _am_noslash,$(abspath $1)),$(call _am_noslash,$(abspath $2)))) +# Note that _am_is_subdir says that a directory is a subdirectory of +# itself. +_am_path = $(call _am_relto,.,$1) + +## Declare the default target +all: build +.PHONY: all + +## Set topoutdir, outdir, and srcdir (assumes that topsrcdir is +## already set, and that $(topoutdir)/config.mk has been included) +ifeq ($(topoutdir),) +topoutdir := $(call _am_path,$(dir $(lastword $(filter %/config.mk config.mk,$(MAKEFILE_LIST))))) +endif + outdir := $(call _am_path,$(dir $(lastword $(filter-out %.mk,$(MAKEFILE_LIST))))) + srcdir := $(call _am_path,$(topsrcdir)/$(call _am_relto,$(topoutdir),$(outdir))) + +_am_included_makefiles := $(_am_included_makefiles) $(call _am_path,$(outdir)/Makefile) + +## Empty variables for use by the module +$(_am)subdirs = +$(_am)depdirs = + +$(_am)src_files = +$(_am)gen_files = +$(_am)cfg_files = +$(_am)out_files = +$(_am)sys_files = + +$(_am)clean_files = +$(_am)slow_files = + +ifeq ($(_am_NO_ONCE),) +include $(topsrcdir)/common.once.head.mk +endif +include $(topsrcdir)/common.each.head.mk diff --git a/automake.tail.mk b/automake.tail.mk new file mode 100644 index 0000000..5d6ad00 --- /dev/null +++ b/automake.tail.mk @@ -0,0 +1,140 @@ +# Copyright (C) 2015-2016 Luke Shumaker +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +include $(topsrcdir)/common.each.tail.mk + + +# Aggregate variables + +# Add some more defaults to the *_files variables +$(_am)clean_files += $($(_am)gen_files) $($(_am)out_files) +$(_am)cfg_files += Makefile + +# Now namespace the *_files variables +define _am_save_variables +_am_src_files/$(outdir) = $(addprefix $(srcdir)/,$($(_am)src_files)) +_am_gen_files/$(outdir) = $(addprefix $(srcdir)/,$($(_am)gen_files)) +_am_cfg_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)cfg_files)) +_am_out_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)out_files)) +_am_sys_files/$(outdir) = $(addprefix $(DESTDIR),$($(_am)sys_files)) +_am_clean_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)clean_files)) +_am_slow_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)slow_files)) +_am_subdirs/$(outdir) = $($(_am)subdirs) +endef +$(eval $(_am_save_variables)) + +# And add them to the $(parent)_*_files variables (if applicable) +define _am_add_subdir +_am_src_files/%(outdir) += $(_am_src_files/%(subdir)) +_am_gen_files/%(outdir) += $(_am_gen_files/%(subdir)) +_am_cfg_files/%(outdir) += $(_am_cfg_files/%(subdir)) +_am_out_files/%(outdir) += $(_am_out_files/%(subdir)) +_am_sys_files/%(outdir) += $(_am_sys_files/%(subdir)) +_am_clean_files/%(outdir) += $(_am_clean_files/%(subdir)) +_am_slow_files/%(outdir) += $(_am_slow_files/%(subdir)) +endef +$(foreach subdir,$(call _am_path,$(addprefix $(outdir)/,$($(_am)subdirs))),$(eval $(subst %(outdir),$(outdir),$(subst %(subdir),$(subdir),$(value _am_add_subdir))))) + +_am_outdirs := $(_am_outdirs) $(outdir) + + +# Do some per-directory magic + +_am_phony = build install uninstall mostlyclean clean distclean maintainer-clean check + +.PHONY: $(addprefix $(outdir)/,$(_am_phony)) + +$(addprefix $(outdir)/,uninstall mostlyclean clean distclean maintainer-clean):: + $(RM) -- $(sort $(_am_$(@F)/$(@D))) + $(RMDIRS) $(sort $(dir $(_am_$(@F)/$(@D)))) 2>/dev/null || $(TRUE) + +# 'build' and 'install' must be defined later, because the +# am_*_files/* variables might not be complete yet. + + +# Include Makefiles from other directories + +define _am_nl + + +endef + +$(foreach _am_NO_ONCE,y,\ + $(foreach makefile,$(foreach dir,$($(_am)subdirs) $($(_am)depdirs),$(call _am_path,$(outdir)/$(dir)/Makefile)),\ + $(eval include $(filter-out $(_am_included_makefiles),$(makefile))))) + + +# This only gets evaluated once, after all of the other Makefiles are read +ifeq ($(_am_NO_ONCE),) +# Empty directory-level variables +outdir = /bogus +srcdir = /bogus + +$(_am)subdirs = +$(_am)depdirs = + +$(_am)src_files = +$(_am)gen_files = +$(_am)cfg_files = +$(_am)out_files = +$(_am)sys_files = +$(_am)clean_files = +$(_am)slow_files = + +_am_clean_files/$(topoutdir) += $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz +$(addprefix $(topoutdir)/,mostlyclean clean distclean maintainer-clean) :: + $(RM) -r -- $(topoutdir)/$(PACKAGE)-$(VERSION) + +define _am_directory_rules +# Constructive phony targets +$(outdir)/build : $(_am_out_files/%(outdir)) +$(outdir)/install: $(_am_sys_files/%(outdir)) +# Destructive phony targets +_am_uninstall/%(outdir) = $(_am_sys_files/%(outdir)) +_am_mostlyclean/%(outdir) = $(filter-out $(_am_slow_files/%(outdir)) $(_am_cfg_files/%(outdir)) $(_am_gen_files/%(outdir)),$(_am_clean_files/%(outdir))) +_am_clean/%(outdir) = $(filter-out $(_am_cfg_files/%(outdir)) $(_am_gen_files/%(outdir)),$(_am_clean_files/%(outdir))) +_am_distclean/%(outdir) = $(filter-out $(_am_gen_files/%(outdir)),$(_am_clean_files/%(outdir))) +_am_maintainer-clean/%(outdir) = $(_am_clean_files/%(outdir)) +endef +$(foreach outdir,$(_am_outdirs),$(eval $(subst %(outdir),$(outdir),$(value _am_directory_rules)))) + +# Add the `dist` target +.PHONY: dist +dist: $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz +$(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz: $(topoutdir)/$(PACKAGE)-$(VERSION) + $(TAR) czf $@ -C $(. - -include $(topsrcdir)/common.each.mk - - -# Aggregate variables - -# Add some more defaults to the *_files variables -clean_files += $(out_files) -conf_files += Makefile $(topoutdir)/config.mk -# Now namespace the *_files variables -define _am_add_to_module -_am_$(module)_src_files = $(addprefix $(srcdir)/,$(src_files)) -_am_$(module)_out_files = $(addprefix $(outdir)/,$(out_files)) -_am_$(module)_sys_files = $(addprefix $(DESTDIR),$(sys_files)) -_am_$(module)_clean_files = $(addprefix $(outdir)/,$(clean_files)) -_am_$(module)_slow_files = $(addprefix $(outdir)/,$(slow_files)) -_am_$(module)_conf_files = $(addprefix $(outdir)/,$(conf_files)) -_am_$(module)_dist_files = $(addprefix $(srcdir)/,$(dist_files)) -endef -$(eval $(_am_add_to_module)) - -# And add them to the $(parent)_*_files variables (if applicable) -define _am_add_to_parent -_am_%(parent)_src_files += $(_am_%(module)_src_files) -_am_%(parent)_out_files += $(_am_%(module)_out_files) -_am_%(parent)_sys_files += $(_am_%(module)_sys_files) -_am_%(parent)_clean_files += $(_am_%(module)_clean_files) -_am_%(parent)_slow_files += $(_am_%(module)_slow_files) -_am_%(parent)_conf_files += $(_am_%(module)_conf_files) -_am_%(parent)_dist_files += $(_am_%(module)_dist_files) -endef -ifneq ($(parent),) -$(eval $(subst %(parent),$(parent),$(subst %(module),$(module),$(value _am_add_to_parent)))) -endif - -modules := $(modules) $(module) - - -# Do some per-module magic - -_am_phony = build install uninstall mostlyclean clean distclean maintainer-clean check - -.PHONY: $(addsuffix -%(module),$(_am_phony)) - -$(addsuffix -$(module),uninstall mostlyclean clean distclean maintainer-clean) :: - $(RM) -- $(sort $(_am_$@)) - $(RMDIRS) $(sort $(dir $(_am_$@))) 2>/dev/null || $(TRUE) - - -# Include Makefiles from other directories - -define _am_nl - - -endef -define _am_include_makefile -ifeq ($(filter $(abspath $1),$(included_makefiles)),) -include $(if $(call _am_is_subdir,.,$1),$(call _am_relto,.,$1),$(topoutdir)/$(call _am_relto,$(topoutdir),$1)) -endif -endef -$(eval \ - _am_NO_ONCE = y$(_am_nl)\ - $(foreach dir,$(subdirs),parent=$(module)$(_am_nl)$(call _am_include_makefile,$(outdir)/$(dir)/Makefile)$(_am_nl))\ - parent=dep$(_am_nl)\ - $(call _am_include_makefile,$(topoutdir)/$(dir)/Makefile)$(_am_nl)\ - _am_NO_ONCE = $(_am_NO_ONCE)) - - -# This only gets evaluated once, after all of the other Makefiles are read -ifeq ($(_am_NO_ONCE),) -# Empty module-level variables -outdir = /bogus -srcdir = /bogus -subdirs = -depdirs = -src_files = -out_files = -sys_files = -clean_files = -slow_files = -conf_files = -dist_files = - -ifeq ($(abspath .),$(abspath $(topoutdir))) -_am_all_clean_files += $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz -$(addsuffix -all,mostlyclean clean distclean maintainer-clean) :: - $(RM) -r -- $(topoutdir)/$(PACKAGE)-$(VERSION) -endif - -define _am_module_rules -# Constructive phony targets -build-%(module): $(_am_%(module)_out_files) -install-%(module): $(_am_%(module)_sys_files) -# Destructive phony targets -_am_uninstall-%(module) = $(_am_%(module)_sys_files)) -_am_mostlyclean-%(module) = $(filter-out $(_am_%(module)_slow_files) $(_am_%(module)_conf_files) $(_am_%(module)_dist_files),$(_am_%(module)_clean_files)) -_am_clean-%(module) = $(filter-out $(_am_%(module)_conf_files) $(_am_%(module)_dist_files),$(_am_%(module)_clean_files)) -_am_distclean-%(module) = $(filter-out $(_am_%(module)_dist_files),$(_am_%(module)_clean_files)) -_am_maintainer-clean-%(module) = $(_am_%(module)_clean_files) -endef -$(foreach module,$(modules),$(eval $(subst %(module),$(module),$(value _am_module_rules)))) - -# Alias each bare phony target to itself with the `-all` suffix -$(foreach t,$(_am_phony),$(eval $t: $t-all)) - -# Add the `dist` target -.PHONY: dist -dist: $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz -$(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz: $(topoutdir)/$(PACKAGE)-$(VERSION) - $(TAR) czf $@ -C $(. - -# Both of these have the argument order "parent,child" -_am_noslash = $(patsubst %/,%,$1) -_am_relto = $(call _am_noslash,$(patsubst $(abspath $1)/%,%,$(abspath $2)/)) -_am_is_subdir = $(filter $(abspath $1)/%,$(abspath $2)/) - -## Declare the standard targets -all: build -.PHONY: all - -## Set topoutdir, outdir, and srcdir (assumes that topsrcdir is already set) -ifeq ($(topoutdir),) -topoutdir := $(call _am_noslash,$(dir $(lastword $(filter %/config.mk config.mk,$(MAKEFILE_LIST))))) -endif - outdir := $(call _am_noslash,$(dir $(lastword $(filter-out %.mk,$(MAKEFILE_LIST))))) - srcdir := $(firstword $(call _am_relto,., $(topsrcdir)/$(call _am_relto,$(topoutdir),$(outdir)) ) .) - -included_makefiles := $(included_makefiles) $(abspath $(outdir)/Makefile) - -## Set module name -module := $(subst /,_,$(if $(call _am_is_subdir,.,$(outdir)),$(firstword $(call _am_relto,.,$(outdir)) all),dep-$(firstword $(call _am_relto,$(topoutdir),$(outdir)) top))) - -## Empty variables for use by the module -subdirs = -depdirs = - -src_files = -out_files = -sys_files = - -clean_files = - -slow_files = -conf_files = -dist_files = diff --git a/config.mk b/config.mk deleted file mode 100644 index a64243b..0000000 --- a/config.mk +++ /dev/null @@ -1,46 +0,0 @@ -ifeq ($(topsrcdir),) -topsrcdir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) -endif - -PACKAGE = rvs -VERSION = 0.10 -pkgtextdomain = $(PACKAGE) - -DESTDIR = -prefix = /usr/local -exec_prefix = $(prefix) - -bindir = $(exec_prefix)/bin -sbindir = $(exec_prefix)/sbin -libexecdir = $(exec_prefix)/libexec -datarootdir = $(prefix)/share -datadir = $(datarootdir) -sysconfdir = $(prefix)/etc -sharedstatedir = $(prefix)/com -localstatedir = $(prefix)/var -runstatedir = $(localstatedir)/run -localedir = $(datarootdir)/locale - -pkgdatadir = $(datadir)/$(PACKAGE) -pkglibexecdir = $(libexecdir)/$(PACKAGE) - -CFLAGS = -std=c99 -Werror -Wall -Wextra -pedantic -O2 -CPPFLAGS = -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE - -CC = cc -M4 = m4 -MKDIR = mkdir -MKDIRS = mkdir -p -RMDIRS = rmdir -p -INSTALL_DATA = install -m644 -INSTALL_PROGRAM = install -m755 -CP = cp -MV = mv -RM = rm -f -SED = sed -SORT = sort -TAR = tar -TRUE = true -PRINTF = printf - -AUTODEPS = t -- cgit v1.2.2