Skip to content

Commit b548df2

Browse files
Add ppc64le cross-compilation support and Makefile fixes for Ubuntu Focal Fossa (#11)
* ubuntu-build.sh: Set MAKE_ARGS earlier * ubuntu-build.sh: Move sysroot install later * resources/Makefile: New file Add a Makefile that can be used to cross-compile libdcsctp.a for architectures that "gn" does not support. * Add ppc64le cross-compilation support * ubuntu-build.sh: Add verbose support * ubuntu-build.sh: Add debug optimization level --------- Co-authored-by: Jonathan Lennox <jonathan.lennox@8x8.com>
1 parent 5b58e75 commit b548df2

File tree

5 files changed

+156
-17
lines changed

5 files changed

+156
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Prerequisites:
2525
- Maven
2626
- CMake
2727
- Git
28-
- APT packages `build-essentials`, `g++-aarch64-linux-gnu` and their dependencies
28+
- APT packages `build-essential`, `g++-aarch64-linux-gnu`, `g++-powerpc64le-linux-gnu` and their dependencies
2929

3030
* Clone the project
3131
* Update the SimpleJNI subproject with

cmake/ppc64el-linux-gnu.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set(CMAKE_SYSTEM_NAME "Linux")
2+
set(CMAKE_SYSTEM_PROCESSOR "ppc64le")
3+
4+
set(CMAKE_C_COMPILER /usr/bin/powerpc64le-linux-gnu-gcc)
5+
set(CMAKE_CXX_COMPILER /usr/bin/powerpc64le-linux-gnu-g++)

resources/Makefile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Minimal build steps that produce libdcsctp.a
2+
# Copyright (C) 2025
3+
# Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
4+
# Version: 1
5+
# SPDX-License-Identifier: Apache-2.0
6+
# "gn" has no support for ppc64le. This Makefile can be used in place of "gn"
7+
# and "ninja" to build libdcsctp.a on non-"gn" architectures. The Makefile was
8+
# written from scratch starting from the assumption that all non-test net/dcsctp
9+
# .cc files were needed by libdcsctp4j.so. Runtime testing of Jitsi confirms
10+
# that the resulting libdcsctp.a satisfies libdcsctp4j.so's needs on ppc64le.
11+
S := $(VPATH)
12+
DEBUG ?= -O2
13+
# Add GCC-compatible flags extracted from "ninja -v" output for x86-64 target.
14+
CXXFLAGS += -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1
15+
CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2
16+
CXXFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
17+
CXXFLAGS += -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE
18+
CXXFLAGS += -D_GLIBCXX_ASSERTIONS=1
19+
CXXFLAGS += -DNDEBUG -DNVALGRIND
20+
CXXFLAGS += -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DWEBRTC_ENABLE_PROTOBUF=1
21+
CXXFLAGS += -DWEBRTC_STRICT_FIELD_TRIALS=0
22+
CXXFLAGS += -DWEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE -DRTC_ENABLE_VP9
23+
CXXFLAGS += -DRTC_DAV1D_IN_INTERNAL_DECODER_FACTORY -DWEBRTC_HAVE_SCTP
24+
CXXFLAGS += -DWEBRTC_ENABLE_LIBEVENT -DWEBRTC_LIBRARY_IMPL -DWEBRTC_ENABLE_AVX2
25+
CXXFLAGS += -DWEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1 -DWEBRTC_POSIX
26+
CXXFLAGS += -DWEBRTC_LINUX -DABSL_ALLOCATOR_NOTHROW=1 -Wall -Wextra
27+
CXXFLAGS += -Wimplicit-fallthrough -Wextra-semi -Wno-missing-field-initializers
28+
CXXFLAGS += -Wno-unused-parameter -Wno-psabi -Wno-cast-function-type
29+
CXXFLAGS += -Wno-invalid-offsetof -Wshadow -Werror
30+
CXXFLAGS += -fno-delete-null-pointer-checks -fno-ident -fno-strict-aliasing
31+
CXXFLAGS += -fstack-protector -funwind-tables -fPIC -pthread
32+
CXXFLAGS += -fmerge-all-constants -ffp-contract=off -m64
33+
CXXFLAGS += -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__=
34+
CXXFLAGS += -D__TIMESTAMP__= -no-canonical-prefixes
35+
CXXFLAGS += $(DEBUG) -fdata-sections
36+
CXXFLAGS += -ffunction-sections -fno-math-errno -fno-omit-frame-pointer
37+
CXXFLAGS += -gdwarf-4 -g2 -ggnu-pubnames -fvisibility=hidden -Wno-shadow
38+
CXXFLAGS += -Wundef -std=c++17 -Wno-trigraphs
39+
CXXFLAGS += -fno-exceptions -fno-rtti
40+
CXXFLAGS += -fvisibility-inlines-hidden -Wnon-virtual-dtor -Woverloaded-virtual
41+
# Silence GCC 12 warnings.
42+
CXXFLAGS += -Wno-return-type -Wno-overloaded-virtual -Wno-comment -Wno-undef
43+
CXXFLAGS += -Wno-redundant-move
44+
# Add include paths to fix compilation errors due to missing headers.
45+
CXXFLAGS += -I$(S)
46+
CXXFLAGS += -I$(S)/third_party/abseil-cpp
47+
CXXFLAGS += -I$(S)/third_party/crc32c/config
48+
CXXFLAGS += -I$(S)/third_party/crc32c/src/include
49+
# Assume all non-test .cc files under net/dcsctp are needed by libdcsctp4j.so.
50+
# "gn/ninja" includes 37 extra objects but they are not needed by
51+
# libdcsctp4j.so.
52+
TESTS = $(shell find $(S)/net/dcsctp -name "*_test*.cc")
53+
SOURCES = $(shell find $(S)/net/dcsctp -name "*.cc")
54+
OBJECTS = $(patsubst %.cc,%.o,$(filter-out $(TESTS),$(SOURCES)))
55+
# Assume all source files are in subdirectories and subsubdirectories of
56+
# net/dcsctp.
57+
DIRS = $(shell find $(S) -maxdepth 5 -type d -print)
58+
# Add other objects required to fix libdcsctp4j.so errors; first compilation
59+
# errors, then undefined symbol errors reported at runtime by the dynamic
60+
# linker.
61+
OBJECTS += $(S)/api/units/time_delta.o
62+
OBJECTS += $(S)/rtc_base/checks.o
63+
OBJECTS += $(S)/rtc_base/logging.o
64+
OBJECTS += $(S)/rtc_base/platform_thread_types.o
65+
OBJECTS += $(S)/rtc_base/string_encode.o
66+
OBJECTS += $(S)/rtc_base/string_utils.o
67+
OBJECTS += $(S)/rtc_base/strings/string_builder.o
68+
OBJECTS += $(S)/rtc_base/strings/string_format.o
69+
OBJECTS += $(S)/rtc_base/system_time.o
70+
OBJECTS += $(S)/rtc_base/time_utils.o
71+
OBJECTS += $(S)/third_party/abseil-cpp/absl/base/internal/raw_logging.o
72+
OBJECTS += $(S)/third_party/abseil-cpp/absl/types/bad_variant_access.o
73+
OBJECTS += $(S)/third_party/crc32c/src/src/crc32c.o
74+
OBJECTS += $(S)/third_party/crc32c/src/src/crc32c_portable.o
75+
# Keep built object paths separate from source code paths.
76+
ifeq ($(strip $(OBJDIR)),)
77+
$(error "Set OBJDIR to absolute path in which to store output objects")
78+
endif
79+
OBJECTS := $(addprefix $(OBJDIR)/,$(OBJECTS))
80+
OBJDIRS := $(addprefix $(OBJDIR)/,$(DIRS))
81+
ifneq ($(strip $(VERBOSE)),1)
82+
SILENT := @
83+
endif
84+
$(OBJDIR)/%.o: %.cc
85+
@echo CXX $@
86+
$(SILENT)$(CXX) $(CXXFLAGS) -c $< -o $@
87+
$(OBJDIR)/libdcsctp.a: $(OBJECTS)
88+
@echo AR $@
89+
$(SILENT)$(AR) $(ARFLAGS) $@ $^
90+
$(OBJECTS): | $(OBJDIRS)
91+
$(OBJDIRS):
92+
@mkdir -p $@

resources/ubuntu-build-all.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
PROJECT_DIR="$(realpath "$(dirname "$0")/../")"
33
JAVA_VERSION=11
4-
ARCHS=(x86-64 arm64)
4+
ARCHS=(x86-64 arm64 ppc64le)
55

66
if [ "$#" -ne 2 ]; then
77
echo "Usage: $0 <DEPOT_TOOLS_DIR> <WEBRTC_DIR>"
@@ -39,5 +39,8 @@ mvn compile # Build SimpleJNI jnigen headers
3939
"$PROJECT_DIR/resources/checkout-webrtc.sh" "$DEPOT_TOOLS_DIR" "$WEBRTC_DIR" "$WEBRTC_REVISION"
4040

4141
for ARCH in "${ARCHS[@]}"; do
42-
"$PROJECT_DIR/resources/ubuntu-build.sh" "$JAVA_HOME" "$DEPOT_TOOLS_DIR" "$WEBRTC_DIR" "$ARCH"
42+
if test "$ARCH" = "ppc64le"; then
43+
MAKEFILE_ARGUMENT=BUILD_DCSCTP_WITH_MAKEFILE
44+
fi
45+
"$PROJECT_DIR/resources/ubuntu-build.sh" "$JAVA_HOME" "$DEPOT_TOOLS_DIR" "$WEBRTC_DIR" "$ARCH" "$MAKEFILE_ARGUMENT"
4346
done

resources/ubuntu-build.sh

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env bash
2-
if [ "$#" -ne 4 ]; then
3-
echo "Usage: $0 <JAVA_HOME> <DEPOT_TOOLS_DIR> <WEBRTC_DIR> <ARCH>"
2+
if [ "$#" -lt 4 -o "$#" -gt 7 ]; then
3+
echo "Usage: $0 <JAVA_HOME> <DEPOT_TOOLS_DIR> <WEBRTC_DIR> <ARCH> [USE_MAKEFILE] [VERBOSE] [DEBUG]"
44
echo " JAVA_HOME: Path to Java installation"
55
echo " DEPOT_TOOLS_DIR: Directory containing Google depot tools"
66
echo " WEBRTC_DIR: Directory containing WebRTC source"
7-
echo " ARCH: Architecture to build for (x86_64 or arm64)"
7+
echo " ARCH: Architecture to build for (x86_64, arm64, or ppc64le)"
8+
echo " USE_MAKEFILE: \"BUILD_DCSCTP_WITH_MAKEFILE\" => Use non-gn/ninja arch Makefile"
9+
echo " VERBOSE: \"true\" => Print compiler invocations"
10+
echo " DEBUG: \"true\" => Build every object with optimization level -O0"
811
exit 1
912
fi
1013

@@ -15,6 +18,9 @@ JAVA_HOME=$1
1518
DEPOT_TOOLS_DIR=$2
1619
WEBRTC_DIR=$3
1720
ARCH=$4
21+
USE_MAKEFILE=$5
22+
VERBOSE=$6
23+
DEBUG=$7
1824

1925
case $ARCH in
2026
"x86-64"|"x86_64"|"amd64"|"x64")
@@ -27,18 +33,46 @@ case $ARCH in
2733
DEBARCH=arm64
2834
GN_ARCH=arm64
2935
;;
36+
"ppc64le")
37+
JNAARCH=ppc64le
38+
DEBARCH=ppc64el
39+
GN_ARCH=ppc64le
40+
GNU_ARCH=powerpc64le
41+
;;
3042
*)
3143
echo "ERROR: Unsupported arch $ARCH"
3244
exit 1
3345
;;
3446
esac
3547

