summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2019-08-09 16:00:18 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-09-02 16:06:19 +0200
commit128669b5a1a4633afe2074c5d7f29f41229db306 (patch)
tree86269826f323390adc655badb17935bbbc720262
parentc817f860127b7795eb53602b6e2b85da3fa2913d (diff)
downloadOSELAS.Toolchain-128669b5a1a4633afe2074c5d7f29f41229db306.tar.gz
cleanup: handle cleanup during install
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--rules/post/cleanup.make30
-rw-r--r--scripts/lib/ptxd_make_toolchain.sh21
-rw-r--r--scripts/lib/ptxd_make_world_install.sh79
3 files changed, 100 insertions, 30 deletions
diff --git a/rules/post/cleanup.make b/rules/post/cleanup.make
index d1beff3..6978311 100644
--- a/rules/post/cleanup.make
+++ b/rules/post/cleanup.make
@@ -7,12 +7,6 @@ TOOLCHAIN_CLEANUP_HOST_DIRS := \
$(STATEDIR)/world.cleanup: $(STATEDIR)/world.targetinstall
@$(call targetinfo)
- @find "$(PTXCONF_SYSROOT_CROSS)/"* -depth -type d -print0 | \
- xargs -r -0 -- rmdir -v --ignore-fail-on-non-empty --
-# # remove all static host libraries
- find $(TOOLCHAIN_CLEANUP_HOST_DIRS) \
- -wholename "$(PTXCONF_SYSROOT_CROSS)/lib/gcc" -prune -o \
- -type f -name "*.a" -print0 | xargs -0 -r rm
ifndef PTXDIST_TOOLCHCAIN_KEEP_DEBUG
# # strip all host binaries
find $(TOOLCHAIN_CLEANUP_HOST_DIRS) \
@@ -20,30 +14,6 @@ ifndef PTXDIST_TOOLCHCAIN_KEEP_DEBUG
-type f \( -executable -o -name "*.so*" \) -print0 \
| xargs -0 -n1 --verbose strip --preserve-dates || true
endif
-# # make sure there are no bogus rpaths
- find "$(PTXCONF_SYSROOT_CROSS)/$(call remove_quotes,$(PTXCONF_GNU_TARGET))" \
- -type f \( -executable -o -name "*.so*" \) -print0 \
- | xargs -0 chrpath -k -d 2>/dev/null || true
-ifdef PTXCONF_TOOLCHAIN_CONFIG_SYSROOT
-# # size compromise: compressed debug sections in static libraries are too large
- find "$(PTXCONF_SYSROOT_TARGET)/usr/lib" \
- -type f -name "*.a" -print0 \
- | xargs -0 -n1 $(PTXCONF_SYSROOT_CROSS)/bin/$(PTXCONF_GNU_TARGET)-objcopy \
- --preserve-dates --strip-debug --keep-file-symbols || true
-endif
-# # compress debug sections and remove any absolute paths
- find "$(PTXCONF_SYSROOT_CROSS)" "$(PTXCONF_SYSROOT_CROSS)/lib/gcc" \
- $(patsubst %,-wholename % -prune -o,$(TOOLCHAIN_CLEANUP_HOST_DIRS)) \
- -type f \( -executable -o -name "*.so*" -o -name "*.a" -o -name "*.o" \) -print0 \
- | xargs -0 -n1 $(PTXCONF_SYSROOT_CROSS)/bin/$(PTXCONF_GNU_TARGET)-objcopy \
- --wildcard \
- --strip-symbol=$(GLIBC_BUILDDIR)/*.o \
- --strip-symbol=$(GLIBC_BUILDDIR)/*.os \
- --strip-symbol=$(PTXCONF_SYSROOT_TARGET)/usr/lib/*.o \
- --preserve-dates --compress-debug-sections 2>/dev/null || true
- find "$(PTXCONF_SYSROOT_TARGET)" \
- -name "*.cmd" -print0 | xargs -0 -r rm
-
@$(call touch)
world: $(STATEDIR)/world.cleanup
diff --git a/scripts/lib/ptxd_make_toolchain.sh b/scripts/lib/ptxd_make_toolchain.sh
new file mode 100644
index 0000000..3ffa560
--- /dev/null
+++ b/scripts/lib/ptxd_make_toolchain.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# Copyright (C) 2019 by Michael Olbrich <m.olbrich@pengutronix.de>
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+ptxd_make_toolchain_cleanup() {
+ local sysroot_cross="$(ptxd_get_ptxconf PTXCONF_SYSROOT_CROSS)"
+ local sysroot_target="$(ptxd_get_ptxconf PTXCONF_SYSROOT_TARGET)"
+
+ # packages install to pkgdir anyways and this avoid empty directories
+ # in the final toolchain
+ rmdir --ignore-fail-on-non-empty \
+ {"${sysroot_cross}","${sysroot_target}"{,/usr}}/{etc,lib,{,s}bin,include,{,share/}man/{man*,},share}
+ # errors may occur when multiple toolchains are built at the same time
+ true
+}
+
+ptxd_make_toolchain_cleanup
diff --git a/scripts/lib/ptxd_make_world_install.sh b/scripts/lib/ptxd_make_world_install.sh
index 0e02c5d..28a9e72 100644
--- a/scripts/lib/ptxd_make_world_install.sh
+++ b/scripts/lib/ptxd_make_world_install.sh
@@ -21,6 +21,11 @@ ptxd_make_world_install_pack() {
return
fi &&
+ # created during install but not needed here
+ if [ "${pkg_type}" = "cross" ]; then
+ rm "${pkg_pkg_dir}/lib64"
+ fi &&
+
# remove empty dirs
test \! -e "${pkg_pkg_dir}" || \
find "${pkg_pkg_dir}" -depth -type d -print0 | xargs -r -0 -- \
@@ -37,5 +42,79 @@ ptxd_make_world_install_pack() {
# remove la files. They are not needed
find "${pkg_pkg_dir}" \( -type f -o -type l \) -name "*.la" -print0 | xargs -r -0 rm &&
check_pipe_status
+
+ # ensure PATH is set correctly to find cross tools if necessary
+ eval "${pkg_path}"
+
+ local ptxconf_gnu_target="$(ptxd_get_ptxconf PTXCONF_GNU_TARGET)"
+ local ptxconf_prefix="$(ptxd_get_ptxconf PTXCONF_PREFIX_CROSS)"
+ if [ "${pkg_type}" = "cross" ]; then
+ local -a host_dirs
+ for dir in \
+ "${pkg_pkg_dir}${ptxconf_prefix}/lib" \
+ "${pkg_pkg_dir}${ptxconf_prefix}/libexec" \
+ "${pkg_pkg_dir}${ptxconf_prefix}/bin" \
+ "${pkg_pkg_dir}${ptxconf_prefix}/${ptxconf_gnu_target}/bin"; do
+ if [ -d "${dir}" ]; then
+ host_dirs[${#host_dirs[*]}]="${dir}"
+ fi
+ done
+ if [ ${#host_dirs[*]} -eq 0 ]; then
+ ptxd_bailout "cross package '${pkg_pkg}' not properly installed"
+ fi
+ # remove all static host libraries
+ find "${host_dirs[@]}" \
+ -wholename "${pkg_pkg_dir}${ptxconf_prefix}/lib/gcc" -prune -o \
+ -type f -name "*.a" -print0 | xargs -0 -r rm -v
+ fi
+ local -a strip_dirs
+ case "${pkg_type}" in
+ target)
+ strip_dirs=( "${pkg_pkg_dir}" )
+ ;;
+ cross)
+ if [ -d "${pkg_pkg_dir}${ptxconf_prefix}/lib/gcc" ]; then
+ strip_dirs[${#strip_dirs[*]}]="${pkg_pkg_dir}${ptxconf_prefix}/lib/gcc"
+ fi
+ if [ -d "${pkg_pkg_dir}${ptxconf_prefix}/${ptxconf_gnu_target}/lib" ]; then
+ strip_dirs[${#strip_dirs[*]}]="${pkg_pkg_dir}${ptxconf_prefix}/${ptxconf_gnu_target}/lib"
+ fi
+ ;;
+ esac
+ if [ ${#strip_dirs[*]} -gt 0 ]; then
+ local objcopy="$(ptxd_get_ptxconf PTXCONF_COMPILER_PREFIX)objcopy"
+ find "${strip_dirs[@]}" \
+ -wholename "${pkg_pkg_dir}${ptxconf_prefix}/lib/gcc/${ptxconf_gnu_target}/*/plugin" -prune -o \
+ -name "*.py" -prune -o \
+ -type f ! -type l \
+ \( -executable -o -name "*.so*" -o -name "*.a" -o -name "*.o" \) -print \
+ | while read f; do
+ # ignore ld scripts
+ case "$(file -b "${f}")" in
+ *ASCII*|*script*) continue ;;
+ esac
+ # size compromise: compressed debug sections in static libraries are too large
+ if [[ "${pkg_type}" = "target" && "${f}" =~ \.a$ ]]; then
+ echo "Stripping $(ptxd_print_path "${f}") ..."
+ ${objcopy} \
+ --preserve-dates --strip-debug --keep-file-symbols \
+ "${f}"
+ else
+ # compress debug sections and remove any bogus paths
+ echo "Compressing $(ptxd_print_path "${f}") ..."
+ ${objcopy} \
+ --wildcard \
+ --strip-symbol=${pkg_pkg_dir}${ptxconf_prefix}/usr/lib/*.o \
+ --strip-symbol=${PTXDIST_SYSROOT_TARGET}/usr/lib/*.o \
+ --strip-symbol=${pkg_build_dir}/*.o \
+ --strip-symbol=${pkg_build_dir}/*.os \
+ --preserve-dates --compress-debug-sections \
+ "${f}" &&
+ if [[ "$(file "${f}")" =~ "dynamically linked" ]]; then
+ chrpath -d "${f}"
+ fi
+ fi || exit 1
+ done
+ fi
}
export -f ptxd_make_world_install_pack