summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.bottom.mk105
-rw-r--r--common.top.mk47
-rw-r--r--config.mk46
3 files changed, 198 insertions, 0 deletions
diff --git a/common.bottom.mk b/common.bottom.mk
new file mode 100644
index 0000000..0e2c039
--- /dev/null
+++ b/common.bottom.mk
@@ -0,0 +1,105 @@
+# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
+
+include $(topsrcdir)/common.each.mk
+
+
+# Aggregate variables
+
+# Add some more defaults to the *_files variables
+clean_files += $(obj_files)
+conf_files += Makefile $(topobjdir)/config.mk
+# Now namespace the *_files variables
+$(module)_src_files := $(addprefix $(srcdir)/,$(src_files))
+$(module)_obj_files := $(addprefix $(objdir)/,$(obj_files))
+$(module)_sys_files := $(addprefix $(DESTDIR)/,$(sys_files))
+$(module)_clean_files := $(addprefix $(objdir)/,$(clean_files))
+$(module)_slow_files := $(addprefix $(objdir)/,$(slow_files))
+$(module)_conf_files := $(addprefix $(objdir)/,$(conf_files))
+$(module)_dist_files := $(addprefix $(objdir)/,$(dist_files))
+
+# And add them to the $(parent)_*_files variables (if applicable)
+ifneq ($(parent),)
+$(parent)_src_files := $($(parent)_src_files) $($(module)_src_files)
+$(parent)_obj_files := $($(parent)_obj_files) $($(module)_obj_files)
+$(parent)_sys_files := $($(parent)_sys_files) $($(module)_sys_files)
+$(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)
+
+
+# Include Makefiles from other directories
+
+define _nl
+
+
+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)) \
+ _COMMON_MK_NOONCE = $(_COMMON_MK_NOONCE))
+
+
+# This only gets evaluated once, after all of the other Makefiles a read
+ifeq ($(_COMMON_MK_NOONCE),)
+
+.phony = build install uninstall mostlyclean clean distclean maintainer-clean check
+
+# Declare phony targets
+define module_rules
+.PHONY: $(addsuffix -%(module),$(.phony))
+# Constructive phony targets
+build-%(module): $(%(module)_obj_files)
+install-%(module): $(%(module)_sys_files)
+# Destructive phony targets
+_%(module)_uninstall = $(%(module)_sys_files))
+_%(module)_mostlyclean = $(filter-out $(%(module)_slow_files) $(%(module)_conf_files) $(%(module)_dist_files),$(%(module)_clean_files))
+_%(module)_clean = $(filter-out $(%(module)_conf_files) $(%(module)_dist_files),$(%(module)_clean_files))
+_%(module)_distclean = $(filter-out $(%(module)_dist_files),$(%(module)_clean_files))
+_%(module)_maintainer-clean = $(%(module)_clean_files)
+uninstall-%(module) mostlyclean-%(module) clean-%(module) distclean-%(module) maintainer-clean-%(module): %-%(module):
+ $(RM) -- $(sort $(_%(module)_$*))
+ $(RMDIRS) $(sort $(dir $(_%(module)_$*))) 2>/dev/null || $(TRUE)
+endef
+$(foreach module,$(modules),$(eval $(subst %(module),$(module),$(value module_rules))))
+
+# Alias each bare phony target to itself with the `-all` suffix
+$(foreach t,$(.phony),$(eval $t: $t-all))
+
+# Add the `dist` target
+.PHONY: dist
+dist: $(topobjdir)/$(PACKAGE)-$(VERSION).tar.gz
+$(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)
+ $(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) &&) \
+ $(MV) $(@D)/tmp.$(@F).$$$$ $@ || $(RM) -r $(@D)/tmp.$(@F).$$$$
+
+include $(topsrcdir)/common.once.mk
+
+endif
diff --git a/common.top.mk b/common.top.mk
new file mode 100644
index 0000000..931bc84
--- /dev/null
+++ b/common.top.mk
@@ -0,0 +1,47 @@
+# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
+
+# Both of these have the argument order "parent,child"
+_noslash = $(patsubst %/,%,$1)
+_relto = $(call _noslash,$(patsubst $(abspath $1)/%,%,$(abspath $2)/))
+_is_subdir = $(filter $(abspath $1)/%,$(abspath $2)/)
+
+## Declare the standard targets
+all: build
+.PHONY: all
+
+## Set topobjdir, objdir, and srcdir (assumes that topsrcdir is already set)
+ifeq ($(topobjdir),)
+topobjdir := $(call _noslash,$(dir $(lastword $(filter %/config.mk config.mk,$(MAKEFILE_LIST)))))
+endif
+ objdir := $(call _noslash,$(dir $(lastword $(filter-out %.mk,$(MAKEFILE_LIST)))))
+ srcdir := $(firstword $(call _relto,., $(topsrcdir)/$(call _relto,$(topobjdir),$(objdir)) ) .)
+
+## Set module name
+module := $(firstword $(subst /,_,$(if $(call _is_subdir,.,$(objdir)),$(call _relto,.,$(objdir)),dep-$(call _relto,$(topobjdir),$(objdir)))) all)
+
+## Empty variables for use by the module
+subdirs =
+depdirs =
+
+src_files =
+obj_files =
+sys_files =
+
+clean_files =
+
+slow_files =
+conf_files =
+dist_files =
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..a64243b
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,46 @@
+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