feat(cookbook): add the option to prefer static

By default all libraries and applications that can be dynamically linked
will be dynamically linked. You can override this behaviour by setting
the `COOKBOOK_PREFER_STATIC` environment variable. Note that if you
perviously did not use this flag, it might (most likely will) require a
complete userland sysroot recompilation.

It will look like this:
```bash
$ make clean
$ COOKBOOK_PREFER_STATIC=yes make image
```

For testing, the following will also work:
```bash
$ COOKBOOK_PREFER_STATIC=yes make cr.{PACKAGE_NAME} # obviously replace
                                                    # PACKAGE_NAME with
                                                    # the name of a package :)
```

Signed-off-by: Anhad Singh <andypython@protonmail.com>
This commit is contained in:
Anhad Singh 2025-01-20 19:12:15 +11:00
parent 48bed31e92
commit 3ee1f4da00
3 changed files with 35 additions and 10 deletions

View File

@ -37,6 +37,18 @@ COOKBOOK_CONFIGURE_FLAGS=(
--with-bugurl="https://gitlab.redox-os.org/redox-os/gcc/-/issues"
)
if [[ -n "$COOKBOOK_PREFER_STATIC" ]]; then
COOKBOOK_CONFIGURE_FLAGS+=(
--enable-static
--disable-shared
)
else
COOKBOOK_CONFIGURE_FLAGS+=(
--enable-shared
--disable-static
)
fi
"${COOKBOOK_CONFIGURE}" "${COOKBOOK_CONFIGURE_FLAGS[@]}"
"${COOKBOOK_MAKE}" -j "${COOKBOOK_MAKE_JOBS}" all-gcc
"${COOKBOOK_MAKE}" install-gcc DESTDIR="${COOKBOOK_STAGE}"

View File

@ -23,9 +23,18 @@ DYNAMIC_INIT
COOKBOOK_CONFIGURE_FLAGS=(
--host="${GNU_TARGET}"
--prefix=""
--enable-shared
--enable-static
ac_cv_have_decl_program_invocation_name=no
)
if [[ -n "$COOKBOOK_PREFER_STATIC" ]]; then
COOKBOOK_CONFIGURE_FLAGS+=(
--enable-static
--disable-shared
)
else
COOKBOOK_CONFIGURE_FLAGS+=(
--enable-shared
--enable-static
)
fi
cookbook_configure
"""

View File

@ -170,6 +170,18 @@ fn run_command_stdin(mut command: process::Command, stdin_data: &[u8]) -> Result
static SHARED_PRESCRIPT: &str = r#"
function DYNAMIC_INIT {
COOKBOOK_AUTORECONF="autoreconf"
autotools_recursive_regenerate() {
for f in $(find . -name configure.ac -o -name configure.in -type f | sort); do
echo "* autotools regen in '$(dirname $f)'..."
( cd "$(dirname "$f")" && "${COOKBOOK_AUTORECONF}" -fvi "$@" -I${COOKBOOK_HOST_SYSROOT}/share/aclocal )
done
}
if [[ -n "$COOKBOOK_PREFER_STATIC" ]]; then
return
fi
echo "WARN: Program is being compiled dynamically."
COOKBOOK_CONFIGURE_FLAGS=(
@ -182,14 +194,6 @@ function DYNAMIC_INIT {
# TODO: check paths for spaces
export LDFLAGS="-L${COOKBOOK_SYSROOT}/lib"
export RUSTFLAGS="-C target-feature=-crt-static"
COOKBOOK_AUTORECONF="autoreconf"
autotools_recursive_regenerate() {
for f in $(find . -name configure.ac -o -name configure.in -type f | sort); do
echo "* autotools regen in '$(dirname $f)'..."
( cd "$(dirname "$f")" && "${COOKBOOK_AUTORECONF}" -fvi "$@" -I${COOKBOOK_HOST_SYSROOT}/share/aclocal )
done
}
}
"#;