48+
if test "$VERBOSE" = "true"; then
49+
VERBOSE_NINJA=-v
50+
VERBOSE_MAKE=VERBOSE=1
51+
VERBOSE_CMAKE=VERBOSE=1
52+
fi
53+
54+
if test "$DEBUG" = "true"; then
55+
DEBUG_GN=true
56+
DEBUG_MAKE=DEBUG=-O0
57+
DEBUG_CMAKE=-DCMAKE_CXX_FLAGS=-O0
58+
DEBUG_CMAKE_BUILD_TYPE=Debug
59+
else
60+
DEBUG_GN=false
61+
DEBUG_CMAKE_BUILD_TYPE=RelWithDebInfo
62+
fi
63+
3664
NATIVEDEBARCH=$(dpkg --print-architecture)
3765

3866
if [ $DEBARCH != $NATIVEDEBARCH -a -f "cmake/$DEBARCH-linux-gnu.cmake" ]; then
3967
TOOLCHAIN_FILE="cmake/$DEBARCH-linux-gnu.cmake"
4068
fi
4169

70+
NCPU=$(nproc)
71+
if [ -n "$NCPU" -a "$NCPU" -gt 1 ]
72+
then
73+
MAKE_ARGS="-j $NCPU"
74+
fi
75+
4276
if test \! -d $WEBRTC_DIR/.git -a -r $WEBRTC_DIR/.gclient -a -d $WEBRTC_DIR/src/.git; then
4377
# They specified the WebRTC gclient directory, not the src checkout subdirectory
4478
WEBRTC_DIR=$WEBRTC_DIR/src
@@ -52,19 +86,23 @@ PATH=$PATH:$DEPOT_TOOLS_DIR
5286
startdir=$PWD
5387

