diff --git a/make/configure.mk b/make/configure.mk index aca76ec..e41007f 100644 --- a/make/configure.mk +++ b/make/configure.mk @@ -1,6 +1,6 @@ # -# Copyright (C) 2020 Linux Studio Plugins Project -# (C) 2020 Vladimir Sadovnikov +# Copyright (C) 2024 Linux Studio Plugins Project +# (C) 2024 Vladimir Sadovnikov # # This file is part of lsp-common-lib # @@ -268,8 +268,9 @@ $(CONFIG_VARS): prepare echo "$(@)=$($(@))" >> "$(CONFIG)" config: $(CONFIG_VARS) - echo "Architecture: $(ARCHITECTURE_FAMILY)/$(ARCHITECTURE) ($(ARCHITECTURE_CFLAGS))" - echo "Features: $(FEATURES)" + echo "Host architecture: $(HOST_ARCHITECTURE_FAMILY)/$(HOST_ARCHITECTURE) ($(HOST_ARCHITECTURE_CFLAGS))" + echo "Architecture: $(ARCHITECTURE_FAMILY)/$(ARCHITECTURE) ($(ARCHITECTURE_CFLAGS))" + echo "Features: $(FEATURES)" echo "Configured OK" help: | pathvars toolvars sysvars diff --git a/make/modules.mk b/make/modules.mk index bf2ff52..b451162 100644 --- a/make/modules.mk +++ b/make/modules.mk @@ -1,6 +1,6 @@ # -# Copyright (C) 2020 Linux Studio Plugins Project -# (C) 2020 Vladimir Sadovnikov +# Copyright (C) 2024 Linux Studio Plugins Project +# (C) 2024 Vladimir Sadovnikov # # This file is part of lsp-common-lib # @@ -45,9 +45,15 @@ UNIQ_ALL_DEPENDENCIES := $(filter-out $(ARTIFACT_ID),$(call uniq, $(ALL_DEP MODULES ?= $(BASEDIR)/modules GIT ?= git +ifeq ($(DEVEL),1) + X_URL_SUFFIX = _RW +else + X_URL_SUFFIX = _RO +endif + ifeq ($(TREE),1) $(foreach dep,$(UNIQ_ALL_DEPENDENCIES), \ - $(eval $(dep)_URL=$($(dep)_URL_RO)) \ + $(eval $(dep)_URL=$($(dep)_URL$(X_URL_SUFFIX))) \ ) ifeq ($(findstring -devel,$(ARTIFACT_VERSION)),-devel) diff --git a/make/paths.mk b/make/paths.mk index 6bcb03e..725466c 100644 --- a/make/paths.mk +++ b/make/paths.mk @@ -22,6 +22,8 @@ ifndef PREFIX ifeq ($(PLATFORM),Windows) PREFIX := $(BASEDIR)/INSTALL + else ifeq ($(CROSS_COMPILE),1) + PREFIX := $(BASEDIR)/INSTALL else PREFIX := /usr/local endif diff --git a/make/system.mk b/make/system.mk index f7ffc14..dbb7311 100644 --- a/make/system.mk +++ b/make/system.mk @@ -38,110 +38,119 @@ ifndef PLATFORM PLATFORM := Linux else ifeq ($(findstring SunOS,$(BUILD_SYSTEM)),SunOS) PLATFORM := Solaris + else ifeq ($(findstring Darwin,$(BUILD_SYSTEM)),Darwin) + PLATFORM := MacOS else ifeq ($(findstring Haiku,$(BUILD_SYSTEM)),Haiku) PLATFORM := Haiku endif endif # Detect system processor architecture -ifndef ARCHITECTURE - ifeq ($(PLATFORM),Windows) - BUILD_ARCH := $(PROCESSOR_ARCHITECTURE) - else - BUILD_ARCH := $(shell uname -m) - endif +ifeq ($(PLATFORM),Windows) + HOST_BUILD_ARCH := $(PROCESSOR_ARCHITECTURE) else - BUILD_ARCH := $(ARCHITECTURE) + HOST_BUILD_ARCH := $(shell uname -m) endif +BUILD_ARCH := $(if $(ARCHITECTURE),$(ARCHITECTURE),$(HOST_BUILD_ARCH)) -# Set actual architecture +# Set actual architecture for HOST and TARGET builds # The current architecture can be obtained by: gcc -Q --help=target -ifeq ($(BUILD_ARCH),armel) - override ARCHITECTURE = $(BUILD_ARCH) - ARCHITECTURE_FAMILY = generic - ARCHITECTURE_CFLAGS := -else ifeq ($(BUILD_ARCH),armhf) - override ARCHITECTURE = arm32 - ARCHITECTURE_FAMILY = arm32 - ARCHITECTURE_CFLAGS := -march=armv7-a+fp -marm -else ifeq ($(patsubst armv6%,armv6,$(BUILD_ARCH)),armv6) - override ARCHITECTURE = arm32 - ARCHITECTURE_FAMILY = arm32 - ARCHITECTURE_CFLAGS := -march=armv6 -marm -else ifeq ($(patsubst armv7ve%,armv7ve,$(BUILD_ARCH)),armv7ve) - override ARCHITECTURE = arm32 - ARCHITECTURE_FAMILY = arm32 - ARCHITECTURE_CFLAGS := -march=armv7ve -marm -else ifeq ($(patsubst armv7%,armv7,$(BUILD_ARCH)),armv7) - override ARCHITECTURE = arm32 - ARCHITECTURE_FAMILY = arm32 - ARCHITECTURE_CFLAGS := -march=armv7-a -marm -else ifeq ($(patsubst armv8%,armv8,$(BUILD_ARCH)),armv8) - override ARCHITECTURE = arm32 - ARCHITECTURE_FAMILY = arm32 - ARCHITECTURE_CFLAGS := -march=armv7-a -marm -else ifeq ($(patsubst aarch64%,aarch64,$(BUILD_ARCH)),aarch64) - override ARCHITECTURE = aarch64 - ARCHITECTURE_FAMILY = aarch64 - ARCHITECTURE_CFLAGS := -march=armv8-a -else ifeq ($(BUILD_ARCH),arm64) - override ARCHITECTURE = aarch64 - ARCHITECTURE_FAMILY = aarch64 - ARCHITECTURE_CFLAGS := -march=armv8-a -else ifeq ($(BUILD_ARCH),arm32) - override ARCHITECTURE = arm32 - ARCHITECTURE_FAMILY = arm32 - ARCHITECTURE_CFLAGS := -march=armv6 -marm -else ifeq ($(BUILD_ARCH),arm) - override ARCHITECTURE = arm32 - ARCHITECTURE_FAMILY = arm32 - ARCHITECTURE_CFLAGS := -march=armv6 -marm -else ifeq ($(patsubst %x86_64%,x86_64,$(BUILD_ARCH)),x86_64) - override ARCHITECTURE = x86_64 - ARCHITECTURE_FAMILY = x86_64 - ARCHITECTURE_CFLAGS := -march=x86-64 -m64 -else ifeq ($(patsubst %amd64%,amd64,$(BUILD_ARCH)),amd64) - override ARCHITECTURE = x86_64 - ARCHITECTURE_FAMILY = x86_64 - ARCHITECTURE_CFLAGS := -march=x86-64 -m64 -else ifeq ($(patsubst %AMD64%,AMD64,$(BUILD_ARCH)),AMD64) - override ARCHITECTURE = x86_64 - ARCHITECTURE_FAMILY = x86_64 - ARCHITECTURE_CFLAGS := -march=x86-64 -m64 -else ifeq ($(BUILD_ARCH),i86pc) - override ARCHITECTURE = x86_64 - ARCHITECTURE_FAMILY = x86_64 - ARCHITECTURE_CFLAGS := -march=x86-64 -m64 -else ifeq ($(patsubst %i686%,i686,$(BUILD_ARCH)),i686) - override ARCHITECTURE = i686 - ARCHITECTURE_FAMILY = ia32 - ARCHITECTURE_CFLAGS := -march=i686 -m32 -else ifeq ($(patsubst i%86,i586,$(BUILD_ARCH)),i586) - override ARCHITECTURE = i586 - ARCHITECTURE_FAMILY = ia32 - ARCHITECTURE_CFLAGS := -march=i586 -m32 -else ifeq ($(BUILD_ARCH),x86) - override ARCHITECTURE = i686 - ARCHITECTURE_FAMILY = ia32 - ARCHITECTURE_CFLAGS := -march=i686 -m32 -else ifeq ($(BUILD_ARCH),riscv32) - override ARCHITECTURE = riscv32 - ARCHITECTURE_FAMILY = riscv32 - ARCHITECTURE_CFLAGS := -march=rv32imafdc -mabi=lp32d -else ifeq ($(BUILD_ARCH),riscv64) - override ARCHITECTURE = riscv64 - ARCHITECTURE_FAMILY = riscv64 - ARCHITECTURE_CFLAGS := -march=rv64imafdc -mabi=lp64d -else - override ARCHITECTURE = $(BUILD_ARCH) - ARCHITECTURE_FAMILY = generic - ARCHITECTURE_CFLAGS := -endif +define detect_architecture = + ifeq ($(1),armel) + $(2)_NAME = $(1) + $(2)_FAMILY = generic + $(2)_CFLAGS := + else ifeq ($(1),armhf) + $(2)_NAME = arm32 + $(2)_FAMILY = arm32 + $(2)_CFLAGS := -march=armv7-a+fp -marm + else ifeq ($(patsubst armv6%,armv6,$(1)),armv6) + $(2)_NAME = arm32 + $(2)_FAMILY = arm32 + $(2)_CFLAGS := -march=armv6 -marm + else ifeq ($(patsubst armv7ve%,armv7ve,$(1)),armv7ve) + $(2)_NAME = arm32 + $(2)_FAMILY = arm32 + $(2)_CFLAGS := -march=armv7ve -marm + else ifeq ($(patsubst armv7%,armv7,$(1)),armv7) + $(2)_NAME = arm32 + $(2)_FAMILY = arm32 + $(2)_CFLAGS := -march=armv7-a -marm + else ifeq ($(patsubst armv8%,armv8,$(1)),armv8) + $(2)_NAME = arm32 + $(2)_FAMILY = arm32 + $(2)_CFLAGS := -march=armv7-a -marm + else ifeq ($(patsubst aarch64%,aarch64,$(1)),aarch64) + $(2)_NAME = aarch64 + $(2)_FAMILY = aarch64 + $(2)_CFLAGS := -march=armv8-a + else ifeq ($(1),arm64) + $(2)_NAME = aarch64 + $(2)_FAMILY = aarch64 + $(2)_CFLAGS := -march=armv8-a + else ifeq ($(1),arm32) + $(2)_NAME = arm32 + $(2)_FAMILY = arm32 + $(2)_CFLAGS := -march=armv6 -marm + else ifeq ($(1),arm) + $(2)_NAME = arm32 + $(2)_FAMILY = arm32 + $(2)_CFLAGS := -march=armv6 -marm + else ifeq ($(patsubst %x86_64%,x86_64,$(1)),x86_64) + $(2)_NAME = x86_64 + $(2)_FAMILY = x86_64 + $(2)_CFLAGS := -march=x86-64 -m64 + else ifeq ($(patsubst %amd64%,amd64,$(1)),amd64) + $(2)_NAME = x86_64 + $(2)_FAMILY = x86_64 + $(2)_CFLAGS := -march=x86-64 -m64 + else ifeq ($(patsubst %AMD64%,AMD64,$(1)),AMD64) + $(2)_NAME = x86_64 + $(2)_FAMILY = x86_64 + $(2)_CFLAGS := -march=x86-64 -m64 + else ifeq ($(1),i86pc) + $(2)_NAME = x86_64 + $(2)_FAMILY = x86_64 + $(2)_CFLAGS := -march=x86-64 -m64 + else ifeq ($(patsubst %i686%,i686,$(1)),i686) + $(2)_NAME = i686 + $(2)_FAMILY = ia32 + $(2)_CFLAGS := -march=i686 -m32 + else ifeq ($(patsubst i%86,i586,$(1)),i586) + $(2)_NAME = i586 + $(2)_FAMILY = ia32 + $(2)_CFLAGS := -march=i586 -m32 + else ifeq ($(1),x86) + $(2)_NAME = i686 + $(2)_FAMILY = ia32 + $(2)_CFLAGS := -march=i686 -m32 + else ifeq ($(1),riscv32) + $(2)_NAME = riscv32 + $(2)_FAMILY = riscv32 + $(2)_CFLAGS := -march=rv32imafdc -mabi=lp32d + else ifeq ($(1),riscv64) + $(2)_NAME = riscv64 + $(2)_FAMILY = riscv64 + $(2)_CFLAGS := -march=rv64imafdc -mabi=lp64d + else + $(2)_NAME = $(1) + $(2)_FAMILY = generic + $(2)_CFLAGS := + endif +endef + +$(eval $(call detect_architecture,$(BUILD_ARCH),ARCHITECTURE)) +$(eval $(call detect_architecture,$(HOST_BUILD_ARCH),HOST_ARCHITECTURE)) + +override ARCHITECTURE = $(ARCHITECTURE_NAME) +override HOST_ARCHITECTURE = $(HOST_ARCHITECTURE_NAME) # Extension of libraries ifndef LIBRARY_EXT ifeq ($(PLATFORM),Windows) LIBRARY_EXT := .dll + else ifeq ($(PLATFORM),MacOS) + LIBRARY_EXT := .dylib else LIBRARY_EXT := .so endif @@ -187,6 +196,9 @@ COMMON_VARS = \ EXECUTABLE_EXT \ EXPORT_SYMBOLS \ FEATURES \ + HOST_ARCHITECTURE \ + HOST_ARCHITECTURE_FAMILY \ + HOST_ARCHITECTURE_CFLAGS \ INSTALL_HEADERS \ LIBRARY_EXT \ LIBRARY_PREFIX \ diff --git a/make/tools.mk b/make/tools.mk index ca42c8e..49c3540 100644 --- a/make/tools.mk +++ b/make/tools.mk @@ -1,6 +1,6 @@ # -# Copyright (C) 2020 Linux Studio Plugins Project -# (C) 2020 Vladimir Sadovnikov +# Copyright (C) 2024 Linux Studio Plugins Project +# (C) 2024 Vladimir Sadovnikov # # This file is part of lsp-common-lib # @@ -27,6 +27,20 @@ ifeq ($(PLATFORM),OpenBSD) X_AR_TOOL := ar X_LD_TOOL := ld X_PKG_CONFIG := pkg-config +else ifeq ($(PLATFORM),BSD) + X_CC_TOOL := clang + X_CXX_TOOL := clang++ + X_AS_TOOL := as + X_AR_TOOL := ar + X_LD_TOOL := ld + X_PKG_CONFIG := pkg-config +else ifeq ($(PLATFORM),MacOS) + X_CC_TOOL := clang + X_CXX_TOOL := clang++ + X_AS_TOOL := as + X_AR_TOOL := ar + X_LD_TOOL := ld + X_PKG_CONFIG := pkg-config else X_CC_TOOL := gcc X_CXX_TOOL := g++ @@ -49,26 +63,36 @@ PHP ?= $(X_PHP_TOOL) PKG_CONFIG ?= $(X_PKG_CONFIG) # Define tool variables for host build -HOST_CC ?= $(CC) -HOST_CXX ?= $(CXX) -HOST_AS ?= $(AS) -HOST_AR ?= $(AR) -HOST_LD ?= $(LD) -HOST_PHP ?= $(PHP) -HOST_PKG_CONFIG ?= $(PKG_CONFIG) +ifeq ($(CROSS_COMPILE),1) + HOST_CC ?= $(X_CC_TOOL) + HOST_CXX ?= $(X_CXX_TOOL) + HOST_AS ?= $(X_AS_TOOL) + HOST_AR ?= $(X_AR_TOOL) + HOST_LD ?= $(X_LD_TOOL) + HOST_PHP ?= $(X_PHP_TOOL) + HOST_PKG_CONFIG ?= $(X_PKG_CONFIG) +else + HOST_CC ?= $(CC) + HOST_CXX ?= $(CXX) + HOST_AS ?= $(AS) + HOST_AR ?= $(AR) + HOST_LD ?= $(LD) + HOST_PHP ?= $(PHP) + HOST_PKG_CONFIG ?= $(PKG_CONFIG) +endif # Miscellaneous tools GIT ?= $(X_GIT_TOOL) INSTALL ?= $(X_INSTALL_TOOL) # Patch flags and tools for (cross) build -FLAG_RELRO = -Wl,-z,relro,-z,now -FLAG_STDLIB = -CFLAGS_EXT = $(ARCHITECTURE_CFLAGS) -CXXFLAGS_EXT = $(ARCHITECTURE_CFLAGS) -EXE_FLAGS_EXT = $(ARCHITECTURE_CFLAGS) -SO_FLAGS_EXT = $(ARCHITECTURE_CFLAGS) -LDFLAGS_EXT = $(ARCHITECTURE_LDFLAGS) +FLAG_RELRO := -Wl,-z,relro,-z,now +FLAG_STDLIB := +NOARCH_CFLAGS := +NOARCH_CXXFLAGS := +NOARCH_EXE_FLAGS := +NOARCH_SO_FLAGS := +NOARCH_LDFLAGS := ifeq ($(PLATFORM),Solaris) FLAG_RELRO = @@ -76,55 +100,49 @@ ifeq ($(PLATFORM),Solaris) else ifeq ($(PLATFORM),Windows) FLAG_RELRO = FLAG_STDLIB = - CFLAGS_EXT += -DWINVER=0x600 -D_WIN32_WINNT=0x600 - CXXFLAGS_EXT += -DWINVER=0x600 -D_WIN32_WINNT=0x600 - EXE_FLAGS_EXT += -static-libgcc -static-libstdc++ - SO_FLAGS_EXT += -static-libgcc -static-libstdc++ - LDFLAGS_EXT += -T $(CURDIR)/make/ld-windows.script -else ifeq ($(PLATFORM),Haiku) - EXE_FLAGS_EXT += -L/system/lib -L/system/develop/lib - SO_FLAGS_EXT += -L/system/lib -L/system/develop/lib - CXXFLAGS_EXT += -D_GNU_SOURCE -D_BSD_SOURCE - CFLAGS_EXT += -D_GNU_SOURCE -D_BSD_SOURCE - LDFLAGS_EXT += -L/system/develop/lib/ + NOARCH_CFLAGS += -DWINVER=0x600 -D_WIN32_WINNT=0x600 + NOARCH_CXXFLAGS += -DWINVER=0x600 -D_WIN32_WINNT=0x600 + NOARCH_EXE_FLAGS += -static-libgcc -static-libstdc++ + NOARCH_SO_FLAGS += -static-libgcc -static-libstdc++ + NOARCH_LDFLAGS += -T $(CURDIR)/make/ld-windows.script else ifeq ($(PLATFORM),BSD) - EXE_FLAGS_EXT += -L/usr/local/lib - SO_FLAGS_EXT += -L/usr/local/lib + NOARCH_EXE_FLAGS += -L/usr/local/lib + NOARCH_SO_FLAGS += -L/usr/local/lib endif ifeq ($(DEBUG),1) - CFLAGS_EXT += -Og -g3 -DLSP_DEBUG -falign-functions=16 - CXXFLAGS_EXT += -Og -g3 -DLSP_DEBUG -falign-functions=16 + NOARCH_CFLAGS += -Og -g3 -DLSP_DEBUG -falign-functions=16 + NOARCH_CXXFLAGS += -Og -g3 -DLSP_DEBUG -falign-functions=16 else - CFLAGS_EXT += -O2 - CXXFLAGS_EXT += -O2 + NOARCH_CFLAGS += -O2 + NOARCH_CXXFLAGS += -O2 endif ifeq ($(ASAN),1) - CFLAGS_EXT += -fsanitize=address - CXXFLAGS_EXT += -fsanitize=address - EXE_FLAGS_EXT += -fsanitize=address - SO_FLAGS_EXT += -fsanitize=address + NOARCH_CFLAGS += -fsanitize=address + NOARCH_CXXFLAGS += -fsanitize=address + NOARCH_EXE_FLAGS += -fsanitize=address + NOARCH_SO_FLAGS += -fsanitize=address endif ifeq ($(PROFILE),1) - CFLAGS_EXT += -pg -DLSP_PROFILE - CXXFLAGS_EXT += -pg -DLSP_PROFILE + NOARCH_CFLAGS += -pg -DLSP_PROFILE + NOARCH_CXXFLAGS += -pg -DLSP_PROFILE endif ifeq ($(TRACE),1) - CFLAGS_EXT += -DLSP_TRACE - CXXFLAGS_EXT += -DLSP_TRACE + NOARCH_CFLAGS += -DLSP_TRACE + NOARCH_CXXFLAGS += -DLSP_TRACE endif ifeq ($(STRICT),1) - CFLAGS_EXT += -Werror - CXXFLAGS_EXT += -Werror + NOARCH_CFLAGS += -Werror + NOARCH_CXXFLAGS += -Werror endif ifeq ($(TEST),1) - CFLAGS_EXT += -DLSP_TESTING - CXXFLAGS_EXT += -DLSP_TESTING + NOARCH_CFLAGS += -DLSP_TESTING + NOARCH_CXXFLAGS += -DLSP_TESTING EXPORT_SYMBOLS ?= 1 else ifeq ($(ARTIFACT_EXPORT_SYMBOLS),1) @@ -135,8 +153,8 @@ else endif ifneq ($(EXPORT_SYMBOLS),1) - CFLAGS_EXT += -fvisibility=hidden - CXXFLAGS_EXT += -fvisibility=hidden + NOARCH_CFLAGS += -fvisibility=hidden + NOARCH_CXXFLAGS += -fvisibility=hidden endif ifneq ($(ARTIFACT_EXPORT_HEADERS),0) @@ -146,18 +164,18 @@ else endif # Define flags for (cross) build -CFLAGS += \ - $(CFLAGS_EXT) \ +NOARCH_CFLAGS += \ -fdata-sections \ -ffunction-sections \ -fno-asynchronous-unwind-tables \ -pipe \ -Wall +CFLAGS += $(ARCHITECTURE_CFLAGS) $(NOARCH_CFLAGS) +HOST_CFLAGS += $(HOST_ARCHITECTURE_CFLAGS) $(NOARCH_CFLAGS) CDEFS += -DLSP_INSTALL_PREFIX=\\\"$(PREFIX)\\\" -CXXFLAGS += \ - $(CXXFLAGS_EXT) \ +NOARCH_CXXFLAGS += \ -fno-exceptions \ -fno-rtti \ -fdata-sections \ @@ -165,22 +183,24 @@ CXXFLAGS += \ -fno-asynchronous-unwind-tables \ -pipe \ -Wall +CXXFLAGS += $(ARCHITECTURE_CFLAGS) $(NOARCH_CXXFLAGS) +HOST_CXXFLAGS += $(HOST_ARCHITECTURE_CFLAGS) $(NOARCH_CXXFLAGS) CXXDEFS += -DLSP_INSTALL_PREFIX=\\\"$(PREFIX)\\\" INCLUDE := -LDFLAGS := $(LDFLAGS_EXT) -r -EXE_FLAGS := $(EXE_FLAGS_EXT) $(FLAG_RELRO) -Wl,--gc-sections -SO_FLAGS := $(SO_FLAGS_EXT) $(FLAG_RELRO) -Wl,--gc-sections -shared $(FLAG_STDLIB) -fPIC - -# Define flags for host build -HOST_CFLAGS := $(CFLAGS) -HOST_CDEFS := $(CDEFS) -HOST_CXXFLAGS := $(CXXFLAGS) -HOST_CXXDEFS := $(CXXDEFS) -HOST_LDFLAGS := $(LDFLAGS) -HOST_EXE_FLAGS := $(EXE_FLAGS) -HOST_SO_FLAGS := $(SO_FLAGS) + +NOARCH_LDFLAGS += -r +LDFLAGS := $(ARCHITECTURE_LDFLAGS) $(NOARCH_LDFLAGS) +HOST_LDFLAGS := $(HOST_ARCHITECTURE_LDFLAGS) $(NOARCH_LDFLAGS) + +NOARCH_EXE_FLAGS += $(FLAG_RELRO) -Wl,--gc-sections +EXE_FLAGS := $(ARCHITECTURE_CFLAGS) $(NOARCH_EXE_FLAGS) +HOST_EXE_FLAGS := $(HOST_ARCHITECTURE_CFLAGS) $(NOARCH_EXE_FLAGS) + +NOARCH_SO_FLAGS += $(FLAG_RELRO) -Wl,--gc-sections -shared $(FLAG_STDLIB) -fPIC +SO_FLAGS := $(ARCHITECTURE_CFLAGS) $(NOARCH_SO_FLAGS) +HOST_SO_FLAGS := $(HOST_ARCHITECTURE_CFLAGS) $(NOARCH_SO_FLAGS) # The overall list of exported variables TOOL_VARS := \