2020-03-28 18:46:24 +01:00
|
|
|
# parameters:
|
|
|
|
# $(1): lowercase package name
|
|
|
|
# $(2): uppercase package name
|
|
|
|
# $(3): 32/64, build type
|
2021-09-23 16:47:03 +02:00
|
|
|
# $(4): CROSS/<empty>, cross compile
|
2020-03-28 18:46:24 +01:00
|
|
|
define create-rules-common
|
|
|
|
$(2)_OBJ$(3) := $$(OBJ)/obj-$(1)$(3)
|
2021-01-21 10:30:21 +01:00
|
|
|
$(2)_DST$(3) := $$(OBJ)/dst-$(1)$(3)
|
2020-03-28 18:46:24 +01:00
|
|
|
$(2)_DEPS$(3) := $$(call toupper,$$($(2)_DEPENDS)) $$(call toupper,$$($(2)_DEPENDS$(3)))
|
|
|
|
|
|
|
|
$(2)_BINDIR$(3) ?= $$($(2)_DST$(3))/bin
|
|
|
|
$(2)_LIBDIR$(3) ?= $$($(2)_DST$(3))/lib$(subst 32,,$(3))
|
|
|
|
$(2)_INCDIR$(3) ?= $$($(2)_DST$(3))/include
|
|
|
|
|
|
|
|
$$(OBJ)/.$(1)-configure$(3): $$(shell mkdir -p $$($(2)_OBJ$(3)))
|
|
|
|
$$(OBJ)/.$(1)-configure$(3): CCACHE_BASEDIR = $$($(2)_SRC)
|
|
|
|
$$(OBJ)/.$(1)-configure$(3): $$(patsubst %,%-build$(3),$$($(2)_DEPENDS) $$($(2)_DEPENDS$(3)))
|
|
|
|
|
|
|
|
$(1)-configure$(3): $$(OBJ)/.$(1)-configure$(3)
|
|
|
|
.INTERMEDIATE: $(1)-configure$(3)
|
|
|
|
|
|
|
|
all-configure$(3) $(1)-configure: $(1)-configure$(3)
|
|
|
|
.PHONY: all-configure$(3) $(1)-configure
|
|
|
|
|
|
|
|
all-configure: $(1)-configure
|
|
|
|
.PHONY: all-configure
|
|
|
|
|
|
|
|
|
|
|
|
$$(OBJ)/.$(1)-build$(3): CCACHE_BASEDIR = $$($(2)_SRC)
|
|
|
|
$$(OBJ)/.$(1)-build$(3): $$(OBJ)/.$(1)-source
|
|
|
|
$$(OBJ)/.$(1)-build$(3): $$(OBJ)/.$(1)-configure$(3)
|
|
|
|
|
|
|
|
ifeq ($(CONTAINER),)
|
|
|
|
$$(OBJ)/.$(1)-build$(3): container-build
|
|
|
|
$$(OBJ)/.$(1)-post-build$(3): container-build
|
2021-01-21 10:30:21 +01:00
|
|
|
$$(OBJ)/.$(1)-dist$(3): container-build
|
2020-03-28 18:46:24 +01:00
|
|
|
else
|
|
|
|
$$(OBJ)/.$(1)-post-build$(3): $$(OBJ)/.$(1)-build$(3)
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(1)-build$(3): $$(OBJ)/.$(1)-build$(3)
|
|
|
|
.INTERMEDIATE: $(1)-build$(3)
|
|
|
|
|
|
|
|
all-build$(3) $(1)-build: $(1)-build$(3)
|
|
|
|
.PHONY: all-build$(3) $(1)-build
|
|
|
|
|
|
|
|
all-build: $(1)-build
|
|
|
|
.PHONY: all-build
|
|
|
|
|
|
|
|
|
2021-01-21 10:30:21 +01:00
|
|
|
ifeq ($(CONTAINER),1)
|
|
|
|
$$(OBJ)/.$(1)-dist$(3): $$(OBJ)/.$(1)-build$(3)
|
|
|
|
$$(OBJ)/.$(1)-dist$(3): $$(OBJ)/.$(1)-post-build$(3)
|
|
|
|
|
|
|
|
ifneq ($(UNSTRIPPED_BUILD),)
|
|
|
|
$$(OBJ)/.$(1)-dist$(3):
|
|
|
|
@echo ":: installing $(3)bit $(1)..." >&2
|
|
|
|
mkdir -p $$($(2)_LIBDIR$(3))/ $$(DST_LIBDIR$(3))/
|
2021-05-28 10:50:59 +02:00
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type f -printf '$$(DST_LIBDIR$(3))/%h\0' | sort -z | uniq -z | xargs $(--verbose?) -0 -r -P$$(J) mkdir -p
|
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type l -printf '%p\0$$(DST_LIBDIR$(3))/%p\0' | xargs $(--verbose?) -0 -r -P$$(J) -n2 cp -a
|
2022-08-03 15:00:45 +02:00
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type f -not '(' -iname '*.pc' -or -iname '*.cmake' -or -iname '*.a' -or -iname '*.la' -or -iname '*.def' -or -iname '*.h' ')' \
|
2021-01-21 10:30:21 +01:00
|
|
|
-printf '--only-keep-debug\0%p\0$$(DST_LIBDIR$(3))/%p.debug\0' | \
|
2022-02-21 11:08:04 +01:00
|
|
|
xargs $(--verbose?) -0 -r -P$$(J) -n3 objcopy --file-alignment=4096
|
2022-08-03 15:00:45 +02:00
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type f -not '(' -iname '*.pc' -or -iname '*.cmake' -or -iname '*.a' -or -iname '*.la' -or -iname '*.def' -or -iname '*.h' ')' \
|
2021-01-21 10:30:21 +01:00
|
|
|
-printf '--add-gnu-debuglink=$$(DST_LIBDIR$(3))/%p.debug\0--strip-debug\0%p\0$$(DST_LIBDIR$(3))/%p\0' | \
|
2022-02-15 17:20:52 +01:00
|
|
|
xargs $(--verbose?) -0 -r -P$$(J) -n4 objcopy --file-alignment=4096 --set-section-flags .text=contents,alloc,load,readonly,code
|
2021-01-21 10:30:21 +01:00
|
|
|
touch $$@
|
|
|
|
else
|
|
|
|
$$(OBJ)/.$(1)-dist$(3):
|
|
|
|
@echo ":: installing $(3)bit $(1)..." >&2
|
|
|
|
mkdir -p $$($(2)_LIBDIR$(3))/ $$(DST_LIBDIR$(3))/
|
2021-05-28 10:50:59 +02:00
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type f -printf '$$(DST_LIBDIR$(3))/%h\0' | sort -z | uniq -z | xargs $(--verbose?) -0 -r -P$$(J) mkdir -p
|
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type l -printf '%p\0$$(DST_LIBDIR$(3))/%p\0' | xargs $(--verbose?) -0 -r -P$$(J) -n2 cp -a
|
2022-08-03 15:00:45 +02:00
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type f -not '(' -iname '*.pc' -or -iname '*.cmake' -or -iname '*.a' -or -iname '*.la' -or -iname '*.def' -or -iname '*.h' ')' \
|
2021-05-28 10:50:59 +02:00
|
|
|
-printf '$$(DST_LIBDIR$(3))/%p.debug\0' | xargs $(--verbose?) -0 -r -P$$(J) rm -f
|
2022-08-03 15:00:45 +02:00
|
|
|
cd $$($(2)_LIBDIR$(3)) && find -type f -not '(' -iname '*.pc' -or -iname '*.cmake' -or -iname '*.a' -or -iname '*.la' -or -iname '*.def' -or -iname '*.h' ')' \
|
2021-01-21 10:30:21 +01:00
|
|
|
-printf '--strip-debug\0%p\0$$(DST_LIBDIR$(3))/%p\0' | \
|
2022-02-15 17:20:52 +01:00
|
|
|
xargs $(--verbose?) -0 -r -P$$(J) -n3 objcopy --file-alignment=4096 --set-section-flags .text=contents,alloc,load,readonly,code
|
2021-01-21 10:30:21 +01:00
|
|
|
touch $$@
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(1)-dist$(3): $$(OBJ)/.$(1)-dist$(3)
|
|
|
|
.INTERMEDIATE: $(1)-dist$(3)
|
|
|
|
|
|
|
|
all-dist$(3) $(1)-dist: $(1)-dist$(3)
|
|
|
|
.PHONY: all-dist$(3) $(1)-dist
|
|
|
|
|
|
|
|
all-dist: $(1)-dist
|
|
|
|
.PHONY: all-dist
|
|
|
|
|
|
|
|
|
|
|
|
$(1)$(3): $(1)-configure$(3) $(1)-build$(3) $(1)-dist$(3)
|
2020-03-28 18:46:24 +01:00
|
|
|
.INTERMEDIATE: $(1)$(3)
|
|
|
|
|
|
|
|
all$(3) $(1): $(1)$(3)
|
|
|
|
.PHONY: all$(3) $(1)
|
|
|
|
|
|
|
|
all: $(1)
|
|
|
|
.PHONY: all
|
|
|
|
|
2021-04-02 12:40:30 +02:00
|
|
|
CONTAINERGOALS := $(CONTAINERGOALS) $(filter $(1),$(MAKECMDGOALS))
|
|
|
|
|
2021-09-23 16:47:03 +02:00
|
|
|
$(2)_INCFLAGS$(3) = $$(foreach d,$$($(2)_DEPS$(3)),-I$$($$(d)_INCDIR$(3)))
|
|
|
|
$(2)_LIBFLAGS$(3) = $$(foreach d,$$($(2)_DEPS$(3)),-L$$($$(d)_LIBDIR$(3))) \
|
|
|
|
$$(foreach d,$$($(2)_DEPS$(3)),-Wl,-rpath-link=$$($$(d)_LIBDIR$(3))) \
|
|
|
|
|
|
|
|
# PKG_CONFIG is intentionally never using CROSS target, as it's missing
|
|
|
|
# wrapper scripts in the toolchain, we use PKG_CONFIG_LIBDIR directly
|
|
|
|
# instead.
|
2021-11-11 04:03:26 +01:00
|
|
|
#
|
|
|
|
# RC and WIDL are intentionally always using CROSS target, as their
|
|
|
|
# native version doesn't exist.
|
2020-03-28 18:46:24 +01:00
|
|
|
|
|
|
|
$(2)_ENV$(3) = \
|
2021-09-23 16:47:03 +02:00
|
|
|
CARGO_TARGET_$$(call toupper,$$(CARGO_TARGET_$(3)))_LINKER="$$(TARGET_$(4)$(3))-gcc" \
|
2020-03-28 18:46:24 +01:00
|
|
|
CCACHE_BASEDIR="$$(CCACHE_BASEDIR)" \
|
|
|
|
STRIP="$$(STRIP)" \
|
2021-09-23 16:47:03 +02:00
|
|
|
AR="$$(TARGET_$(4)$(3))-ar" \
|
|
|
|
RANLIB="$$(TARGET_$(4)$(3))-ranlib" \
|
2021-11-12 11:23:36 +01:00
|
|
|
CC="$$(TARGET_$(4)$(3))-gcc" \
|
|
|
|
CXX="$$(TARGET_$(4)$(3))-g++" \
|
2021-09-23 16:47:03 +02:00
|
|
|
LD="$$(TARGET_$(4)$(3))-ld" \
|
2021-11-11 04:03:26 +01:00
|
|
|
RC="$$(TARGET_CROSS$(3))-windres" \
|
|
|
|
WIDL="$$(TARGET_CROSS$(3))-widl" \
|
2021-09-23 16:47:03 +02:00
|
|
|
PKG_CONFIG="$$(TARGET_$(3))-pkg-config" \
|
2022-09-12 22:25:26 +02:00
|
|
|
PATH="$$(call list-join,:,$$(foreach d,$$($(2)_DEPS$(3)),$$($$(d)_BINDIR$(3))),,:):$$$$PATH" \
|
2021-01-21 10:30:21 +01:00
|
|
|
LD_LIBRARY_PATH="$$(call list-join,:,$$(foreach d,$$($(2)_DEPS$(3)),$$($$(d)_LIBDIR$(3))),,:)$$$$LD_LIBRARY_PATH" \
|
|
|
|
PKG_CONFIG_PATH="$$(call list-join,:,$$(foreach d,$$($(2)_DEPS$(3)),$$($$(d)_LIBDIR$(3))/pkgconfig))" \
|
2021-09-23 16:47:03 +02:00
|
|
|
PKG_CONFIG_LIBDIR="/usr/lib/$$(PKG_CONFIG_TARGET_$(4)$(3))/pkgconfig:/usr/share/pkgconfig" \
|
|
|
|
CFLAGS="$$($(2)_INCFLAGS$(3)) $$($(2)_CFLAGS) $$(COMMON_FLAGS) $$(COMMON_FLAGS$(3))" \
|
|
|
|
CPPFLAGS="$$($(2)_INCFLAGS$(3)) $$($(2)_CPPFLAGS) $$(COMMON_FLAGS) $$(COMMON_FLAGS$(3))" \
|
|
|
|
CXXFLAGS="$$($(2)_INCFLAGS$(3)) $$($(2)_CXXFLAGS) $$(COMMON_FLAGS) $$(COMMON_FLAGS$(3)) -std=c++17" \
|
|
|
|
LDFLAGS="$$($(2)_LIBFLAGS$(3)) $$($(2)_LDFLAGS$(3)) $$($(2)_LDFLAGS) $$($(4)LDFLAGS)" \
|
|
|
|
|
|
|
|
ifneq ($(4),CROSS)
|
|
|
|
|
|
|
|
# CROSS-prefixed variables for non-CROSS builds which may need to cross
|
|
|
|
# compile some binaries.
|
|
|
|
#
|
|
|
|
# This is for instance used by Wine, but also Meson, as it requires the
|
|
|
|
# environment variable to ones for native.
|
|
|
|
|
|
|
|
$(2)_ENV$(3) += \
|
|
|
|
CROSSAR="$$(TARGET_CROSS$(3))-ar" \
|
|
|
|
CROSSRANLIB="$$(TARGET_CROSS$(3))-ranlib" \
|
2021-11-12 11:23:36 +01:00
|
|
|
CROSSCC="$$(TARGET_CROSS$(3))-gcc" \
|
|
|
|
CROSSCXX="$$(TARGET_CROSS$(3))-g++" \
|
2021-09-23 16:47:03 +02:00
|
|
|
CROSSLD="$$(TARGET_CROSS$(3))-ld" \
|
|
|
|
CROSSCFLAGS="$$($(2)_INCFLAGS$(3)) $$($(2)_CFLAGS) $$(COMMON_FLAGS) $$(COMMON_FLAGS$(3))" \
|
|
|
|
CROSSCPPFLAGS="$$($(2)_INCFLAGS$(3)) $$($(2)_CPPFLAGS) $$(COMMON_FLAGS) $$(COMMON_FLAGS$(3))" \
|
|
|
|
CROSSCXXFLAGS="$$($(2)_INCFLAGS$(3)) $$($(2)_CXXFLAGS) $$(COMMON_FLAGS) $$(COMMON_FLAGS$(3)) -std=c++17" \
|
|
|
|
CROSSLDFLAGS="$$($(2)_LIBFLAGS$(3)) $$($(2)_LDFLAGS$(3)) $$($(2)_LDFLAGS) $$(CROSSLDFLAGS)" \
|
|
|
|
CROSSPKG_CONFIG_LIBDIR="/usr/lib/$$(PKG_CONFIG_TARGET_CROSS$(3))/pkgconfig:/usr/share/pkgconfig" \
|
|
|
|
|
|
|
|
endif
|
2020-03-28 18:46:24 +01:00
|
|
|
|
|
|
|
endef
|
|
|
|
|
2021-01-21 10:30:21 +01:00
|
|
|
ifneq ($(UNSTRIPPED_BUILD),)
|
|
|
|
install-strip = objcopy --file-alignment=4096 --only-keep-debug $(1) $(2)/$(notdir $(1)).debug && \
|
|
|
|
objcopy --file-alignment=4096 --add-gnu-debuglink=$(2)/$(notdir $(1)).debug --strip-debug $(1) $(2)/$(notdir $(1))
|
|
|
|
else
|
|
|
|
install-strip = objcopy --file-alignment=4096 --strip-debug $(1) $(2)/$(notdir $(1)) && rm -f $(2)/$(notdir $(1)).debug
|
|
|
|
endif
|
|
|
|
|
2021-09-23 16:47:03 +02:00
|
|
|
TARGET_32 := i686-linux-gnu
|
|
|
|
TARGET_64 := x86_64-linux-gnu
|
|
|
|
TARGET_CROSS32 := i686-w64-mingw32
|
|
|
|
TARGET_CROSS64 := x86_64-w64-mingw32
|
|
|
|
|
|
|
|
PKG_CONFIG_TARGET_32 := i386-linux-gnu
|
|
|
|
PKG_CONFIG_TARGET_64 := x86_64-linux-gnu
|
|
|
|
PKG_CONFIG_TARGET_CROSS32 := i386-w64-mingw32
|
|
|
|
PKG_CONFIG_TARGET_CROSS64 := x86_64-w64-mingw32
|
2020-03-28 18:46:24 +01:00
|
|
|
|
2021-10-01 17:24:17 +02:00
|
|
|
LIBDIR_WINE_32 := wine/i386-unix
|
|
|
|
LIBDIR_WINE_64 := wine/x86_64-unix
|
|
|
|
LIBDIR_WINE_CROSS32 := wine/i386-windows
|
|
|
|
LIBDIR_WINE_CROSS64 := wine/x86_64-windows
|
|
|
|
|
2020-03-28 18:46:24 +01:00
|
|
|
$(OBJ)/.%-post-build32:
|
|
|
|
touch $@
|
|
|
|
$(OBJ)/.%-post-build64:
|
|
|
|
touch $@
|
|
|
|
|
2021-09-23 16:47:03 +02:00
|
|
|
rules-common = $(call create-rules-common,$(1),$(call toupper,$(1)),$(2),$(3))
|