Skip to content

Commit ca23361

Browse files
committed
hacking: move the preinst hack_pkg_conflicts to a separate makefile
1 parent d1dfbe4 commit ca23361

File tree

3 files changed

+99
-67
lines changed

3 files changed

+99
-67
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,27 @@ The expected files to be into this repository are:
1717

1818
A special file named `Makefile` have to be placed in the device directory `community/device/Makefile`, see [this file](https://github.com/libremesh/network-profiles/blob/master/libremesh/encrypt-11s/Makefile) as an example.
1919
This file can also be used to include a list of extra packages which will be included in the firmware.
20+
21+
## Hacking
22+
23+
### hack_pkg_conflicts (imagebuilder)
24+
Define a list of packages to be removed in PKG_CONFLICTS.
25+
Include then the `preinst` defined in `hack_pkg_conflicts.mk` to do the package removal, like in the example below:
26+
Warn: To use it with asu, the server must support this hack.
27+
Warn: To use it with the firmware-selector (by now) be sure to include the profile as first in the package's list.
28+
```
29+
include $(TOPDIR)/rules.mk
30+
31+
PROFILE_DESCRIPTION:=Generic libremesh metapackage
32+
PKG_CONFLICTS:=\
33+
-dnsmasq \
34+
-odhcpd-ipv6only
35+
PROFILE_DEPENDS:=\
36+
+profile-libremesh-suggested-packages
37+
38+
include ../../hack_pkg_conflicts.mk
39+
include ../../profile.mk
40+
41+
# call BuildPackage - OpenWrt buildroot signature
42+
43+
```
Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
include $(TOPDIR)/rules.mk
22

33
PROFILE_DESCRIPTION:=Generic metapackage for 8MB flash and/or 64MB RAM devices
4-
PKG_NAME:=profile-antennine.org-outdoor-8-64
54
PKG_CONFLICTS:=\
65
-dnsmasq \
76
-odhcpd-ipv6only \
@@ -23,72 +22,7 @@ PROFILE_DEPENDS:=\
2322
+shared-state-babeld_hosts \
2423
+shared-state-nodes_and_links
2524

26-
# hack to deselect openwrt's default_packages. To be used by at most by one metapackage/network-profile
27-
define Package/$(PKG_NAME)/preinst
28-
#!/bin/sh
29-
[ -z "$${IPKG_INSTROOT}" ] && exit 0
30-
echo "########################################################################## Inside package preinst"
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
66-
echo "########################################################################## Determine make's target"
67-
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)
68-
make_target=$$(echo "$${R}" | grep -q manifest && echo 'manifest' || echo 'image')
69-
echo "make_target: $${make_target}"
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
72-
echo "########################################################################## Terminate the execution after the second make image/manifest"
73-
cat << EOF > /tmp/hack_pkg_conflicts
74-
fail_target:
75-
cp $${TOPDIR}/Makefile.orig $${TOPDIR}/Makefile
76-
kill $$(ls -l /proc/*/exe | grep make | sed 's|.*/proc/\(.*\)/exe.*|\1|' | tr '\n' ' ' )
77-
# IB_MODIFIED_BY_$(PKG_NAME)
78-
EOF
79-
cat /tmp/hack_pkg_conflicts >> $${TOPDIR}/Makefile
80-
echo "########################################################################## 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
88-
make "$${make_target}"
89-
make fail_target
90-
endef
91-
25+
include ../../hack_pkg_conflicts.mk
9226
include ../../profile.mk
9327

9428
# call BuildPackage - OpenWrt buildroot signature

hack_pkg_conflicts.mk

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)