Skip to content

Commit

Permalink
build: added libexpat build support
Browse files Browse the repository at this point in the history
This allows commands such as "info os files"
previously we had expat support on x86_64 only.
  • Loading branch information
guyush1 committed Jan 9, 2025
1 parent f7e97ca commit e8263f9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
path = src/submodule_packages/binutils-gdb
url = [email protected]:guyush1/binutils-gdb.git
branch = gdb-static
[submodule "src/submodule_packages/libexpat"]
path = src/submodule_packages/libexpat
url = [email protected]:guyush1/libexpat.git
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RUN apt update && apt install -y \
gcc-powerpc-linux-gnu \
git \
libncurses-dev \
libtool \
m4 \
make \
patch \
Expand Down
72 changes: 66 additions & 6 deletions src/compilation/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ function set_compliation_variables() {
export LDFLAGS="-s"
}

function set_ncurses_link_variables() {
# Set up ncurses library link variables
function set_up_lib_search_paths() {
# Set up library-related linker search paths.
#
# Parameters:
# $1: ncursesw build dir
# $2: libexpat build dir
local ncursesw_build_dir="$1"
local libexpat_build_dir="$2"

# Allow tui mode by adding our custom built static ncursesw library to the linker search path.
export LDFLAGS="-L$ncursesw_build_dir/lib $LDFLAGS"
# I) Allow tui mode by adding our custom built static ncursesw library to the linker search path.
# II) Allow parsing xml files by adding libexpat library to the linker search path.
export LDFLAGS="-L$ncursesw_build_dir/lib -L$libexpat_build_dir/lib/.libs $LDFLAGS"
}

function build_iconv() {
Expand Down Expand Up @@ -214,6 +217,56 @@ function build_ncurses() {
popd > /dev/null
}

function build_libexpat() {
# Build libexpat.
#
# Parameters:
# $1: libexpat package directory
# $2: target architecture
#
# Echoes:
# The libexpat build directory
#
# Returns:
# 0: success
# 1: failure
local libexpat_dir="$1"
local target_arch="$2"
local libexpat_build_dir="$(realpath "$libexpat_dir/build-$target_arch")"

echo "$libexpat_build_dir"
mkdir -p "$libexpat_build_dir"

if [[ -f "$libexpat_build_dir/lib/.libs/libexpat.a" ]]; then
>&2 echo "Skipping build: libexpat already built for $target_arch"
return 0
fi

pushd "$libexpat_build_dir" > /dev/null

>&2 fancy_title "Building libexpat for $target_arch"

# Generate configure if it doesnt exist.
if [[ ! -f "$libexpat_build_dir/../expat/configure" ]]; then
>&2 ../expat/buildconf.sh ../expat/
fi

../expat/configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
if [[ $? -ne 0 ]]; then
return 1
fi

make -j$(nproc) 1>&2
if [[ $? -ne 0 ]]; then
return 1
fi

>&2 fancy_title "Finished building libexpat for $target_arch"

popd > /dev/null
}

function build_python() {
# Build python.
#
Expand Down Expand Up @@ -373,10 +426,11 @@ function build_gdb() {

../configure -C --enable-static --with-static-standard-libraries --disable-inprocess-agent \
--enable-tui "$python_flag" \
--with-expat --with-libexpat-type="static" \
"--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
"--with-gmp=$libgmp_prefix" \
"--with-mpfr=$libmpfr_prefix" \
"CC=$CC" "CXX=$CXX" "--host=$HOST" \
"CC=$CC" "CXX=$CXX" "LDFLAGS=$LDFLAGS" "--host=$HOST" \
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
if [[ $? -ne 0 ]]; then
return 1
Expand Down Expand Up @@ -515,7 +569,13 @@ function build_gdb_with_dependencies() {
if [[ $? -ne 0 ]]; then
return 1
fi
set_ncurses_link_variables "$ncursesw_build_dir"

libexpat_build_dir="$(build_libexpat "$packages_dir/libexpat" "$target_arch")"
if [[ $? -ne 0 ]]; then
return 1
fi

set_up_lib_search_paths "$ncursesw_build_dir" "$libexpat_build_dir"

if [[ "$with_python" == "yes" ]]; then
build_python "$packages_dir/cpython-static" "$target_arch"
Expand Down
1 change: 1 addition & 0 deletions src/submodule_packages/libexpat
Submodule libexpat added at 2691af

0 comments on commit e8263f9

Please sign in to comment.