summaryrefslogtreecommitdiff
path: root/common.once.head.mk
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-02-08 16:36:45 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-02-08 16:36:45 -0500
commit7e704d7ac997387341e920e1757c24cac0efe5e9 (patch)
treea9f30eabaaad5496397a91053d3e03bab1ea57e4 /common.once.head.mk
parent7785a72495e3eb0ea826b41720c241f58a15b601 (diff)
Refactor the build system. Avoid recursive make.
This looks like a lot, but more things should "just work". We have `make dist` now!
Diffstat (limited to 'common.once.head.mk')
-rw-r--r--common.once.head.mk81
1 files changed, 81 insertions, 0 deletions
diff --git a/common.once.head.mk b/common.once.head.mk
new file mode 100644
index 0000000..f27fe07
--- /dev/null
+++ b/common.once.head.mk
@@ -0,0 +1,81 @@
+# 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/>.
+
+# Configure how Make works
+MAKEFLAGS += --no-builtin-rules --no-builtin-variables
+.SECONDARY:
+.DELETE_ON_ERROR:
+
+.PHONY: FORCE
+
+write-ifchanged = $(topsrcdir)/write-ifchanged
+
+# Magic for tracking variables that affect files. If a file changes
+# based on a variable, just stick $(var)VARNAME as a dependency.
+var = $(call _am_path,$(topoutdir)/.var.)
+$(var)%: FORCE
+ @printf '%s' '$($*)' | $(write-ifchanged) $@
+
+# Usage: <INPUT $(edit) >OUTPUT
+# Expand m4_include macros to use librelib
+# This is used when using sources grabbed from devtools
+# Magic for doing @variable@ replacement in files
+edit = sed \
+ -e 's|^\#!\s*/bin/bash|\#!/usr/bin/env bash|' \
+ -e 's|m4_include(lib/\(.*\))|. "$$(librelib \1)"|' \
+ $(foreach v,$(patsubst $(var)%,%,$(filter $(var)%,$^)), -e 's|@$(v)@|$($(v))|g' )
+
+# Usage: $(call indent,FILENAME)
+# Command to auto-indent a file.
+indent = emacs --batch $1 \
+ --eval '(setq make-backup-files nil)' \
+ --eval '(setq sh-basic-offset 8)' \
+ --eval '(indent-region (point-min) (point-max) nil)' \
+ -f save-buffer &>/dev/null
+
+# Usage <INPUT $(pofmt) >OUTPUT
+# Normalize a .po(t) file
+pofmt = msguniq -Fi --to-code=UTF-8
+
+# It's easy to think of these as "each" variables, but because they
+# will be evaluated on demand, only am_src_files needs to be "each".
+detect-all = $(filter-out $(detect-ignore) ,$(am_src_files))
+detect-exec = $(filter-out $(detect-ignore-exec),$(patsubst $(srcdir)/%,%,$(shell find $(addprefix $(srcdir)/,$(detect-all)) -executable)))
+detect-conf = $(filter-out $(detect-ignore-conf),$(filter %.conf ,$(detect-all)))
+detect-ronn = $(filter-out $(detect-ignore-ronn),$(filter %.ronn ,$(detect-all)))
+detect-md = $(filter-out $(detect-ignore-md) ,$(filter %.ronn %.md,$(detect-all)))
+detect-sh = $(filter-out $(detect-ignore-sh) ,$(filter %.sh ,$(detect-all)))
+
+ifeq ($(wildcard $(topsrcdir)/.git),)
+include $(topsrcdir)/.srcversion-libretools.mk
+else
+$(topsrcdir)/.srcversion-libretools.mk: FORCE
+ @{ \
+ echo LIBRETOOLS_VERSION = $(patsubst v%,%,$(shell cd $(topsrcdir) && git describe --tags)); \
+ echo LIBRETOOLS_COMMIT = $(shell cd $(topsrcdir) && git rev-parse HEAD); \
+ :; } | $(write-ifchanged) $@
+-include $(topsrcdir)/.srcversion-libretools.mk
+endif
+
+ifeq ($(wildcard $(devtoolsdir)/.git),)
+include $(topsrcdir)/.srcversion-devtools.mk
+else
+$(topsrcdir)/.srcversion-devtools.mk: FORCE
+ @{ \
+ echo DEVTOOLS_VERSION = $(patsubst libretools-%,%,$(shell cd $(devtoolsdir) && git describe --tags)); \
+ echo DEVTOOLS_COMMIT = $(shell cd $(devtoolsdir) && git rev-parse HEAD); \
+ :; } | $(write-ifchanged) $@
+-include $(topsrcdir)/.srcversion-devtools.mk
+endif