5488
cd $WEBRTC_DIR
55-
./build/linux/sysroot_scripts/install-sysroot.py --arch=$GN_ARCH
5689
rm -rf $WEBRTC_BUILD
57-
gn gen $WEBRTC_BUILD --args="use_custom_libcxx=false target_cpu=\"$GN_ARCH\" is_debug=false symbol_level=2"
58-
ninja -C $WEBRTC_BUILD dcsctp
90+
if test "$USE_MAKEFILE" != "BUILD_DCSCTP_WITH_MAKEFILE"; then
91+
./build/linux/sysroot_scripts/install-sysroot.py --arch=$GN_ARCH
92+
gn gen $WEBRTC_BUILD --args="use_custom_libcxx=false target_cpu=\"$GN_ARCH\" is_debug=$DEBUG_GN symbol_level=2"
93+
ninja $VERBOSE_NINJA -C $WEBRTC_BUILD dcsctp
94+
else
95+
make $MAKE_ARGS -C $startdir/resources \
96+
VPATH="$WEBRTC_DIR" \
97+
OBJDIR="$WEBRTC_OBJ/obj" \
98+
$VERBOSE_MAKE \
99+
$DEBUG_MAKE \
100+
CXX=${GNU_ARCH}-linux-gnu-g++ \
101+
AR=${GNU_ARCH}-linux-gnu-ar
102+
fi
59103

