civodul pushed a commit to tag 1.8
in repository guix.
commit 075cfe3b97bf0e90577bb7e842ba467524fad0ef
Author: Eelco Dolstra <[email protected]>
Date: Fri Sep 5 14:17:05 2014 +0200
Add support for using a build directory
---
functions.mk | 2 +-
lib.mk | 10 ++++++++++
libraries.mk | 4 ++--
patterns.mk | 9 ++++++---
programs.mk | 4 ++--
5 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/functions.mk b/functions.mk
index 45d9173..c48775d 100644
--- a/functions.mk
+++ b/functions.mk
@@ -10,5 +10,5 @@ filename-to-dep = $(dir $1).$(notdir $1).dep
# empty string if not found.
find-program = $(shell for i in $$(IFS=: ; echo $$PATH); do p=$$i/$(strip $1);
if [ -e $$p ]; then echo $$p; break; fi; done)
-# Remove trailing slash.
+# Ensure that the given string ends in a single slash.
add-trailing-slash = $(patsubst %/,%,$(1))/
diff --git a/lib.mk b/lib.mk
index 8b109e2..aa92d8d 100644
--- a/lib.mk
+++ b/lib.mk
@@ -25,6 +25,16 @@ sysconfdir ?= $(prefix)/etc
mandir ?= $(prefix)/share/man
+# Initialise support for build directories.
+builddir ?=
+
+ifdef builddir
+ buildprefix = $(builddir)/
+else
+ buildprefix =
+endif
+
+
# Pass -fPIC if we're building dynamic libraries.
BUILD_SHARED_LIBS ?= 1
diff --git a/libraries.mk b/libraries.mk
index 3b91c69..2064819 100644
--- a/libraries.mk
+++ b/libraries.mk
@@ -45,9 +45,9 @@ endif
# built, otherwise a static library.
define build-library
$(1)_NAME ?= $(1)
- _d := $$(strip $$($(1)_DIR))
+ _d := $(buildprefix)$$(strip $$($(1)_DIR))
_srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src)))
- $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs)))
+ $(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename
$$(_srcs))))
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))
$(1)_INSTALL_DIR ?= $$(libdir)
diff --git a/patterns.mk b/patterns.mk
index 6b2cfd0..3219d96 100644
--- a/patterns.mk
+++ b/patterns.mk
@@ -1,8 +1,11 @@
-%.o: %.cc
+$(buildprefix)%.o: %.cc
+ @mkdir -p "$(dir $@)"
$(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS)
$(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call
filename-to-dep, $@) -MP
-%.o: %.cpp
+$(buildprefix)%.o: %.cpp
+ @mkdir -p "$(dir $@)"
$(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS)
$(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call
filename-to-dep, $@) -MP
-%.o: %.c
+$(buildprefix)%.o: %.c
+ @mkdir -p "$(dir $@)"
$(trace-cc) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS)
-MMD -MF $(call filename-to-dep, $@) -MP
diff --git a/programs.mk b/programs.mk
index 72afdf9..3ac6449 100644
--- a/programs.mk
+++ b/programs.mk
@@ -23,9 +23,9 @@ programs-list :=
# - $(1)_INSTALL_DIR: the directory where the program will be
# installed; defaults to $(bindir).
define build-program
- _d := $$($(1)_DIR)
+ _d := $(buildprefix)$$($(1)_DIR)
_srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src)))
- $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs)))
+ $(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename
$$(_srcs))))
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))
$(1)_PATH := $$(_d)/$(1)