hostapd: add support for authenticating with multiple PSKs via ubus helper
[openwrt/staging/nbd.git] / include / rootfs.mk
1 ifdef CONFIG_USE_MKLIBS
2 define mklibs
3 rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
4 # first find all programs and add them to the mklibs list
5 find $(STAGING_DIR_ROOT) -type f -perm /100 -exec \
6 file -r -N -F '' {} + | \
7 awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
8 # find all loadable objects that are not regular libraries and add them to the list as well
9 find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
10 file -r -N -F '' {} + | \
11 awk ' /shared object/ { print $$1 }' > $(TMP_DIR)/mklibs-libs
12 mkdir -p $(TMP_DIR)/mklibs-out
13 $(STAGING_DIR_HOST)/bin/mklibs -D \
14 -d $(TMP_DIR)/mklibs-out \
15 --sysroot $(STAGING_DIR_ROOT) \
16 `cat $(TMP_DIR)/mklibs-libs | sed 's:/*[^/]\+/*$$::' | uniq | sed 's:^$(STAGING_DIR_ROOT):-L :'` \
17 --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
18 $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so ld-musl-*.so.*, \
19 $(STAGING_DIR_ROOT)/lib/$(name) \
20 )))) \
21 --target $(REAL_GNU_TARGET_NAME) \
22 `cat $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-libs` 2>&1
23 $(RSTRIP) $(TMP_DIR)/mklibs-out
24 for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
25 LIB="$${lib##*/}"; \
26 DEST="`ls "$(1)/lib/$$LIB" "$(1)/usr/lib/$$LIB" 2>/dev/null`"; \
27 [ -n "$$DEST" ] || continue; \
28 echo "Copying stripped library $$lib to $$DEST"; \
29 cp "$$lib" "$$DEST" || exit 1; \
30 done
31 endef
32 endif
33
34 # where to build (and put) .ipk packages
35 opkg = \
36 IPKG_NO_SCRIPT=1 \
37 IPKG_INSTROOT=$(1) \
38 TMPDIR=$(1)/tmp \
39 $(STAGING_DIR_HOST)/bin/opkg \
40 --offline-root $(1) \
41 --force-postinstall \
42 --add-dest root:/ \
43 --add-arch all:100 \
44 --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
45
46 apk = \
47 IPKG_INSTROOT=$(1) \
48 $(FAKEROOT) $(STAGING_DIR_HOST)/bin/apk \
49 --root $(1) \
50 --repositories-file /dev/zero \
51 --keys-dir $(TOPDIR) \
52 --no-cache \
53 --no-logfile \
54 --preserve-env \
55 --repository file://$(PACKAGE_DIR_ALL)/packages.adb
56
57 TARGET_DIR_ORIG := $(TARGET_ROOTFS_DIR)/root.orig-$(BOARD)
58
59 ifdef CONFIG_CLEAN_IPKG
60 define clean_ipkg
61 -find $(1)/usr/lib/opkg/info -type f -and -not -name '*.control' -delete
62 -sed -i -ne '/^Require-User: /p' $(1)/usr/lib/opkg/info/*.control
63 awk ' \
64 BEGIN { conffiles = 0; print "Conffiles:" } \
65 /^Conffiles:/ { conffiles = 1; next } \
66 !/^ / { conffiles = 0; next } \
67 conffiles == 1 { print } \
68 ' $(1)/usr/lib/opkg/status >$(1)/usr/lib/opkg/status.new
69 mv $(1)/usr/lib/opkg/status.new $(1)/usr/lib/opkg/status
70 -find $(1)/usr/lib/opkg -empty -delete
71 endef
72 endif
73
74 define prepare_rootfs
75 $(if $(2),@if [ -d '$(2)' ]; then \
76 $(call file_copy,$(2)/.,$(1)); \
77 fi)
78 @mkdir -p $(1)/etc/rc.d
79 @mkdir -p $(1)/var/lock
80 @( \
81 cd $(1); \
82 if [ -n "$(CONFIG_USE_APK)" ]; then \
83 $(STAGING_DIR_HOST)/bin/tar -xf ./lib/apk/db/scripts.tar --wildcards "*.post-install" -O > script.sh; \
84 chmod +x script.sh; \
85 IPKG_INSTROOT=$(1) $$(command -v bash) script.sh; \
86 else \
87 for script in ./usr/lib/opkg/info/*.postinst; do \
88 IPKG_INSTROOT=$(1) $$(command -v bash) $$script; \
89 ret=$$?; \
90 if [ $$ret -ne 0 ]; then \
91 echo "postinst script $$script has failed with exit code $$ret" >&2; \
92 exit 1; \
93 fi; \
94 done; \
95 $(if $(IB),,awk -i inplace \
96 '/^Status:/ { \
97 if ($$3 == "user") { $$3 = "ok" } \
98 else { sub(/,\<user\>|\<user\>,/, "", $$3) } \
99 }1' $(1)/usr/lib/opkg/status) ; \
100 $(if $(SOURCE_DATE_EPOCH),sed -i "s/Installed-Time: .*/Installed-Time: $(SOURCE_DATE_EPOCH)/" $(1)/usr/lib/opkg/status ;) \
101 fi; \
102 for script in ./etc/init.d/*; do \
103 grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
104 if ! echo " $(3) " | grep -q " $$(basename $$script) "; then \
105 IPKG_INSTROOT=$(1) $$(command -v bash) ./etc/rc.common $$script enable; \
106 echo "Enabling" $$(basename $$script); \
107 else \
108 IPKG_INSTROOT=$(1) $$(command -v bash) ./etc/rc.common $$script disable; \
109 echo "Disabling" $$(basename $$script); \
110 fi; \
111 done || true \
112 )
113
114 @-find $(1) -name CVS -o -name .svn -o -name .git -o -name '.#*' | $(XARGS) rm -rf
115 rm -rf \
116 $(1)/boot \
117 $(1)/tmp/* \
118 $(1)/usr/lib/opkg/info/*.postinst* \
119 $(1)/usr/lib/opkg/lists/* \
120 $(1)/var/lock/*.lock
121 $(call clean_ipkg,$(1))
122 $(call mklibs,$(1))
123 $(if $(SOURCE_DATE_EPOCH),find $(1)/ -mindepth 1 -execdir touch -hcd "@$(SOURCE_DATE_EPOCH)" "{}" +)
124 endef