60104
cd $startdir
61105

62-
NCPU=$(nproc)
63-
if [ -n "$NCPU" -a "$NCPU" -gt 1 ]
64-
then
65-
MAKE_ARGS="-j $NCPU"
66-
fi
67-
68106
if [ -n "$MAKE_ARGS" ]
69107
then
70108
CMAKE_BUILD_ARGS=" -- $MAKE_ARGS"
@@ -77,6 +115,7 @@ cmake -B cmake-build-linux-"$DEBARCH" \
77115
-DWEBRTC_DIR="$WEBRTC_DIR" \
78116
-DWEBRTC_OBJ="$WEBRTC_OBJ" \
79117
-DCMAKE_TOOLCHAIN_FILE:PATH="$TOOLCHAIN_FILE" \
80-
-DCMAKE_BUILD_TYPE=RelWithDebInfo
118+
$DEBUG_CMAKE \
119+
-DCMAKE_BUILD_TYPE=$DEBUG_CMAKE_BUILD_TYPE
81120

82-
cmake --build cmake-build-linux-"$DEBARCH" --target install $CMAKE_BUILD_ARGS
121+
cmake --build cmake-build-linux-"$DEBARCH" --target install $CMAKE_BUILD_ARGS $VERBOSE_CMAKE

0 commit comments

Comments
 (0)