|
| 1 | +include $(TOPDIR)/rules.mk |
| 2 | + |
| 3 | +PROFILE_NAME=$(notdir ${CURDIR}) |
| 4 | +PROFILE_COMMUNITY=$(lastword $(filter-out $(PROFILE_NAME),$(subst /, ,$(CURDIR)))) |
| 5 | +PKG_NAME:=profile-$(PROFILE_COMMUNITY)-$(PROFILE_NAME) |
| 6 | + |
| 7 | +# hack to deselect openwrt's default_packages. To be used by at most by one metapackage/network-profile |
| 8 | +define Package/$(PKG_NAME)/postinst |
| 9 | +#!/bin/sh |
| 10 | +[ -z "$${IPKG_INSTROOT}" ] && exit 0 |
| 11 | +echo "########################################################################## Inside package $(PKG_NAME) preinst" |
| 12 | +grep -q IB_MODIFIED_BY_$(PKG_NAME) $${TOPDIR}/Makefile && exit 0 |
| 13 | +echo "########################################################################## Backup original Makefile" |
| 14 | +cp $${TOPDIR}/Makefile $${TOPDIR}/Makefile.orig |
| 15 | +echo "########################################################################## Check default packages" |
| 16 | +cat << EOF > /tmp/hack_pkg_conflicts |
| 17 | +echo_build_packages: |
| 18 | + @echo BUILD_PACKAGES |
| 19 | +EOF |
| 20 | +cat /tmp/hack_pkg_conflicts >> $${TOPDIR}/Makefile |
| 21 | +sed -i 's|@echo BUILD_PACKAGES|@echo $\$$(BUILD_PACKAGES)|' $${TOPDIR}/Makefile |
| 22 | +build_packages=$$(make echo_build_packages) |
| 23 | +echo "Build packages: $${build_packages}" |
| 24 | +echo "########################################################################## Exit if no changes needed" |
| 25 | +need_run=0 |
| 26 | +for p in $(PKG_CONFLICTS); do |
| 27 | + i=$$(echo $$p | sed 's|-||') |
| 28 | + echo "Verifing the removal of package: $${i}" |
| 29 | + present=$$(echo $$build_packages | sed 's|\s|\n|g' | grep $$i | grep -v "\-$$i" ) |
| 30 | + removed=$$(echo $$build_packages | sed 's|\s|\n|g' | grep "\-$$i") |
| 31 | + if [ -n "$${removed}" ]; then |
| 32 | + echo "Removed continuing" |
| 33 | + continue; |
| 34 | + fi |
| 35 | + if [ -n "$${present}" ]; then |
| 36 | + echo "Present need_run" |
| 37 | + need_run=1 |
| 38 | + break |
| 39 | + fi |
| 40 | + echo 'Unset continuing' |
| 41 | +done |
| 42 | +if [ $${need_run} = 0 ]; then |
| 43 | + echo "Continue build without hack" |
| 44 | + cp $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile |
| 45 | + exit 0 |
| 46 | +fi |
| 47 | +echo "########################################################################## Determine make's target" |
| 48 | +R=$$(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) |
| 49 | +make_target=$$(echo "$${R}" | grep -q makemanifest && echo 'manifest' || echo 'image') |
| 50 | +echo "make_target: $${make_target}" |
| 51 | +echo "########################################################################## Add PKG_CONFLICTS to be removed in the main Makefile" |
| 52 | +sed -i 's|\($$(USER_PACKAGES)\) \($$(BUILD_PACKAGES)\)|\1 $(PKG_CONFLICTS) \2|' $${TOPDIR}/Makefile |
| 53 | +echo "########################################################################## Prevent unnecessary opkg/apk update in the main Makefile" |
| 54 | +sed -i '/update/d' $${TOPDIR}/Makefile |
| 55 | +echo "########################################################################## Terminate the execution after the second make image/manifest" |
| 56 | +cat << EOF > /tmp/hack_pkg_conflicts |
| 57 | +fail_target: |
| 58 | + cp $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile |
| 59 | + rm /tmp/hack_pkg_conflicts $${TOPDIR}/Makefile.orig |
| 60 | + kill $$(ls -l /proc/*/exe | grep make | sed 's|.*/proc/\(.*\)/exe.*|\1|' | tr '\n' ' ' ) |
| 61 | +# IB_MODIFIED_BY_$(PKG_NAME) |
| 62 | +EOF |
| 63 | +cat /tmp/hack_pkg_conflicts >> $${TOPDIR}/Makefile |
| 64 | +echo "########################################################################## Re-run make $${make_target} with the untouched MAKEFLAGS" |
| 65 | +if [ "$${make_target}" = "manifest" ]; then |
| 66 | + echo "########################################################################## make manifest: use the BIN_DIR of asu if available" |
| 67 | + manifest_dir=$$(find $${TOPDIR} -maxdepth 1 -type d -regex '.*[a-z].*[0-9].*' | grep . || echo $${TOPDIR}/bin/targets/$${TARGET} ) |
| 68 | + mkdir -p "$${manifest_dir}" |
| 69 | + sed -i "s|\(--manifest --no-network\)|\1 > $${manifest_dir}/manifest|" $${TOPDIR}/Makefile |
| 70 | + sed -i "s|\(--strip-abi)\)|\1 > $${manifest_dir}/manifest|" $${TOPDIR}/Makefile |
| 71 | +fi |
| 72 | +make "$${make_target}" |
| 73 | +make fail_target |
| 74 | +endef |
0 commit comments