Skip to content

Commit

Permalink
Makefiles cleanup (#3410)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Jan 23, 2025
1 parent c1a0657 commit 14ab117
Show file tree
Hide file tree
Showing 71 changed files with 314 additions and 359 deletions.
35 changes: 25 additions & 10 deletions config/Make.project.rules
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
# Copyright (c) ZeroC, Inc.

# $(call project,[$1=<project path>])
#
# $(call project,[$1])
#
# Returns the project name, $(top_srcdir) is removed from the begining
# of the path so for example ./src/Ice is transformed to src/Ice.
# Returns the project name by removing the lang-specific directory prefix.
# For example, ./src/Ice becomes src/Ice, and ./test/Ice/ami becomes test/Ice/ami.
#
# $1 is the project path. If $1 is not provided, the current directory is used.
project = $(patsubst $(lang_srcdir)/%,%,$(if $1,$1,$(currentdir)))

#
# The platforms, configs and languages to build.
#
platforms = $(filter-out $(SKIP),$(if $(filter all,$(PLATFORMS)),$(supported-platforms),$(filter $(supported-platforms),$(PLATFORMS))))
configs = $(filter-out $(SKIP),$(if $(filter all,$(CONFIGS)),$(supported-configs),$(filter $(supported-configs),$(CONFIGS))))
languages = $(filter-out $(SKIP),$(if $(filter all,$(or $(LANGUAGES),all)),$(supported-languages),$(filter $(supported-languages),$(LANGUAGES))))
build-platform := $(or $(build-platform),$(firstword $(supported-platforms)))

# Define the platforms to build, excluding those listed in SKIP.
# If PLATFORMS is set to 'all', include all supported platforms from supported-platforms.
# Otherwise, include only the platforms in PLATFORMS that are also in supported-platforms.
platforms = $(filter-out $(SKIP),\
$(if $(filter all,$(PLATFORMS)),$(supported-platforms),$(filter $(supported-platforms),$(PLATFORMS))))

# Define the configurations to build, excluding those listed in SKIP.
# If CONFIGS is set to 'all', include all supported configurations from supported-configs.
# Otherwise, include only the configurations in CONFIGS that are also in supported-configs.
configs = $(filter-out $(SKIP), \
$(if $(filter all,$(CONFIGS)),$(supported-configs),$(filter $(supported-configs),$(CONFIGS))))

# Define the languages to build, excluding those listed in SKIP.
# If LANGUAGES is set to 'all', include all supported languages from supported-languages.
# Otherwise, include only the languages in LANGUAGES that are also in supported-languages.
languages = $(filter-out $(SKIP),\
$(if $(filter all,$(or $(LANGUAGES),all)),$(supported-languages),$(filter $(supported-languages),$(LANGUAGES))))

# The platform the build is running on, if not set default to the first supported platform.
build-platform := $(or $(build-platform),$(firstword $(supported-platforms)))

#
# The list of platforms to build for the given component. We iterate over the platform
Expand Down
5 changes: 1 addition & 4 deletions config/Make.rules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Copyright (c) ZeroC, Inc.

#
# Select an installation base directory. The directory will be created
# if it does not exist.
#
# Select an installation base directory. The directory will be created if it does not exist.
prefix ?= /opt/Ice-$(version)

#
Expand Down
13 changes: 3 additions & 10 deletions config/Make.rules.Darwin
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ mcpp_ldflags := $(MCPP_HOME)/lib/libmcpp.a
cppflags = -fvisibility=hidden -Wall -Wextra -Wshadow -Wshadow-all -Wredundant-decls -Wno-shadow-field \
-Wdeprecated -Wstrict-prototypes -Werror -Wconversion -Wdocumentation -Wno-shadow-uncaptured-local \
-Wreorder-init-list -pthread \
$(if $(filter yes,$(OPTIMIZE)),-O2 -DNDEBUG,-g)
$(if $(filter yes,$(OPTIMIZE)),-O2 -DNDEBUG,-g) \
-std=c++20

# TODO review this setting
ifeq ($(MAXWARN),yes)
cppflags += -Wweak-vtables
endif
Expand All @@ -55,15 +57,6 @@ endif
static_objdir = obj
shared_objdir = obj

clang_version = $(shell clang -dumpversion 2>&1 | cut -f1 -d\.)

# We use -std=c++20 with clang 15.0 and later.
ifeq ($(shell test $(clang_version) -ge 15 && echo yes),yes)
cppflags += -std=c++20
else
cppflags += -std=c++17
endif

nodeprecatedwarnings-cppflags := -Wno-deprecated-declarations
nounusedparameter-cppflags := -Wno-unused-parameter

Expand Down
74 changes: 18 additions & 56 deletions config/Make.rules.Linux
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
# Copyright (c) ZeroC, Inc.

known_distributions := centos rhel fedora debian ubuntu amzn sles
linux_ids := $(if $(wildcard /etc/os-release),$(shell . /etc/os-release && echo $${ID} $${ID_LIKE}),)
linux_id ?= $(word 1,$(or $(filter $(known_distributions),$(linux_ids)),$(linux_ids)))
is-bin-program = $(and $(filter $(bindir)%,$($4_targetdir)),$(filter $($1_target),program))

ifneq ($(OECORE_SDK_VERSION),)
linux_id = yocto
endif

ifneq ($(filter yocto poky,$(linux_id)),)
known_distributions := centos rhel fedora debian ubuntu

build-platform = default
supported-platforms = $(build-platform)
# Assign the linux_ids from the ID and ID_LIKE variables in /etc/os-release if available.
linux_ids := $(if $(wildcard /etc/os-release),$(shell . /etc/os-release && echo $${ID} $${ID_LIKE}),)

$(build-platform)_cc = $(CC)
$(build-platform)_cxx = $(CXX)
$(build-platform)_cppflags = -Wno-psabi
$(build-platform)_libtool = $(AR)
$(build-platform)_targetdir = $(if $(filter %/build,$5),/$(build-platform))
$(build-platform)_installdir =
$(build-platform)_objdir =
# Assign the linux_id to the first known distribution in the linux_ids list, or for unknown distributions to the first
# element in the linux_ids list.
linux_id ?= $(firstword $(or $(filter $(known_distributions),$(linux_ids)),$(linux_ids)))

# system install directory
system-install-dir := $(OECORE_TARGET_SYSROOT)/usr
is-bin-program = $(and $(filter $(bindir)%,$($4_targetdir)),$(filter $($1_target),program))

else ifneq ($(and $(filter centos rhel fedora,$(linux_id)),$(filter x86_64 i%86,$(shell uname -m))),)
ifneq ($(and $(filter centos rhel fedora,$(linux_id)),$(filter x86_64 i%86,$(shell uname -m))),)

#
# MultiLib Linux (x64 libraries go in the lib64 directory, x86 executable names are suffixed with 32)
Expand Down Expand Up @@ -64,10 +50,8 @@ x86_excludes = slice2%

else ifneq ($(filter debian ubuntu,$(linux_id)),)

#
# MultiArch Linux (libraries are installed in lib/<arch>, executables are installed in bin/<arch>
# except for the build architecture where executables are installed in bin/).
#
# MultiArch Linux (libraries are installed in lib/<arch>, executables are installed in bin/<arch> except for the build
# architecture where executables are installed in bin/).
build-platform ?= $(shell dpkg --print-architecture)
foreign-platforms ?= $(shell dpkg --print-foreign-architectures)

Expand Down Expand Up @@ -113,12 +97,8 @@ else
#
ifeq ($(OPTIMIZE),yes)
# Use default system packaging flags if building with OPTIMIZE and CXXFLAGS/LDFLAGS aren't defined.
ifneq ($(filter amzn sles,$(linux_id)),)
opt-cppflags = $(if $(CXXFLAGS),,$(shell setarch $1 rpm --eval %optflags))
opt-ldflags = $(if $(LDFLAGS),,$(shell setarch $1 rpm --eval %?__global_ldflags))
else
opt-cppflags = $(if $(CXXFLAGS),,-O2)
endif
opt-cppflags = $(if $(CXXFLAGS),,$(shell setarch $1 rpm --eval %optflags))
opt-ldflags = $(if $(LDFLAGS),,$(shell setarch $1 rpm --eval %?__global_ldflags))
endif

build-platform = $(if $(filter arm%,$(shell uname -m)),arm,$(shell uname -m))
Expand All @@ -136,7 +116,7 @@ rpath-link-ldflag = -Wl,-rpath-link,$1
make-rpath-link-ldflags = $(foreach d,$(filter-out $2,$(call get-all-deps,$1)),$(call rpath-link-ldflag,$($d_targetdir)))

# If building objects for a shared library build, add -fPIC or -fPIE.
# gcc in most Linux distribution is configued with --enable-default-pie, which is equivalent to auto-adding -fPIE -pie:
# gcc in most Linux distribution is configured with --enable-default-pie, which is equivalent to auto-adding -fPIE -pie:
# https://gcc.gnu.org/install/configure.html
# We pass these options explicitly in case the gcc we use is not configured with --enable-default-pie.
shared_cppflags = $(if $(filter-out program,$($1_target)),-fPIC,-fPIE)
Expand All @@ -160,8 +140,6 @@ cppflags = -fvisibility=hidden -Wall -Wextra -Wredundant-decls -Wshadow -
$(if $(filter yes,$(OPTIMIZE)),-DNDEBUG,-g)
ldflags = -pthread

gcc_version = $(shell $(CXX) -dumpversion 2>&1 | cut -f1 -d\.)

# As of GCC 13.4, https://gcc.gnu.org/projects/cxx-status.html#cxx20 still describes C++20 support as "experimental".
cppflags += -std=c++17

Expand All @@ -186,35 +164,19 @@ mkshlibname = lib$(1).so
# Clear the iconv ldflags, iconv is part of libc on Linux
iconv_ldflags :=

#
# With GCC < 6.1, libbacktrace crash with a SEGV for -pie exes linked with debug-stripped libs
# See https://gcc.gnu.org/ml/gcc-patches/2016-03/msg00132.html
# Here we assume only release builds occasionally get -g and later get stripped
# TODO: enable libbacktrace for release builds with GCC >= 6.1
ifneq ($(OPTIMIZE),yes)
libbacktrace_fullpath := $(shell $(CXX) --print-file-name=libbacktrace.a)
ifneq ($(libbacktrace_fullpath),libbacktrace.a)
libbacktrace = yes
endif
endif

IceUtil_system_libs = -lrt $(if $(filter yes,$(libbacktrace)),-lbacktrace)
IceUtil_system_libs = -lrt -lbacktrace
Ice_system_libs = -ldl -lssl -lcrypto $(IceUtil_system_libs)
ifeq ($(shell pkg-config --exists libsystemd 2> /dev/null && echo yes),yes)
Ice_system_libs += $(shell pkg-config --libs libsystemd)
endif

Glacier2CryptPermissionsVerifier_system_libs = -lcrypt

icegridadmin_system_libs = -ledit
icestormadmin_system_libs = -ledit

#
# On supported platforms and if Bluez and DBus are installed, we set the IceBT
# system libraries. The build system checks for this variable to build or not
# the IceBT plugin, demos, ...
#
ifneq ($(filter debian ubuntu yocto poky,$(linux_id)),)
# If BlueZ and DBus are installed, set the IceBT system libraries.
# The build system uses this variable to determine whether or not to build the IceBT targets.
ifeq ($(shell pkg-config --exists bluez dbus-1 2> /dev/null && echo yes),yes)
IceBT_system_libs = $(shell pkg-config --libs dbus-1)
endif
IceBT_system_libs = $(shell pkg-config --libs dbus-1)
endif
9 changes: 1 addition & 8 deletions config/Make.tests.rules
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Copyright (c) ZeroC, Inc.

#
# $(call test,[$1])
#
# Returns the test project name (./test/Ice/operations -> test/Ice/operations)
#
test = $(patsubst $(lang_srcdir)/%,%,$(if $1,$1,$(currentdir)))

#
# $(call test-sources,$1=sources,$2=dir,$3=main-src extra-srcs)
#
Expand Down Expand Up @@ -83,7 +76,7 @@ endef
# Returns the tests which don't have a Makefile.mk fragment specified
#
tests-without-project-makefile = $(foreach d,$(patsubst %/Client.$1,%,$(shell find $(lang_srcdir)/test -name Client.$1)),\
$(if $(wildcard $d/Makefile.mk),,$(call test,$d)))
$(if $(wildcard $d/Makefile.mk),,$(call project,$d)))

