Add support for using a build directory
This commit is contained in:
parent
afbdd55334
commit
075cfe3b97
5 changed files with 21 additions and 8 deletions
|
@ -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))/
|
||||
|
|
10
lib.mk
10
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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue