@@ -24,31 +24,69 @@ PROFILE_DEPENDS:=\
2424 +shared-state-nodes_and_links
2525
2626# hack to deselect openwrt's default_packages. To be used by at most by one metapackage/network-profile
27- # warn: here TOPDIR is calculated by SDK, so it works with dockerized SDK and IB that use the same /builder
2827define Package/$(PKG_NAME)/preinst
2928# !/bin/sh
3029[ -z "$${IPKG_INSTROOT}" ] && exit 0
3130echo "# ######################################################################### Inside package preinst"
32- grep -q IB_MODIFIED_BY_$(PKG_NAME ) $(TOPDIR ) /Makefile && exit 0
31+ grep -q IB_MODIFIED_BY_$(PKG_NAME ) $${TOPDIR}/Makefile && exit 0
32+ echo "# ######################################################################### Backup original Makefile"
33+ cp $${TOPDIR}/Makefile $${TOPDIR}/Makefile.orig
34+ echo "# ######################################################################### Check default packages"
35+ cat << EOF > /tmp/hack_pkg_conflicts_detect
36+ echo_build_packages:
37+ @echo BUILD_PACKAGES
38+ EOF
39+ cat /tmp/hack_pkg_conflicts_detect >> $${TOPDIR}/Makefile
40+ sed -i 's|@echo BUILD_PACKAGES|@echo $\$$(BUILD_PACKAGES ) |' $${TOPDIR}/Makefile
41+ build_packages=$$(make echo_build_packages )
42+ echo "Build packages: $${build_packages}"
43+ echo "# ######################################################################### Exit if no changes needed"
44+ need_run=0
45+ for p in $(PKG_CONFLICTS ) ; do
46+ i=$$(echo $$p | sed 's|-||' )
47+ echo "Verifing the removal of package: $${i}"
48+ present=$$(echo $$build_packages | sed 's|\s|\n|g' | grep $$i | grep -v "\-$$i" )
49+ removed=$$(echo $$build_packages | sed 's|\s|\n|g' | grep "\-$$i" )
50+ if [ -n "$${removed}" ]; then
51+ echo "Removed continuing"
52+ continue;
53+ fi
54+ if [ -n "$${present}" ]; then
55+ echo "Present need_run"
56+ need_run=1
57+ break
58+ fi
59+ echo 'Unset continuing'
60+ done
61+ if [ $${need_run} = 0 ]; then
62+ echo "Continue build without hack"
63+ cp $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile
64+ exit 0
65+ fi
3366echo "# ######################################################################### Determine make's target"
3467R=$$(for cmd in $$(ls -l /proc/*/exe | grep make | sed 's|.*/proc/\(.*\ ) /exe.*|\1|' | tr '\n' ' ' | tr -d '\0' ) ; do cat "/proc/$${cmd}/cmdline"; done)
3568make_target=$$(echo "$${R}" | grep -q manifest && echo 'manifest' || echo 'image' )
3669echo "make_target: $${make_target}"
37- echo "# ######################################################################### Backup original Makefile"
38- cp $( TOPDIR ) /Makefile $( TOPDIR ) /Makefile.orig
70+ echo "# ######################################################################### Add PKG_CONFLICTS to be removed in the main Makefile"
71+ sed -i 's|\( $$( USER_PACKAGES ) \) \( $$( BUILD_PACKAGES ) \)|\1 $( PKG_CONFLICTS ) \2|' $${TOPDIR} /Makefile
3972echo "# ######################################################################### Terminate the execution after the second make image/manifest"
4073cat << EOF > /tmp/hack_pkg_conflicts
41- cp $(TOPDIR ) /Makefile.orig $(TOPDIR ) /Makefile
74+ fail_target:
75+ cp $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile
4276 kill $$(ls -l /proc/*/exe | grep make | sed 's|.*/proc/\(.*\ ) /exe.*|\1|' | tr '\n' ' ' )
77+ # IB_MODIFIED_BY_$(PKG_NAME)
4378EOF
44- [ "$${make_target}" = "image" ] \
45- && sed -i '/^manifest:\ /e cat /tmp/hack_pkg_conflicts' $(TOPDIR ) /Makefile \
46- || sed -i '/^package_whatdepends:\ /e cat /tmp/hack_pkg_conflicts' $(TOPDIR ) /Makefile
47- echo "# ######################################################################### Add PKG_CONFLICTS to be removed in the main Makefile"
48- sed -i 's|\($$(USER_PACKAGES ) \) \($$(BUILD_PACKAGES ) \)|\1 $(PKG_CONFLICTS ) \2|' $(TOPDIR ) /Makefile
49- echo "# IB_MODIFIED_BY_$(PKG_NAME)" >> $(TOPDIR)/Makefile
79+ cat /tmp/hack_pkg_conflicts >> $${TOPDIR}/Makefile
5080echo "# ######################################################################### Re-run make image with the untouched MAKEFLAGS"
81+ if [ "$${make_target}" = "manifest" ]; then
82+ echo "# ######################################################################### make manifest: use the BIN_DIR of asu if available"
83+ manifest_dir=$$(find $${TOPDIR} -maxdepth 1 -type d -regex '.*[a-z].*[0-9].*' | grep . || echo $${TOPDIR}/bin/targets/$${TARGET} )
84+ mkdir -p "$${manifest_dir}"
85+ sed -i "s|\(--manifest --no-network\)|\1 > $${manifest_dir}/manifest|" $${TOPDIR}/Makefile
86+ sed -i "s|\(--strip-abi)\)|\1 > $${manifest_dir}/manifest|" $${TOPDIR}/Makefile
87+ fi
5188make "$${make_target}"
89+ make fail_target
5290endef
5391
5492include ../../profile.mk
0 commit comments