#
# The tests variable is used to load tests in Makefile.mk fragments
Expand Down
12 changes: 6 additions & 6 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ include $(lang_srcdir)/config/Make.rules
# that other projects might depend on so it's important to parse them first for the
# generated headers variable to be defined when we load other projects.
#
load_first = Ice IceBox Glacier2Lib IceGridLib IceStormLib
load_first = Ice IceBox Glacier2Lib IceGridLib IceStormLib DataStorm

#
# Create projects for all the Slice translators from src/slice2* and load source projects.
#
projects :=
$(foreach t,$(wildcard $(lang_srcdir)/src/slice2*),$(eval $(call create-translator-project,$(call project,$t))))
$(eval $(call create-translator-project,$(call project,$(lang_srcdir)/src/ice2slice)))

# Create projects for all the Slice translators from src/slice2* and src/ice2slice.
slice_translators := $(wildcard $(lang_srcdir)/src/slice2*) $(lang_srcdir)/src/ice2slice
$(foreach t, $(slice_translators), $(eval $(call create-translator-project,$(call project,$t))))

include $(foreach p,$(load_first),src/$p/Makefile.mk)
include $(filter-out $(foreach p,$(load_first),%/src/$p/Makefile.mk),$(shell find $(lang_srcdir)/src -name Makefile.mk))
$(call make-projects,$(projects),make-cpp-src-project,,$(filter all cpp,$(ICE_BIN_DIST)))
Expand Down
7 changes: 1 addition & 6 deletions cpp/config/Make.rules
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Copyright (c) ZeroC, Inc.

# ----------------------------------------------------------------------
# Don't change anything below this line!
# ----------------------------------------------------------------------

#
# Supported configurations
#
Expand Down Expand Up @@ -58,8 +54,7 @@ static_projects = test/Common \
static_excludes = test/Ice/library test/Ice/plugin

#
# If building on a Linux multilib platform, we restrict what we build for
# the 32-bits architecture.
# If building on a Linux multilib platform, we restrict what we build for the 32-bits architecture.
#
ifeq ($(multilib-platform),yes)
x86_components = $(coreandstub_components) IceDB IceStormService icebox
Expand Down
8 changes: 4 additions & 4 deletions cpp/test/DataStorm/api/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) ZeroC, Inc.

$(test)_programs = writer
$(test)_dependencies = DataStorm Ice TestCommon
$(project)_programs = writer
$(project)_dependencies = DataStorm Ice TestCommon

$(test)_writer_sources = Writer.cpp DuplicateSymbols.cpp Test.ice
$(project)_writer_sources = Writer.cpp DuplicateSymbols.cpp Test.ice

tests += $(test)
tests += $(project)
10 changes: 5 additions & 5 deletions cpp/test/DataStorm/callbacks/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) ZeroC, Inc.

$(test)_programs = reader writer
$(test)_dependencies = DataStorm Ice TestCommon
$(project)_programs = reader writer
$(project)_dependencies = DataStorm Ice TestCommon

$(test)_reader_sources = Reader.cpp
$(test)_writer_sources = Writer.cpp
$(project)_reader_sources = Reader.cpp
$(project)_writer_sources = Writer.cpp

tests += $(test)
tests += $(project)
10 changes: 5 additions & 5 deletions cpp/test/DataStorm/config/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) ZeroC, Inc.

$(test)_programs = reader writer
$(test)_dependencies = DataStorm Ice TestCommon
$(project)_programs = reader writer
$(project)_dependencies = DataStorm Ice TestCommon

$(test)_reader_sources = Reader.cpp
$(test)_writer_sources = Writer.cpp
$(project)_reader_sources = Reader.cpp
$(project)_writer_sources = Writer.cpp

tests += $(test)
tests += $(project)
10 changes: 5 additions & 5 deletions cpp/test/DataStorm/events/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) ZeroC, Inc.

$(test)_programs = reader writer
$(test)_dependencies = DataStorm Ice TestCommon
$(project)_programs = reader writer
$(project)_dependencies = DataStorm Ice TestCommon

$(test)_reader_sources = Reader.cpp Test.ice
$(test)_writer_sources = Writer.cpp Test.ice
$(project)_reader_sources = Reader.cpp Test.ice
$(project)_writer_sources = Writer.cpp Test.ice

tests += $(test)
tests += $(project)
10 changes: 5 additions & 5 deletions cpp/test/DataStorm/partial/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) ZeroC, Inc.

$(test)_programs = reader writer
$(test)_dependencies = DataStorm Ice TestCommon
$(project)_programs = reader writer
$(project)_dependencies = DataStorm Ice TestCommon

$(test)_reader_sources = Reader.cpp Test.ice
$(test)_writer_sources = Writer.cpp Test.ice
$(project)_reader_sources = Reader.cpp Test.ice
$(project)_writer_sources = Writer.cpp Test.ice

tests += $(test)
tests += $(project)
10 changes: 5 additions & 5 deletions cpp/test/DataStorm/reliability/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) ZeroC, Inc.

$(test)_programs = reader writer
$(test)_dependencies = DataStorm Ice TestCommon
$(project)_programs = reader writer
$(project)_dependencies = DataStorm Ice TestCommon

$(test)_reader_sources = Reader.cpp
$(test)_writer_sources = Writer.cpp
$(project)_reader_sources = Reader.cpp
$(project)_writer_sources = Writer.cpp

tests += $(test)
tests += $(project)
10 changes: 5 additions & 5 deletions cpp/test/DataStorm/types/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) ZeroC, Inc.

$(test)_programs = reader writer
$(test)_dependencies = DataStorm Ice TestCommon
$(project)_programs = reader writer
$(project)_dependencies = DataStorm Ice TestCommon

$(test)_reader_sources = Reader.cpp Test.ice
$(test)_writer_sources = Writer.cpp Test.ice
$(project)_reader_sources = Reader.cpp Test.ice
$(project)_writer_sources = Writer.cpp Test.ice

tests += $(test)
tests += $(project)
8 changes: 4 additions & 4 deletions cpp/test/Glacier2/attack/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) ZeroC, Inc.

$(test)_client_sources = Client.cpp BackendI.cpp Backend.ice
$(test)_client_dependencies = Glacier2
$(project)_client_sources = Client.cpp BackendI.cpp Backend.ice
$(project)_client_dependencies = Glacier2

$(test)_server_sources = Server.cpp BackendI.cpp Backend.ice
$(project)_server_sources = Server.cpp BackendI.cpp Backend.ice

tests += $(test)
tests += $(project)
Loading

0 comments on commit 14ab117

Please sign in to comment.